Пример #1
0
	def auth(self,userid = '33580'):
		print(userid)
		userid = str(userid)
		session = DBSession()
		ret = session.query(auxAccount).filter(auxAccount.aux_id_number==userid).all()
		if ret:
			self.account = ret[0]
		else:
			return utils.errorReport('查无用户,aux_userid:' + userid + "ord_id:" + self.ord_id,system_name = self.system_name)
		print(self.account.aux_serial_number)
		element = self.login2("123456",self.account.aux_serial_number,'')
		print(element['username'])
		print(element['channelid'])
		if element == False:
			return element
		self.account.token = element['token']
		self.token = element['token']
		self.userid = userid
		self.adminid = element['adminid']
		self.account.channelid = element['channelid']
		self.account.aux_adminid = element['adminid']
		session.add(self.account)
		session.commit()
		session.close()
		kickoff_element = self.kickoff(element)
		print(json.dumps(kickoff_element))
		if kickoff_element == False:
			return kickoff_element
		return self.addchannel(kickoff_element)
Пример #2
0
	def _after_mastergetwait(self,obj):
		session = DBSession()
		for item in obj:
			isexists = session.query(AuxOrder).filter(AuxOrder.aux_orderno == item['orderno']).all()
			if isexists:
				aux = isexists[0]
				aux.json_detail = json.dumps(item)
				session.add(aux)
		session.commit()
		session.close()
Пример #3
0
	def _after_mastergetservice2(self,lists):
		session = DBSession()
		for item in lists:
			if len(item['detail']) == 0:
				continue
			for order in item['detail']:
				isexists = session.query(AuxOrder).filter(AuxOrder.aux_orderno == order['orderno']).all()
				if isexists:
					aux = isexists[0]
					aux.json_detail = json.dumps(order)
					session.add(aux)
		session.commit()
		session.close()
Пример #4
0
def save_cmd(data):
    phppy = Phppy()
    phppy.data = item['data']
    phppy.time = time.time()
    phppy.channel = item['channel']

    session = DBSession()
    session.add(phppy)
    session.commit()
    session.close()
Пример #5
0
	def _after_finish(self,data,operator):
		session = DBSession()
		_auxorder = session.query(AuxOrder).filter(AuxOrder.aux_orderno == data['orderno']).all()
		auxorder = _auxorder[0]
		auxorder.is_pending = 0
		auxorder.is_finish = 1
		session.add(auxorder)
		session.commit()
		session.close()

		utils.orderTracking(ord_id = operator['ord_id'],
                            operator_id = operator['operator_id'],
                            operator_name = operator['operator_name'],
                            title = '师傅帮家系统完成订单',
                            desc = operator['operator_name'] + '在帮家系统完成了订单auxordno' + data['orderno'],
                            add_time = time.time())
Пример #6
0
def save_account(item,account):
    '''保存师傅账号信息'''
    session = DBSession()
    md_account = MdAccount(
                    )
    md_account.engineer_id = item['engineer_id']
    md_account.engineer_code = item['engineer_code']
    md_account.work_year = item['work_year']
    md_account.sex = item['sex']
    if item['address']:
        md_account.address = item['address']
    if item['unit_name']:
        md_account.unit_name = item['unit_name']
    if item['mobile']:
        md_account.engineer_tel = item['mobile']
    if item['engineer_name']:
        md_account.engineer_name = item['engineer_name']
    if item['work_no']:
        md_account.workNo = item['work_no']
    if item['unit_code']:
        md_account.unitCode = item['unit_code']
    md_account.account_source = account
    try:
        # 通过异常处理来避免插入时师傅重复
        session.add(md_account)           # 更好的方式是批量插入,add_all
        session.commit()
    except Exception as e:
        pass
Пример #7
0
def save_account(item):
    '''保存师傅账号信息'''
    session = DBSession()
    md_account = JdAccount()
    md_account.engineer_id = item['engineerNoSec']
    md_account.engineer_code = item['engineerNo']
    # md_account.work_year = item['work_year']
    # md_account.sex = item['sex']
    if item['address']:
        md_account.address = item['address']
    if item['websiteName']:
        md_account.unit_name = item['websiteName']
    if item['mobile']:
        md_account.engineer_tel = item['mobile']
    if item['engineerName']:
        md_account.engineer_name = item['engineerName']
    # if item['work_no']:
    #     md_account.workNo = item['work_no']
    if item['websiteNo']:
        md_account.unitCode = item['websiteNo']
    try:
        # 通过异常处理来避免插入时师傅姓名重复
        session.add(md_account)  # 更好的方式是批量插入,add_all
        session.commit()
    except Exception as e:
        pass
Пример #8
0
 def add_dispatch(self,data,operator = None):
     '''
     建单,接单,派单业务处理
     '''
     print('add_dispatch')
     print(self.account)
     add_ret = self.add_order(data['adddata'],operator = operator)
     if add_ret is False:
        return add_ret
     grid = self.gridIndex(None)
     if grid.get('total') != '0':
         for item in grid['rows']:
             if item['mobile']==data['adddata']['callNo']:
                 receipt = self.providerReceiptOrder(item['factorynumber'],operator = operator)
                 print("receiptJon:",receipt)
                 if receipt is False:
                     return receipt
                 account = self.getAccountByName(data['info']['user'])
                 print("account:",account)
                 aux = AuxOrder()
                 session = DBSession()
                 aux.aux_orderno = receipt['orderno']
                 aux.platform_orderid = data['info']['platform_orderid']
                 aux.aux_userid = account['aux_id_number']
                 session.add(aux)
                 fac = AuxFactoryOrder()
                 fac.factorynumber = item['factorynumber']
                 fac.platform_id = data['info']['platform_orderid']
                 fac.aux_orderno = receipt['orderno']
                 fac.order_type = data['adddata']['servDesc']
                 fac.created_at = str(time.time())[:str(time.time()).index('.')]
                 fac.order_type = self.get_order_type(data['adddata']['servDesc'])
                 session.add(fac)
                 session.commit()
                 session.close()
                 return self.dispatch_order(orderno = receipt['orderno'],userid = account['aux_id_number'],operator = operator)
     print('no wait accept order.')
     utils.errorReport('notice:no wait accept order',system_name = self.system_name)
     return False
Пример #9
0
def save_md_factory_tm(item, esx_orderno):
    '''保存美的的工单号和对应的二师兄平台对应的订单号'''
    session = DBSession()
    md_factory = MdFactory(
        factorynumber=item['SERVICE_ORDER_NO'],      # 工单号
        service_order_id=item['SERVICE_ORDER_ID'],   # 和工单对应
        service_user_demandids=item['SERVICE_CUSTOMER_DEMAND_ID'],   # 和工单对应
        # appoint_time=item['APPOINT_TIME'],           # 预约时间
        # enginer_name=item['ENGINEER_NAME'],          # 派工师傅
        factory_data=json.dumps(item,encoding='utf-8',ensure_ascii=False),               # 所有数据
        platform_id= esx_orderno,                    # 二师兄平台订单插入id
        created_at=current_timestamp()
    )
    session.add(md_factory)
    session.commit()
Пример #10
0
def save_factory(item, esx_orderno, static_data):
    '''保存美的的工单号和对应的二师兄平台对应的订单号'''
    session = DBSession()
    md_factory = JdFactory(
        factorynumber=item['orderno'],  # 工单号
        service_order_id=item['orderId'],  # 和工单对应
        # service_user_demandids=item['SERVICE_CUSTOMER_DEMAND_ID'],   # 和工单对应
        appoint_time=static_data['appoint_time'],  # 预约时间
        enginer_name=item['engineerName'],  # 派工师傅
        factory_data=json.dumps(item, encoding='utf-8',
                                ensure_ascii=False),  # 所有数据
        esx_order_id=esx_orderno,  # 二师兄平台订单插入id
        created_at=current_timestamp())
    session.add(md_factory)
    session.commit()
Пример #11
0
def query_md_merchant(id):
    session = DBSession()
    rs = session.query(MdMerchant).filter(MdMerchant.id == id)
    # new_rs = [r for r in rs]
    return rs
Пример #12
0
	def addinstall_orderpic_finish(self,data):
		'''
		add and finsh:data['addinstall'] , data['finish']
		'''
		print("addinstall_orderpic_finish")
		self.ord_id = data['operator']['ord_id']
		if data.get('add'):
			self.auxapi = AuxApi(data['add']['info']['account'],data['add']['info']['password'])
			add_dis = self.auxapi.add_dispatch(data['add'],operator = data['operator'])
			print('add_dis',add_dis)
			if add_dis is not True:
				print('建单派单失败')
				return False
			print("al add")
			ord_id = data['add']['info']['platform_orderid']
			auxorder = db.find(AuxOrder,AuxOrder.platform_orderid == str(ord_id))
			data['finish']['orderno'] = auxorder['aux_orderno']
			data['finish']['userid'] = auxorder['aux_userid']
		if data['finish']['userid'] is None:
			data['finish']['userid'] = '77181'
		print('before auth')
		self.auth(data['finish']['userid'])
		print('after auth')
		self.mastergetservice2(self.userid,token = self.token,pagesize = 20,page = 1)
		print('after mastergetservice2')
		self.mastergetwait(self.userid, self.token, pagesize = 20, page = 1)
		print('after mastergetwait')

		session = DBSession()
		_aux= session.query(AuxOrder).filter(AuxOrder.platform_orderid==data['operator']['ord_id']).all()
		aux = _aux[0]
		aux.is_pending = 1
		session.add(aux)
		json_detail = aux.json_detail
		aux_userid = aux.aux_userid
		session.commit()
		session.close()

		aux_account = db.find(auxAccount,auxAccount.aux_id_number==aux_userid)
		print('json_detail:',json_detail)
		if json.loads(json_detail)['lng'] is None:
			return utils.errorReport('The value of latitude and longitude is not allowed to be None.ord_id:'+data['operator']['ord_id'])
		distance = utils.distanceRange(lon1 = json.loads(json_detail)['lng'],
										lat1 = json.loads(json_detail)['lat'],
										lon2 = json.loads(json_detail)['lng'],
										lat2 = json.loads(json_detail)['lat'],
										maxdistance = 490)
		if distance is False:
			return utils.errorReport('经纬度距离超过450米,提交阻止.ord_id:' + data['operator']['ord_id'])
		
		data['finish']['lng'] = distance['lon2']
		data['finish']['lat'] = distance['lat2']
		print(distance)
		regeo = utils.baidumapdecode({'lat': distance['lat2'], 'lng': distance['lon2']})
		print(regeo)
		if regeo.get("result").get("addressComponent") is None:
			print('regeo field')
			return False
		
		for m in data['addinstall']:
			print('for addinstall 1')
			if vars().has_key('auxorder') is True:
				m['orderno'] = auxorder['aux_orderno']
				m['userid'] = auxorder['aux_userid']
			print('for addinstall 2')
			
			for pic in m['piclist']:
				print('for piclist 1')
				pic['finishlng'] = distance['lon2']
				pic['finishlat'] = distance['lat2']
				text1 = aux_account['aux_name'] + " " + datetime.now().strftime("%Y-%m-%d %H:%M:%S")
				street_number = str(regeo["result"]["addressComponent"]["street_number"])
				if street_number != "" and u"号" not in street_number:
					street_number + "号"
				text2 = "在"+regeo["result"]["addressComponent"]["street"] + street_number + "附近"
				print(text2)
				IM = image_mark.ImageMark()
				# file_stream = IM.aux_mark(ttf_file = "./library/fonts/msyh.ttf",link = pic['picurl'],text1 = text1,text2 = text2)
				try:
					#有照片资源路劲无法访问的情况
					file_stream = IM.aux_mark(ttf_file = "./library/fonts/msyh.ttf",link = pic['picurl'],text1 = text1,text2 = text2)
				except Exception as e:
					return utils.errorReport(str(e) + '.ord_id:' + self.ord_id + '.url:' + pic['picurl'],system_name = self.system_name)
				picret = self.orderpic(file_stream,m['orderno'],m['userid'])
				print('for piclist 2')
				
				if picret is False:
					return utils.errorReport('aliyun oss upload picture field.ord_id:' + self.ord_id,system_name = self.system_name)
				pic['picurl'] = picret
			
			m['piclist'] = json.dumps(m['piclist'],encoding="UTF-8", ensure_ascii=False)
			m['token'] = self.token
			m['userid'] = self.userid
			m['lng'] = data['finish']['lng']
			m['lat'] = data['finish']['lat']
			print('add 1')
			
			addret = self.addinstallmachine(requestData = m,operator = data['operator'])
			print('add 2')
			if addret is False:
				return addret
		
		data['finish']['token'] = self.token
		data['finish']['userid'] = self.userid
		print('finish 1')
		
		finshret = self.finishorder2(data['finish'],operator = data['operator'])
		print('finish 2')
		if finshret is False:
			return finshret
		print('done')
Пример #13
0
def query_jd_ordid(order_id):
    session = DBSession()
    rs = session.query(
        JdFactory.esx_order_id).filter(JdFactory.service_order_id == order_id)
    new_rs = [r.esx_order_id for r in rs]
    return new_rs
Пример #14
0
def query_jd_merchant():
    session = DBSession()
    rs = session.query(JdMerchant).filter(
        JdMerchant.is_active == 0)  # 只获取激活的商家账号0,未激活是1
    return rs
Пример #15
0
def query_aux_merchant():
    session = DBSession()
    rs = session.query(AuxMerchant).filter(AuxMerchant.is_active == 0)
    return rs
Пример #16
0
def query_area(name):
    session = DBSession()
    rs = session.query(DmArea).filter(DmArea.name == name)
    return rs
Пример #17
0
def query_md_factory(factory_no):
    session = DBSession()
    rs = session.query(MdFactory).filter(MdFactory.factorynumber == factory_no)
    new_rs = [r for r in rs]
    return new_rs
Пример #18
0
 def getAccountByName(self,name = ''):
     session = DBSession()
     account = session.query(auxAccount).filter((auxAccount.aux_name==name) & (auxAccount.channelid!='-1') & (auxAccount.channelid!=None) & (auxAccount.aux_merc_account==self.account)).all()
     if account:
         data = account[0]
         r = {"aux_id_number":data.aux_id_number}
         session.commit()
         session.close()
         return r
     else:
         # session = DBSession()
         aux_node = session.query(AuxMerchant).filter(AuxMerchant.account==self.account).all()
         r = {"aux_id_number":aux_node[0].default_master}
         session.commit()
         session.close()
         return r
Пример #19
0
def query_md_merchant_active():
    session = DBSession()
    rs = session.query(MdMerchant).filter(MdMerchant.is_active == 0)  # 0代表有效商家账号
    return rs