def _after_add(self,data,operator): utils.orderTracking(ord_id = operator['ord_id'], operator_id = operator['operator_id'], operator_name = operator['operator_name'], title = '帮家建单', desc = operator['operator_name'] + '帮家建单成功', add_time = time.time())
def _after_dispatch(self,orderno,userid,operator): print(orderno,userid,operator) utils.orderTracking(ord_id = operator['ord_id'], operator_id = operator['operator_id'], operator_name = operator['operator_name'], title = '帮家派单', desc = operator['operator_name'] + '帮家派单成功' +str(userid), add_time = time.time())
def _after_Receipt(self,factorynumber,operator,ret): print("_after_Receipt:",factorynumber) utils.orderTracking(ord_id = operator['ord_id'], operator_id = operator['operator_id'], operator_name = operator['operator_name'], title = '商家接单成功[帮家]', desc = operator['operator_name'] + '操作在在帮家后台接单成功', add_time = time.time())
def order_detail_parse_xyj(self): """针对洗悦家清洁业务""" account_info = query_md_merchant(2)[0] # 1是midea账号表中宏旺的id usename = account_info.account pwd = account_info.password cookies = login(usename, pwd) # 测试用17 res_json = get_orders(cookies=cookies) # 默认抓取已派工订单 # print 'daijie_orders:%s'%res_json order_list = res_json['content']['rows'] if order_list: for od in order_list: try: if od['ORDER_ORIGIN'] != u'网点自建': # 只有订单来源是非网点自建的才做同步 # 从dm_midea_factory_order查询工单号,如果查不到进行同步 rs = query_md_factory(od['SERVICE_ORDER_NO']) if not rs: print od['SERVICE_ORDER_NO'] # 解析原始订单数据 detail_item = xyj_detail_parse(od) clear_db = CleanDb(od_detail=detail_item) # 保存详情数据 order_id = clear_db.save_order_detail() # 保存订单详情 print ('order_id:%s' % order_id) # errorReport('success save order_detail:'+str(order_id)) # 保存原始工单和对应的二师兄平台的订单对应id save_md_factory(od, int(order_id),usename) # errorReport('xyj success save md_factory:'+od['SERVICE_ORDER_NO']+' '+time.asctime(time.localtime(time.time()))) # 保存日志 api_logs = {'client': 'media_save_orderdetail', 'order_source_data': od, 'order_parse_data': detail_item, 'order_id': order_id, 'time': time.time() } saveApiLogs(api_logs) self.log('finish order crawl:%s' % order_id) # 增加跟单记录 track_time = current_timestamp() track_desc = u"系统在{}从美的同步了订单".format(current_timestr()) orderTracking(order_id, 1, 'system', u'同步', track_desc, track_time) except Exception as e: # import traceback # traceback.print_exc() errorReport('xyj crawl exception->' + od['SERVICE_ORDER_NO'] + ':' + str(e) + str(e.args) + time.asctime(time.localtime(time.time()))) # 保存美的师傅的数据 shifu_data = get_engineers_data(cookies=cookies) if shifu_data: for shifu_data in shifu_data['content']['rows']: save_account(shifu_data, usename) # 保存师傅数据 self.log('finish save shifu_data')
def order_detail_parse_fortianmao(self, cookies): res_json = get_orders(cookies=cookies, order_status='14') # 已接单以后开始 # print 'daijie_orders:%s'%res_json order_list = res_json['content']['rows'] if order_list: for od in order_list[:1]: print 'tianmao :%s' % od['SERVICE_ORDER_NO'] try: if od['ORDER_ORIGIN'] == u'天猫接入': # 只有订单来源是非网点自建的才做同步 rs = query_md_factory(od['SERVICE_ORDER_NO']) if not rs: # 解析原始订单数据 meidi_detail_item = md_detail_parse(od) # 保存详情数据 order_id = self.md_db.save_order_detail( meidi_detail_item) # 保存订单详情 self.log('order_id:%s' % order_id) # 保存原始工单和对应的二师兄平台的订单对应id save_md_factory_tm(od, int(order_id)) # errorReport('success save md_factory:' + od['SERVICE_ORDER_NO'] + ' ' + time.asctime( # time.localtime(time.time()))) # 保存日志 api_logs = { 'client': 'media_save_orderdetail', 'order_source_data': od, 'order_parse_data': meidi_detail_item, 'order_id': order_id, 'time': time.time() } saveApiLogs(api_logs) self.log('finish order crawl:%s' % order_id) # 增加跟单记录 track_time = current_timestamp() track_desc = u"系统在{}从美的同步了订单".format( current_timestr()) orderTracking(order_id, 1, 'system', u'同步', track_desc, track_time) except Exception as e: errorReport('media tianmao crawl exception->' + od['SERVICE_ORDER_NO'] + ':' + str(e) + str(e.args) + time.asctime(time.localtime(time.time())))
def order_detail_parse(self,merchant): """在订单详情页提取订单详情数据""" jd_login = jp.JdLogin(merchant) cookies = jd_login.login() res_json = jp.quest_orders(cookies=cookies,merchant=merchant) # 默认抓取已预约订单 order_list = res_json['rows'] # print('order_list',order_list) if order_list: for od in order_list: print '*' * 20 + str(od['orderno'])+'_start_' + '*' * 20 try: # 解析原始订单数据 static_data = parse_static_data(od['ordernoSecret'], cookies) print 'orderno:%s' % od['orderno'] # 非送装一体的工单才同步 if not static_data['is_ins_join_send']: # 查询factory表,查询为空才同步 is_exist_factory = query_factory(od['orderno']) if not is_exist_factory: is_exist_jd_ordid = query_jd_ordid(od['orderId']) detail_item = detail_parse(od, static_data,merchant) # 保存详情数据 spider_db = JdDb(od_detail=detail_item) if not is_exist_jd_ordid: # 同步订单,dm_order和apl表插入数据 order_id = spider_db.new_save_order_detail() # 保存订单详情 # errorReport('success save order_detail:'+str(order_id)) # 保存原始工单和对应的二师兄平台的订单对应id track_time = current_timestamp() track_desc = u"系统在{}从{}同步了订单".format(current_timestr(), self.order_source) orderTracking(order_id, 1, 'system', u'同步', track_desc, track_time) print 'finish add order:%s'%order_id if is_exist_jd_ordid: # 更新订单,更新dm_order和apl order_id = is_exist_jd_ordid[0] spider_db.update_order_detail(order_id) track_time = current_timestamp() track_desc = u"系统在{}修改了订单".format(current_timestr()) orderTracking(order_id, 1, 'system', u'改单', track_desc, track_time) print 'finish update order:%s'%order_id # 保存factory信息 print('order_id:%s' % order_id) save_factory(od, int(order_id), static_data) # report_message = '%s->success save:' % self.name + str( # od['orderno']) + ' ' + od['orderId']+' '+time.asctime(time.localtime(time.time())) # errorReport(report_message) # 保存日志 print '*' * 20 + str(od['orderno'])+'_success_' + '*' * 20 api_logs = {'client': self.name, 'order_source_data': od, 'order_parse_data': detail_item, 'order_id': order_id, 'time': time.time() } saveApiLogs(api_logs) # print('finish order crawl:%s' % order_id) # 增加跟单记录 except Exception as e: # import traceback # traceback.print_exc() errorReport('%s exception->' % self.name + str(od['orderno']) + ':' + str(e) + str( e.args) + time.asctime(time.localtime(time.time()))) # 保存师傅的数据 shifu_datas = jp.get_engineers(cookies=cookies,merchant=merchant) if shifu_datas: for shifu_data in shifu_datas['rows']: save_account(shifu_data) # 保存师傅数据 print ('finish save shifu_data')
def order_detail_parse(self, response): """在订单详情页提取订单详情数据""" order_detail = OrderedDict() try: work_order_info = u"工单信息" cust_info = u"客户信息" service_post = u"服务请求" product_info = u"产品信息" selector = Selector(response) # 顾客姓名 order_detail['ord_cust_name'] = self.new_selector( selector, '//input[@class="detail-data-form customerName"]/@value') # print('ord_cust_name:%s'%order_detail['ord_cust_name']) # 以下为dm_order所需数据 # 拼接电话 # print(self.new_selector(selector,'//div[@title="%s"]'%work_order_info)) laidian_num = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[2]/input/@value' % work_order_info) print('laidian_numxxx:%s' % laidian_num) # laidian_num = self.new_selector(selector,'//div[@title="%s"]/table/tr[1]/td[2]/input/@value'%work_order_info) mobile_phone = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[6]/input/@value' % cust_info) print('mobile_phone:%s' % mobile_phone) order_detail['ord_cust_tel'] = laidian_num print('ord_cust_tel:%s' % order_detail['ord_cust_tel']) # 拼接具体用户地址 town = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[4]/select[4]/option[@selected="selected"]/text()' % (cust_info)) addr_detail = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[2]/input/@value' % (cust_info)) distrct = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[4]/select[3]/option[@selected="selected"]/text()' % (cust_info)) if distrct in addr_detail: ord_cust_addr = intercept_qu(addr_detail) elif town in addr_detail: ord_cust_addr = addr_detail.replace(town, '') else: ord_cust_addr = addr_detail order_detail['ord_cust_addr'] = ord_cust_addr # print('ord_cust_addr:%s'%order_detail['ord_cust_addr']) # 客户省市区 order_detail['ord_province'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[4]/select[1]/option[@selected="selected"]/text()' % (cust_info)) order_detail['ord_city'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[4]/select[2]/option[@selected="selected"]/text()' % (cust_info)) order_detail['ord_district'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[4]/select[3]/option[@selected="selected"]/text()' % (cust_info)) order_detail['ord_street'] = town # 服务描述 order_detail['ord_remark'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[2]/textarea/text()' % service_post) # print('ord_remark:%s'%order_detail['ord_remark']) # 订单号 order_detail['ord_num'] = create_sn() # 利用东哥算法计算 print("ord_num:%s" % order_detail['ord_num']) # 微信支付号 order_detail['ord_pay_num'] = create_sn() # 利用东哥算法计算 print("ord_pay_num:%s" % order_detail['ord_pay_num']) # 联合地址 order_detail['ord_grab_addr'] = order_detail[ 'ord_province'] + order_detail['ord_city'] + order_detail[ 'ord_district'] + order_detail['ord_cust_addr'] # print('ord_grab_addr:%s'%order_detail['ord_grab_addr']) # 服务描述 order_detail['ord_cust_fault'] = order_detail['ord_remark'] # 工单号 order_detail['ord_accept_no'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[4]/input/@value' % work_order_info) print('ord_accept_no:%s' % order_detail['ord_accept_no']) # 要求服务时间 ymd_time = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[2]/input[1]/@value' % service_post) # print(ymd_time) ymd_time_timestamps = time_to_timestamp(ymd_time) # ap_time = self.new_selector(selector,'//div[@title="请求"]/table/tbody/tr[3]/td[2]/input[2]/@value') order_detail['ord_ask_time'] = ymd_time_timestamps # print('ord_ask_time:%s'%order_detail['ord_ask_time']) # 当前时间戳 order_detail['ord_create_time'] = current_timestamp() print('ord_create_time:%s' % order_detail['ord_create_time']) # 购买时间,存时间戳格式 buy_time = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[2]/input/@value' % product_info) order_detail['ord_buy_time'] = time_to_timestamp(buy_time) print('ord_buy_time:%s' % order_detail['ord_buy_time']) # 经纬度 # if u"区" in addr_detail: # point_index = addr_detail.index(u'区') # addr_detail = addr_detail[point_index+1:] order_detail['ord_cust_lng'], order_detail[ 'ord_cust_lat'] = get_latlng( order_detail['ord_city'], order_detail['ord_district'] + order_detail['ord_street'] + order_detail['ord_cust_addr']) # print('ord_cust_lng:%s'%order_detail['ord_cust_lng']) order_detail['ord_weixin_num'] = '' order_detail['ord_merc_id'] = response.meta['account_info'][ 'platform_id'] # 根据登录的账号商家决定 print('ord_merc_id:%s' % order_detail['ord_merc_id']) order_detail['ord_purchase_unit'] = u'厂派' order_detail['ord_purchase_unit_id'] = 0 order_detail['ord_status'] = 0 order_detail['ord_need_build'] = 2 #//不用建单 order_detail['ord_type'] = 1 # 销售单位,购买单位 order_detail['ord_sale_unit'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[6]/input/@value' % (product_info)) # 接件时间,受理日期 order_detail['ord_accept_time'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[4]/input/@value' % service_post) order_detail['ord_accept_time'] = time_to_timestamp3( order_detail['ord_accept_time']) # order_detail['ord_show_cost'] = 0.0 # 服务原因 order_detail['service_reason'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[2]/select[1]/option[@selected="selected"]/text()' % work_order_info) if order_detail['service_reason'] == u'维修': if u'移机' in order_detail['ord_remark']: order_detail['ord_type'] = 3 else: order_detail['ord_type'] = 5 print 'ord_type:%s' % order_detail['ord_type'] # 解析渠道,不会立即插入dm_order,这些渠道名称根据dm_merchant_purchase_unit获得 if order_detail[ 'ord_merc_id'] == 91: # 聚杰因为没有厂家系统,京东其他渠道的配置,所以区别对待 order_detail['qudao'] = u'天猫' elif u'京东' in order_detail['ord_sale_unit']: order_detail['qudao'] = u'京东' elif u'京.东' in order_detail['ord_sale_unit']: order_detail['qudao'] = u'京东' elif u'天猫' in order_detail['ord_sale_unit']: order_detail['qudao'] = u'天猫' elif u'国美' in order_detail['ord_sale_unit']: order_detail['qudao'] = u'国美' else: order_detail['qudao'] = u'厂家系统' # 下面为dm_order 暂时不需要数据 # 以下工单信息 # 进展查询码 order_detail['ord_check_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[6]/input/@value' % work_order_info) # 工单途径 order_detail['ord_way'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[8]/input/@value' % work_order_info) # # 服务原因 # order_detail['service_reason'] = self.new_selector(selector,'//div[@title="%s"]/table/tr[2]/td[2]/select[1]/option[@selected="selected"]/text()'%work_order_info) # 投诉原因 order_detail['complaint_reason'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[4]/select[1]/option[@selected="selected"]/text()' % work_order_info) # 处理类别 order_detail['deal_category'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[6]/select[1]/option[@selected="selected"]/text()' % work_order_info) # 指令人 order_detail['zhilin_ren'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[8]/input/@value' % work_order_info) # 工程单 order_detail['eng_form'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[2]/span/text()' % work_order_info) # 处理级别 order_detail['deal_level'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[4]/select[1]/option[@selected="selected"]/text()' % work_order_info) # 历史工单数 order_detail['work_num_history'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[6]/select[1]/option[@selected="selected"]/text()' % work_order_info) # 重电次数 order_detail['call_repeat_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[8]/input/@value' % work_order_info) # 工单类型 order_detail['work_order_category'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[4]/td[2]/select[1]/option[@selected="selected"]/text()' % work_order_info) # 处理阶段 order_detail['deal_stage'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[4]/td[4]/select[1]/option[@selected="selected"]/text()' % work_order_info) # 处理状态 order_detail['deal_status'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[4]/td[6]/select[1]/option[@selected="selected"]/text()' % work_order_info) # 督办 order_detail['duban'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[4]/td[8]/span/text()' % work_order_info) # 督办日期 order_detail['duban_date'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[5]/td[2]/input/@value' % work_order_info) # 退单次数 order_detail['return_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[5]/td[4]/input/@value' % work_order_info) # 服务时长 order_detail['service_time_length'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[5]/td[6]/input/@value' % work_order_info) # 承诺时间 order_detail['commit_time'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[5]/td[8]/input/@value' % work_order_info) # 做出承诺人 order_detail['commit_person'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[6]/td[2]/input/@value' % work_order_info) # 做出承诺时间 order_detail['do_commit_time'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[6]/td[4]/input/@value' % work_order_info) # 废单次数 order_detail['discard_order_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[6]/td[6]/input/@value' % work_order_info) # 处理工程师 order_detail['engineer'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[6]/td[8]/input/@value' % work_order_info) # 以下服务请求 # 故障树方案 order_detail['guzhang_'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[4]/textarea/text()' % service_post) # 空调台数 order_detail['condition_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[2]/input/@value' % service_post) # 受理日期 # order_detail['accepted_date'] = self.new_selector(selector,'//div[@title="%s"]/table/tr[2]/td[4]/input/@value'%service_post) # 服务项目 order_detail['service_project'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[6]/input/@value' % service_post) # 上门预约日期 ymr_yuyue = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[4]/input/@value' % service_post) # sfm_yuyue = self.new_selector(selector,'//div[@title="%s"]/table/tr[3]/td[4]/select[1]/option[@selected="selected"]/text()'%service_post) order_detail['yuyue_date'] = time_to_timestamp(ymr_yuyue) # 以下客户信息 # 家庭电话 order_detail['family_phone'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[2]/input/@value' % (cust_info)) # 办公电话 order_detail['office_phone'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[4]/input/@value' % (cust_info)) # 移动电话 order_detail['mobile_phone'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[6]/input/@value' % (cust_info)) # 电话区号 order_detail['quhao'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[4]/td[2]/input/@value' % (cust_info)) # 微信账号 order_detail['weixin_account'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[4]/td[4]/input/@value' % (cust_info)) # 是否延保金用户 order_detail['is_yanbao_account'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[5]/td[2]/span/text()' % (cust_info)) # 延保卡号 order_detail['yanbao_cardno'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[5]/td[4]/input/@value' % (cust_info)) # 延保金卡地址 order_detail['yanbao_card_addr'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[5]/td[6]/input/@value' % (cust_info)) # 保养卡号 order_detail['baoyang_cardno'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[5]/td[8]/input/@value' % (cust_info)) # 以下产品信息 # 品牌 order_detail['brand'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[2]/select[1]/option[@selected="selected"]/text()' % (product_info)) # 产品大类 order_detail['product_category'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[4]/select[1]/option[@selected="selected"]/text()' % (product_info)) # 整机型号 order_detail['machine_model'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[6]/select[1]/option[@selected="selected"]/text()' % (product_info)) # 整机型编号 order_detail['machine_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[1]/td[8]/select[1]/option[@selected="selected"]/text()' % (product_info)) # 是否延保 order_detail['is_yanbao'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[4]/span/text()' % (product_info)) # 延保年限 order_detail['yanbao_year'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[6]/input/@value' % (product_info)) # 匹数 order_detail['pi_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[2]/td[8]/select[1]/option[@selected="selected"]/text()' % (product_info)) # 内机编号 order_detail['neiji_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[2]/input/@value' % (product_info)) # 外机编号 order_detail['waiji_num'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[4]/input/@value' % (product_info)) # 购买单位 # order_detail['buy_unit'] = self.new_selector(selector,'//div[@title="%s"]/table/tr[3]/td[6]/input/@value'%(product_info)) # 安装单位 order_detail['anzhuang_unit'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[3]/td[8]/input/@value' % (product_info)) # 维修单位 order_detail['weixiu_unit'] = self.new_selector( selector, '//div[@title="%s"]/table/tr[4]/td[2]/input/@value' % (product_info)) # 保存订单详情数据 # print(order_detail) if not order_detail['ord_accept_no']: utils.errorReport('aux_exption->parse order_detail fail' + ':' + time.asctime(time.localtime(time.time()))) order_id = self.aux_db.save_order_detail(order_detail) print 'order_id:%s' % order_id # 保存工单和订单插入id的映射关系 print 'ord_accept_no:%s' % order_detail['ord_accept_no'] self.aux_db.save_auxfactory( order_detail['ord_accept_no'], order_id, current_timestamp(), order_detail['ord_type'], response.meta['account_info']['username']) # utils.errorReport('aux->success save order_detail:%s'%order_detail['ord_accept_no']+' '+response.meta['account_info']['username']+' '+time.asctime(time.localtime(time.time()))) # 保存日志 api_logs = { 'client': 'media_save_orderdetail', 'order_source_data': response.body, 'order_parse_data': order_detail, 'order_id': order_id, 'time': time.time() } utils.saveApiLogs(api_logs) track_time = current_timestamp() track_desc = u"系统在{}从奥克斯同步了订单".format(current_timestr()) utils.orderTracking(order_id, 1, 'system', u'同步', track_desc, track_time) except Exception as e: # import traceback # traceback.print_exc() # print('aux_exption-->>'+str(e)) utils.errorReport('aux_exption->' + order_detail['ord_accept_no'] + ':' + str(e) + str(e.args) + time.asctime(time.localtime(time.time())))
def order_detail_parse(self, merchant): """在订单详情页提取订单详情数据""" # 从数据库获取账号信息 # account_info = query_md_merchant(1)[0] # 1是midea账号表中宏旺的id # # usename = account_info.account # pwd = account_info.password usename = merchant.account pwd = merchant.password # 登录获取订单 cookies = login(usename, pwd) self.order_detail_parse_fortianmao(cookies) res_json = get_orders(cookies=cookies) # 默认抓取已派工订单 # print 'daijie_orders:%s'%res_json order_list = res_json['content']['rows'] if order_list: for od in order_list: try: if od['ORDER_ORIGIN'] != u'网点自建': # 只有订单来源是非网点自建的才做同步 print '*' * 20 + od['SERVICE_ORDER_NO'] + '*' * 20 # r = receive_order(od['SERVICE_ORDER_ID'], od['UNIT_CODE'], cookies=cookies) # 对待接单订单进行接单 # # r=True # if r: # 从dm_midea_factory_order查询工单号,如果查不到进行同步 rs = query_md_factory(od['SERVICE_ORDER_NO']) print 'success query rs:%s' % od['SERVICE_ORDER_NO'] if not rs: # 解析原始订单数据 meidi_detail_item = md_detail_parse(od, merchant) print 'success parse order:%s' % od[ 'SERVICE_ORDER_NO'] # 保存详情数据 order_id = self.md_db.save_order_detail( meidi_detail_item) # 保存订单详情 print('success save order_id:%s' % order_id) # errorReport('success save order_detail:'+str(order_id)) # 保存原始工单和对应的二师兄平台的订单对应id save_md_factory(od, int(order_id), usename) print('success save md_factory:%s' % od['SERVICE_ORDER_NO']) # errorReport('success save md_factory:'+od['SERVICE_ORDER_NO']+' '+time.asctime(time.localtime(time.time()))) print('*' * 20 + od['SERVICE_ORDER_NO'] + '*' * 20) # 保存日志 api_logs = { 'client': 'media_save_orderdetail', 'order_source_data': od, 'order_parse_data': meidi_detail_item, 'order_id': order_id, 'time': time.time() } saveApiLogs(api_logs) # print('success save apilogs:%s'%od['SERVICE_ORDER_NO']) # 增加跟单记录 track_time = current_timestamp() track_desc = u"系统在{}从美的同步了订单".format( current_timestr()) orderTracking(order_id, 1, 'system', u'同步', track_desc, track_time) except Exception as e: # import traceback # traceback.print_exc() errorReport('media crawl exception->' + od['SERVICE_ORDER_NO'] + ':' + str(e) + str(e.args) + time.asctime(time.localtime(time.time()))) # 保存美的师傅的数据 shifu_data = get_engineers_data(cookies=cookies) if shifu_data: for shifu_data in shifu_data['content']['rows']: save_account(shifu_data, usename) # 保存师傅数据 self.log('finish save shifu_data')