def product_audit_dailysale(start_at=Common.current_time()[:10]): op_token = cf.operation_token1 su_token = cf.supplier_token # 供应商添加商品 obj = Business().post_GetVerifyCode(token=su_token, phone=19986415739) code = obj.json()['data']['content'] time.sleep(3) obj = Business().post_ProductAfterSale(token=su_token, code=code, mobile=19986415739) product_after_sale_id = obj.json()['data']['id'] p = Business.post_products(su_token, freight_template=[1, 2], product_after_sale_id=product_after_sale_id) product_id = Common.loads_text(p)["data"][0]["attributes"]["id"] # 运维审核通过 Business.CompleteAudit(product_id) # 运维获取悟空团列表 w = Business.get_daily_sales(op_token) # print(int(Common.loads_text(w)["data"]["today"])+type(Common.loads_text(w)["data"]["today"])) if Common.loads_text(w)["data"]["today"] == []: # 运维添加拼团 Business.post_daily_sale_create(op_token, product_id=product_id, start_at=start_at) else: daily_sale_id = Common.loads_text(w)["data"]["today"]["id"] # 运维修改拼团 product_list = Common.loads_text(w)["data"]["today"]["products"] Business.modify_dailysale(op_token, daily_sale_id, product_list, product_id) # 运维获取悟空团列表 w = Business.get_daily_sales(op_token) product_id = Common.loads_text(w)["data"]["today"]["products"][0]['id'] return product_id
def modify_dailysale(op_token, daily_sales_id, product_list, product_id, start_at=Common.current_time()[:10]): products = [{"product_id": product_id}] if len(product_list) <= 4: for i in product_list: products.append({"product_id": i["product_id"]}) # sku=[] # for sk in i["product_skus"]: # sku.append({"price": sk["price"], "sku_id": sk["sku_id"]}) # products.append({"product_id": i["product_id"], "sku": sku}) else: for i in product_list[:4]: products.append({"product_id": i["product_id"]}) data = { "id": daily_sales_id, "start_at": start_at, "products": products, "cover": "https://mayistatic.bc2c.cn/FtuiEMOuduOnpuiE3r_m7OMor-Fa?imageMogr2/auto-orient" } data1 = Common.dumps_text(data) obj = Http.post(Common.first_url() + "admin/DailySaleUpdate", data1, op_token) print("编辑团" + str(obj.status_code)) Common.out_error(obj) return obj
def get_daily_sales(token, start_at=Common.current_time()[:10], end_at=None, page=1, pageSize=15, order="desc", orderField=None, isDailySale=None, status=None, product_name=None, approval_status=None): data = { "start_at": start_at, # 开团时间格式:2019-3-28,默认今天 "end_at": end_at, "page": page, "pageSize": pageSize, "order": order, "orderField": orderField, "isDailySale": isDailySale, # 悟空团编辑时调用,值是1 "status": status, "product_name": product_name, "approval_status": approval_status } obj = Http.get(Common.first_url() + "admin/DailySales", data, token) print("获取悟空团管理列表" + str(obj.status_code)) Common.out_error(obj) return obj
def post_daily_sale_create( token, start_at=Common.current_time()[:10], product_id=None, cover="https://mayistatic.bc2c.cn/FtuiEMOuduOnpuiE3r_m7OMor-Fa?imageMogr2/auto-orient" ): data = { "start_at": start_at, # 开团日期格式:"2019-03-29", # 参团商品,最多六件 "products": [{ "product_id": product_id }], "cover": cover, # 悟空团分享主图: } data1 = Common.dumps_text(data) obj = Http.post(Common.first_url() + "admin/DailySaleCreate", data1, token) print(obj.json()) print("添加悟空团" + str(obj.status_code)) Common.out_error(obj) return obj