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)
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
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()
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()
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())
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')
def query_area(name): session = DBSession() rs = session.query(DmArea).filter(DmArea.name == name) return rs
def query_aux_merchant(): session = DBSession() rs = session.query(AuxMerchant).filter(AuxMerchant.is_active == 0) return rs
def query_md_merchant_active(): session = DBSession() rs = session.query(MdMerchant).filter(MdMerchant.is_active == 0) # 0代表有效商家账号 return rs
def query_md_merchant(id): session = DBSession() rs = session.query(MdMerchant).filter(MdMerchant.id == id) # new_rs = [r for r in rs] return rs
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
def query_jd_merchant(): session = DBSession() rs = session.query(JdMerchant).filter( JdMerchant.is_active == 0) # 只获取激活的商家账号0,未激活是1 return rs
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