Exemple #1
0
    def post(self):
        order_id = self.get_argument("jd_order_id", "")
        coupon = self.get_argument("jd_coupon_no", "")

        # 根据订单号查券
        if order_id:
            coupons = []
            i = 0
            while True:
                jd_coupons = Jingdong(
                    "getCouponsList",
                    options.jingdong_fx_vender_id,
                    options.jingdong_fx_vender_key,
                    options.jingdong_fx_secret_key,
                )
                response_coupons = jd_coupons.sync_fetch(order_id=order_id, start=i * 100, count=100)
                jd_coupons.parse_response(response_coupons)
                if jd_coupons.is_ok():
                    current_coupons = [
                        {
                            "coupon_sn": c.findtext("CouponId"),
                            "coupon_pwd": c.findtext("CouponPwd"),
                            "status": c.findtext("CouponStatus"),
                        }
                        for c in jd_coupons.message.findall("Coupons/Coupon")
                    ]
                    coupons.extend(current_coupons)
                    i += 1
                    if len(current_coupons) != 100:
                        break
                else:
                    logging.error("failed to query jd_coupons for jd_order_id: %s", order_id)
                    break

            self.render("coupon/imported_jd.html", coupons=coupons)
            return
        # 根据券号查
        if coupon:
            jd = Jingdong(
                "queryCouponStatus",
                options.jingdong_fx_vender_id,
                options.jingdong_fx_vender_key,
                options.jingdong_fx_secret_key,
            )
            resp = jd.sync_fetch(coupon=coupon)
            jd.parse_response(resp)
            if jd.is_ok():
                jd_coupons = [
                    {
                        "coupon_sn": c.findtext("CouponId"),
                        "coupon_pwd": c.findtext("CouponPwd"),
                        "status": str(c.findtext("CouponStatus")),
                    }
                    for c in jd.message.findall("Coupons/Coupon")
                ]
                self.render("coupon/imported_jd.html", coupons=jd_coupons)
                return

        self.render("coupon/imported_jd.html", coupons=None)
Exemple #2
0
    def post(self):
        order_id = self.get_argument('jd_order_id', '')
        coupon = self.get_argument('jd_coupon_no', '')

        # 根据订单号查券
        if order_id:
            coupons = []
            i = 0
            while True:
                jd_coupons = Jingdong('getCouponsList',
                                      options.jingdong_fx_vender_id,
                                      options.jingdong_fx_vender_key,
                                      options.jingdong_fx_secret_key)
                response_coupons = jd_coupons.sync_fetch(order_id=order_id,
                                                         start=i * 100,
                                                         count=100)
                jd_coupons.parse_response(response_coupons)
                if jd_coupons.is_ok():
                    current_coupons = [{
                        'coupon_sn': c.findtext('CouponId'),
                        'coupon_pwd': c.findtext('CouponPwd'),
                        'status': c.findtext('CouponStatus')
                    } for c in jd_coupons.message.findall('Coupons/Coupon')]
                    coupons.extend(current_coupons)
                    i += 1
                    if len(current_coupons) != 100:
                        break
                else:
                    logging.error(
                        'failed to query jd_coupons for jd_order_id: %s',
                        order_id)
                    break

            self.render('coupon/imported_jd.html', coupons=coupons)
            return
        # 根据券号查
        if coupon:
            jd = Jingdong('queryCouponStatus', options.jingdong_fx_vender_id,
                          options.jingdong_fx_vender_key,
                          options.jingdong_fx_secret_key)
            resp = jd.sync_fetch(coupon=coupon)
            jd.parse_response(resp)
            if jd.is_ok():
                jd_coupons = [{
                    'coupon_sn': c.findtext('CouponId'),
                    'coupon_pwd': c.findtext('CouponPwd'),
                    'status': str(c.findtext('CouponStatus'))
                } for c in jd.message.findall('Coupons/Coupon')]
                self.render('coupon/imported_jd.html', coupons=jd_coupons)
                return

        self.render('coupon/imported_jd.html', coupons=None)
Exemple #3
0
def sync_jd(db):
    goods = db.query(
        "select gds.id,gds.status,gds.distributor_goods_id,"
        "gds.goods_link_id,ds.taobao_api_info,ds.taobao_seller_id "
        "from goods_distributor_shop gds, distributor_shop ds "
        'where gds.distributor_shop_id=ds.id and gds.status <> "PREPARE" and gds.deleted=0 '
        'and gds.distributor_goods_id <> "" and ds.distributor_id=%s',
        options.distributor_id_jingdong,
    )
    now = datetime.now()
    for g in goods:
        api_info = json.loads(g.taobao_api_info, object_hook=json_hook)
        jingdong = Jingdong("queryTeamInfo", str(g.taobao_seller_id), api_info.vender_key, api_info.secret_key)
        response = jingdong.sync_fetch(vender_team_id=g.goods_link_id, jd_team_id=g.distributor_goods_id)
        jingdong.parse_response(response)
        if not jingdong.is_ok():
            if jingdong.result_code == "-538":
                db.execute('update goods_distributor_shop set deleted="1", deleted_at=NOW() ' "where id=%s", g.id)
                logging.info("sync goods status. delete jingdong item %s", g.distributor_goods_id)
            else:
                logging.error("sync goods status. jingdong request error %s", response)
            continue
        end_time = datetime.fromtimestamp(int(jingdong.message.findtext("EndTime")))
        if end_time < now and g.status != "OFF_SALE":
            db.execute(
                'update goods_distributor_shop set status="OFF_SALE", offsale_at=NOW(), onsale_at=NULL ' "where id=%s",
                g.id,
            )
            logging.info("sync goods status. offsale jingdong item %s", g.distributor_goods_id)
        elif end_time > now and g.status != "ON_SALE":
            db.execute(
                'update goods_distributor_shop set status="ON_SALE", onsale_at=NOW(), offsale_at=NULL ' "where id=%s",
                g.id,
            )
            logging.info("sync goods status. onsale jingdong item %s", g.distributor_goods_id)
Exemple #4
0
def sync_jd(db):
    goods = db.query(
        'select gds.id,gds.status,gds.distributor_goods_id,'
        'gds.goods_link_id,ds.taobao_api_info,ds.taobao_seller_id '
        'from goods_distributor_shop gds, distributor_shop ds '
        'where gds.distributor_shop_id=ds.id and gds.status <> "PREPARE" and gds.deleted=0 '
        'and gds.distributor_goods_id <> "" and ds.distributor_id=%s',
        options.distributor_id_jingdong)
    now = datetime.now()
    for g in goods:
        api_info = json.loads(g.taobao_api_info, object_hook=json_hook)
        jingdong = Jingdong('queryTeamInfo', str(g.taobao_seller_id),
                            api_info.vender_key, api_info.secret_key)
        response = jingdong.sync_fetch(vender_team_id=g.goods_link_id,
                                       jd_team_id=g.distributor_goods_id)
        jingdong.parse_response(response)
        if not jingdong.is_ok():
            if jingdong.result_code == '-538':
                db.execute(
                    'update goods_distributor_shop set deleted="1", deleted_at=NOW() '
                    'where id=%s', g.id)
                logging.info('sync goods status. delete jingdong item %s',
                             g.distributor_goods_id)
            else:
                logging.error('sync goods status. jingdong request error %s',
                              response)
            continue
        end_time = datetime.fromtimestamp(
            int(jingdong.message.findtext('EndTime')))
        if end_time < now and g.status != 'OFF_SALE':
            db.execute(
                'update goods_distributor_shop set status="OFF_SALE", offsale_at=NOW(), onsale_at=NULL '
                'where id=%s', g.id)
            logging.info('sync goods status. offsale jingdong item %s',
                         g.distributor_goods_id)
        elif end_time > now and g.status != 'ON_SALE':
            db.execute(
                'update goods_distributor_shop set status="ON_SALE", onsale_at=NOW(), offsale_at=NULL '
                'where id=%s', g.id)
            logging.info('sync goods status. onsale jingdong item %s',
                         g.distributor_goods_id)