Esempio n. 1
0
    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')
Esempio n. 2
0
def rk_get_captcha():
    im, t = down_image()
    rc = RClient('WongTH', '147258369', '89380',
                 'c2faa5c3ff5d4b459c703f53ef3ad17b')
    cap_r = rc.rk_create(im=im, im_type=3040)  # 3040表示数字字母混合
    print('captcha:%s' % cap_r['Result'])
    image_name = './captcha_images/' + cap_r[
        'Result'] + '_' + current_timestamp() + '.jpg'
    if not os.path.exists('./captcha_images/'):
        os.mkdir('./captcha_images/')
    with open(image_name, 'wb') as f:
        f.write(im)
    return cap_r['Result']
Esempio n. 3
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()
Esempio n. 4
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()
Esempio n. 5
0
 def master_parse(self, response):
     item = {}
     selector = Selector(response)
     shifus = selector.xpath('//table[@class="table table-hover"]/tbody/tr')
     for master in shifus:
         item['aux_merc_account'] = response.meta['account_info']['username']
         item['password'] = response.meta['account_info']['password']
         item['aux_id_number'] = master.xpath('.//td[12]/a[1]/@data').extract()[0]
         item['aux_name'] = master.xpath('.//td[2]/text()').extract()[0]
         item['aux_serial_number'] = master.xpath('.//td[1]/text()').extract()[0]
         item['aux_phone'] = master.xpath('.//td[3]/text()').extract()[0]
         item['aux_archives_number'] = item['aux_serial_number'].replace('aux','')
         item['is_use'] = master.xpath('.//td[9]/div/@class').extract()[0]
         item['aux_add_time'] = current_timestamp()
         item['token'] = ''
         print item
         self.aux_db.save_master(item)
Esempio n. 6
0
def xyj_detail_parse(od_dict):
    '''美的订单详情数据组装'''
    item = OrderedDict()

    # dm_clean_order 表所需数据
    # 接件单号
    item['cord_user_name'] = od_dict['SERVICE_CUSTOMER_NAME']
    item['cord_user_tel'] = od_dict['CUSTOMER_TEL1']
    # 来源,喜悦家是1
    item['cord_source_id'] = 1
    addr_dict = get_every_addr(od_dict['SERVICE_CUSTOMER_ADDRESS'])  # 计算地址dict
    item['cord_user_address'] = addr_dict['addr_detail']
    item['cord_user_province'] = addr_dict['province']
    item['cord_user_city'] = addr_dict['city']
    item['cord_user_area'] = addr_dict['strict']
    # 备注,对应于美的的服务请求描述
    item['cord_remark'] = od_dict['SERVICE_DESC']
    # 订单号,待确认
    item['cord_num'] = 'Q' + datetime.datetime.now().strftime(
        '%Y%m%d%H%M%S') + str(random.randrange(1000, 9999))
    item['cord_is_pay'] = 0
    item['cord_create_time'] = current_timestamp()
    # 关联微信信息
    item['cord_open_id'] = 0
    # 订单关联渠道,默认0
    item['cord_merc_id'] = 0  #
    # 购买渠道id
    # item['ord_purchase_unit_id'] =    # 和渠道表的是同一个值,在查到渠道id后更新
    item['cord_status'] = 0  # 待发布
    # 业务类型
    item['cord_type'] = 0
    # 预约安装时间
    try:
        item['cord_ins_time'] = time_to_timestamp2(
            aptime_format(od_dict['APPOINT_TIME']))
    except:
        pass
    # 用户支付金额
    item['cord_user_cost'] = 0.0
    # 师傅所得金额
    # item['cord_mast_cost'] = '0.00'

    # clean_goods所需数据
    item['og_num'] = od_dict['PROD_NUM']
    return item
Esempio n. 7
0
    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())))
Esempio n. 8
0
    def get_authcode(self, uuid):
        im = self.get_image(uuid)
        rc = RClient('WongTH', '147258369', '89380',
                     'c2faa5c3ff5d4b459c703f53ef3ad17b')
        cap_r = rc.rk_create(im=im, im_type=3040)  # 3040表示数字字母混合
        try:
            print('captcha:%s' % cap_r['Result'])
        except KeyError as e:
            if str(e) == "'Result'":
                errorReport('ruokuai count run out')
                import sys
                sys.exit('ruokuai count run out')

        image_name = './captcha_images/' + cap_r[
            'Result'] + '_' + current_timestamp() + '.jpg'
        if not os.path.exists('./captcha_images/'):
            os.mkdir('./captcha_images/')
        with open(image_name, 'wb') as f:
            f.write(im)
        return cap_r['Result']
Esempio n. 9
0
    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')
Esempio n. 10
0
    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())))
Esempio n. 11
0
def detail_parse(od_dict, static_data, merchant):
    '''订单详情数据组装'''
    item = OrderedDict()

    # dm_order 表所需数据
    # 接件单号
    item['ord_cust_name'] = od_dict['customerName']
    item['ord_cust_tel'] = static_data['ord_cust_tel']
    addr_dict = parse_addr_jd(od_dict['serviceStreet'])  # 计算地址dict
    item['ord_cust_addr'] = addr_dict['addr_detail']
    item['ord_province'] = addr_dict['province']
    item['ord_city'] = addr_dict['city']
    item['ord_district'] = addr_dict['strict']
    item['ord_street'] = addr_dict['street']
    # 备注,对应于美的的服务请求描述
    item['ord_remark'] = ''
    # 用户报修故障
    item['ord_cust_fault'] = ''
    item['ord_num'] = create_sn()
    item['ord_pay_num'] = create_sn()
    item['ord_grab_addr'] = ''
    # 接件单号
    item['ord_accept_no'] = od_dict['orderId']
    # item['ord_ask_time'] =
    item['ord_create_time'] = current_timestamp()
    item['ord_buy_time'] = item['ord_create_time']
    lng_lat = get_latlng(
        addr_dict['city'],
        addr_dict['strict'] + addr_dict['street'] + addr_dict['addr_detail'])
    item['ord_cust_lng'] = lng_lat[0]
    item['ord_cust_lat'] = lng_lat[1]
    item['ord_weixin_num'] = ''
    # 商家id
    item['ord_merc_id'] = 1  # 兴科域
    # 购买单位,在后台表示信息来源
    item['ord_purchase_unit'] = u'京东'
    item['ord_status'] = 0  # 待发布
    item['ord_need_build'] = 2  # 不用建单
    # 业务类型
    if u'维修' in od_dict['serviceTypeName']:  # 根据实施业务类型字段判断业务类型
        item['ord_type'] = 5
    else:
        item['ord_type'] = 1
    ## 预约安装时间
    item['ord_ins_time'] = static_data['appoint_time']  # 和售后确认
    # 接件时间,接入时间
    item['ord_accept_time'] = time_to_timestamp3(
        static_data['ord_accept_time'])
    # 销售单位,购买渠道
    item['ord_sale_unit'] = u'京东'
    # 是否0元装
    if od_dict['freeinstall'] == 1:
        item['ord_free_ins'] = 1  # 免费
    elif od_dict['freeinstall'] == 2:
        item['ord_free_ins'] = 0  # 不免费
    # 购买渠道id
    item[
        'ord_purchase_unit_id'] = 0  # 和渠道表的是同一个值,在查到渠道id后更新,和ord_purchase_unit对应

    # dm_order之外所需数据
    product_name = od_dict['productName']
    p_num_regex = r")??.*?(?P<pi_num>[1-9](.[1-9])?)匹".decode('utf-8')
    model_regex = r"\((.*?)\)"
    # 商家名称
    item['shangjia'] = od_dict['outletsName']

    # 商家id
    item['merchant_id'] = merchant.platform_id
    # 购买渠道
    item['qudao'] = item['ord_sale_unit']

    # 匹数
    pi_result = re.search(p_num_regex, product_name)
    if pi_result:
        # item['pi_num'] = pi_result.group('pi_num') + 'P'   # 从产品名称中正则匹配匹数
        pass
    else:
        errorReport('regex pi_num fail', system_name='jd_parse_order')
    item['pi_num'] = pi_result.group('pi_num') + 'P'  # 从产品名称中正则匹配匹数

    # 产品型号
    model_result = re.search(model_regex, product_name)
    item['pro_model'] = model_result.group(1)  # 从产品名称中正则匹配型号

    ## 需要的数量
    item['pro_num'] = 1

    # 品牌名称
    point_index = od_dict['productBrandName'].index(u'(')
    item['brand'] = od_dict['productBrandName'][:point_index]

    # 默认电器id
    item['default_apl_id'] = 91  # 京东后台目前只有奥克斯的,渠道就是京东,商家兴科域

    return item
Esempio n. 12
0
    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')