Arthur-Wu committed this file on 2024-11-18
This commit is contained in:
@ -63,7 +63,7 @@ class YMClientApi(object):
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def add_retire_purchase(self, GoodsInfoData, AddPurchaseQuantity, LoginData):
|
||||
def add_cart_goods(self, GoodsInfoData, AddPurchaseQuantity, LoginData):
|
||||
logging.info("========== [加入购物车] add_retire_purchase ==========")
|
||||
payload = json.dumps({
|
||||
"addGoods":[{
|
||||
@ -82,6 +82,115 @@ class YMClientApi(object):
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def delete_cart_goods(self, GoodsInfoData):
|
||||
logging.info("========== [删除购物车商品] delete_cart_goods ==========")
|
||||
payload = json.dumps({
|
||||
"addGoods": [],
|
||||
"autoSelectCoupon": True,
|
||||
"coupons": [],
|
||||
"deleteGoods": [{
|
||||
"inputCode": "6924743915848",
|
||||
"isNormalAddPurchase": True,
|
||||
"qty": 1,
|
||||
"uuid": ["23B2363A224E4933942992F84B937D7D"],
|
||||
"weight": 0
|
||||
}],
|
||||
"existGoods": [{
|
||||
"inputCode": "6924743915848",
|
||||
"isNormalAddPurchase": True,
|
||||
"qty": 1,
|
||||
"uuid": ["23B2363A224E4933942992F84B937D7D"],
|
||||
"weight": 155
|
||||
}],
|
||||
"orderNo": "1858386778027515904"
|
||||
})
|
||||
|
||||
add_2_result = {
|
||||
"code": 0,
|
||||
"msg": "成功",
|
||||
"data": {
|
||||
"remainAmount": "13.8",
|
||||
"totalDisc": "0.0",
|
||||
"orderItemList": [{
|
||||
"uuid": ["2BEDF9C6DD954E1FB3DCD9A9F3C57D29"], #
|
||||
"qty": 1, #
|
||||
"marketPrice": "5",
|
||||
"salePrice": "5.00",
|
||||
"totalSalePrice": "5",
|
||||
"minWeight": 0,
|
||||
"weight": 0,
|
||||
"maxWeight": 0,
|
||||
"goodsPic": "https://ieemoo-storage.obs.cn-east-3.myhuaweicloud.com/lhpic/6925303796426.jpg",
|
||||
"barcode": "6925303796426",
|
||||
"inputCode": "6925303796426",
|
||||
"goodsName": "统一茄皇蕃茄牛肉面",
|
||||
"goodsPromotionTags": null,
|
||||
"measureProperty": 0,
|
||||
"shoppingBagFlag": false,
|
||||
"activityId": null,
|
||||
"activityDescription": null,
|
||||
"totalPromotionPrice": 0,
|
||||
"categoryCode": null,
|
||||
"isOneBarcodeMore": false,
|
||||
"pkgFlag": false
|
||||
},
|
||||
{
|
||||
"uuid": ["F9BBA7C9AF7944FF91C717E3D18BD682"],
|
||||
"qty": 1,
|
||||
"marketPrice": "8.8",
|
||||
"salePrice": "8.80",
|
||||
"totalSalePrice": "8.8",
|
||||
"minWeight": 0,
|
||||
"weight": 0,
|
||||
"maxWeight": 0,
|
||||
"goodsPic": "https://ieemoo-storage.obs.cn-east-3.myhuaweicloud.com/lhpic/6924743915848.jpg",
|
||||
"barcode": "6924743915848",
|
||||
"inputCode": "6924743915848",
|
||||
"goodsName": "乐事无限翡翠黄瓜味薯片",
|
||||
"goodsPromotionTags": null,
|
||||
"measureProperty": 0,
|
||||
"shoppingBagFlag": false,
|
||||
"activityId": null,
|
||||
"activityDescription": null,
|
||||
"totalPromotionPrice": 0,
|
||||
"categoryCode": null,
|
||||
"isOneBarcodeMore": false,
|
||||
"pkgFlag": false
|
||||
}],
|
||||
"bagInfoList": null,
|
||||
"couponMap": null,
|
||||
"activityGoodsList": null
|
||||
}
|
||||
}
|
||||
|
||||
del_201 = {
|
||||
"addGoods": [],
|
||||
"autoSelectCoupon": True,
|
||||
"coupons": [],
|
||||
"deleteGoods": [{
|
||||
"inputCode": "6924743915848",
|
||||
"isNormalAddPurchase": True,
|
||||
"qty": 1,
|
||||
"uuid": ["F9BBA7C9AF7944FF91C717E3D18BD682"],
|
||||
"weight": 0
|
||||
}],
|
||||
"existGoods": [{
|
||||
"inputCode": "6925303796426",
|
||||
"isNormalAddPurchase": True,
|
||||
"qty": 1,
|
||||
"uuid": ["2BEDF9C6DD954E1FB3DCD9A9F3C57D29"],
|
||||
"weight": 165 # GoodsInfoData["data"]["weight"]
|
||||
}, {
|
||||
"inputCode": "6924743915848",
|
||||
"isNormalAddPurchase": True,
|
||||
"qty": 1,
|
||||
"uuid": ["F9BBA7C9AF7944FF91C717E3D18BD682"],
|
||||
"weight": 160 # GoodsInfoData["data"]["weight"]
|
||||
}],
|
||||
"orderNo": "1858386778027515904"
|
||||
}
|
||||
|
||||
def get_coupon_list(self):
|
||||
logging.info("========== [获取优惠券列表] get_coupon_list ==========")
|
||||
@ -116,13 +225,16 @@ class YMClientApi(object):
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
def get_cart_goods_info(self, GoodsInfoData):
|
||||
def get_cart_goods_info(self, GoodsDataList):
|
||||
logging.info("========== [获取购物车商品信息] get_cart_goods_info ==========")
|
||||
payload = json.dumps({"goodsParamList":[{
|
||||
"inputCode": GoodsInfoData["data"]["inputCode"],
|
||||
"qty": GoodsInfoData["data"]["qty"],
|
||||
"weight": int(GoodsInfoData["data"]["weight"]),
|
||||
}]})
|
||||
goods_param_lList = []
|
||||
for goods_data in GoodsDataList:
|
||||
goods_dict = {}
|
||||
goods_dict["inputCode"] = goods_data["data"]["inputCode"]
|
||||
goods_dict["qty"] = goods_data["data"]["qty"]
|
||||
goods_dict["weight"] = int(goods_data["data"]["weight"])
|
||||
goods_param_lList.append(goods_dict)
|
||||
payload = json.dumps({"goodsParamList": goods_param_lList})
|
||||
url = self.Domain+"/v2/shopping/cart/goods/info"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
@ -142,12 +254,6 @@ class YMClientApi(object):
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
return response.json()
|
||||
|
||||
''' 加购购物袋
|
||||
POST
|
||||
https://api.test.yimaogo.com/cart/v2/shopping/add/retire/purchase
|
||||
|
||||
'''
|
||||
|
||||
''' 2- without sessionid '''
|
||||
def get_ads_list(self):
|
||||
logging.info("========== [获取广告列表] get_ads_list ==========")
|
||||
@ -185,7 +291,7 @@ if __name__ == '__main__':
|
||||
CouponListData = ymc.get_coupon_list() # step6:获取优惠券列表
|
||||
ymc.receive_coupon(CouponListData) # step7:领取优惠券
|
||||
ymc.query_coupon_list_user() # step8:查询用户持有的优惠券列表
|
||||
ymc.add_retire_purchase(GoodsInfoData, 1, LoginData) # step9:加购商品 ------ 6924882486100
|
||||
ymc.add_cart_goods(GoodsInfoData, 1, LoginData) # step9:加购商品 ------ 6924882486100
|
||||
ymc.get_cart_goods_info(GoodsInfoData) # step10:获取购物车商品信息
|
||||
ymc.request_order_settlement(LoginData) # step11:请求订单结算
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
import requests,json, time, logging
|
||||
from configs.globalParams import *
|
||||
from commons.SignatureYM import SignatureYM
|
||||
from commons.FileHandler import Txt
|
||||
|
||||
|
||||
class YMServiceApi(object):
|
||||
@ -14,65 +15,105 @@ class YMServiceApi(object):
|
||||
self.headerss = SignatureYM().return_headers()
|
||||
|
||||
''' 1-广告模块 '''
|
||||
def publish_ad(self, ADDetail, MarketAndStoreDetail):
|
||||
def publish_ad(self, ADDetailList, MarketAndStoreDetail):
|
||||
logging.info("========== [发布广告] ==========")
|
||||
timeStamp = str(int(time.time()))
|
||||
PublicParams = {
|
||||
"status": 4, "name": "Auto"+timeStamp,
|
||||
"agencyId": 3, "agencyName": "洪家班", "advertiserId": 3,
|
||||
"advertiserName": "阿宝传媒", "adsUse": 1, "customerTag": 3,
|
||||
"putRangeCycle": "[7,6,5,1,2,3,4]",
|
||||
"addType": 1, "pricingType": 1, "standardPrice": "1", "minPrice": "1",
|
||||
"putStart": GlobalParams["todayDate"], "putEnd": GlobalParams["todayDate"],
|
||||
"putStartTime": "00:00:00", "putEndTime": "23:00:00"
|
||||
}
|
||||
payload = json.dumps(PublicParams | ADDetail | MarketAndStoreDetail)
|
||||
url = self.Domain + "admin/ads"
|
||||
def __publish(ADDetail, MarketAndStoreDetail):
|
||||
timeStamp = str(int(time.time()))
|
||||
PublicParams = {
|
||||
"status": 4, "name": "Auto"+timeStamp,
|
||||
"agencyId": 3, "agencyName": "洪家班", "advertiserId": 3,
|
||||
"advertiserName": "阿宝传媒", "adsUse": 1, "customerTag": 3,
|
||||
"putRangeCycle": "[7,6,5,1,2,3,4]",
|
||||
"addType": 1, "pricingType": 1, "standardPrice": "1", "minPrice": "1",
|
||||
"putStart": GlobalParams["todayDate"], "putEnd": GlobalParams["todayDate"],
|
||||
"putStartTime": "00:00:00", "putEndTime": "23:00:00"
|
||||
}
|
||||
payload = json.dumps(PublicParams | ADDetail | MarketAndStoreDetail)
|
||||
url = self.Domain + "admin/ads"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
|
||||
for adDetail in ADDetailList:
|
||||
__publish(adDetail, MarketAndStoreDetail)
|
||||
time.sleep(0.5)
|
||||
|
||||
def add_promotional_product_whitelist(self, GoodsInfo, MarketAndStoreInfo):
|
||||
logging.info("========== [新增促销白名单] ==========")
|
||||
payload = json.dumps({
|
||||
"goodsType": 3,
|
||||
"dataScope": 1,
|
||||
"categoryCode": "",
|
||||
"categoryName": "",
|
||||
"barcode": GoodsInfo["GoodsInputcode"],
|
||||
"goodsName": GoodsInfo["GoodsName"],
|
||||
"storeId": MarketAndStoreInfo["StoreId"],
|
||||
"marketId": MarketAndStoreInfo["MarketId"]
|
||||
})
|
||||
url = self.Domain + "admin/goods/promotion"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
if response.status_code == 200:
|
||||
time.sleep(0.5)
|
||||
rspJson = response.json()
|
||||
goodsWhiteListID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("ScenarioTest_GoodsWhiteListID.txt", str(goodsWhiteListID))
|
||||
if not writeResult:
|
||||
logging.error(f"---写入 新建促销商品白名单ID 失败!")
|
||||
|
||||
def delete_whitelist_goods(self):
|
||||
logging.info("========== [删除促销白名单商品] ==========")
|
||||
GoodsWhiteListIDList = Txt().read_txt("ScenarioTest_GoodsWhiteListID.txt")
|
||||
for i in range(len(GoodsWhiteListIDList)):
|
||||
if GoodsWhiteListIDList[i] not in [None, '']:
|
||||
url = self.Domain + "admin/goods/promotion/{GoodsWhiteListID}".replace(
|
||||
"{GoodsWhiteListID}", str(GoodsWhiteListIDList[i]))
|
||||
logging.info(f"---删除促销白名单商品接口URL为:: {url}")
|
||||
response = requests.request(method="DELETE", url=url, headers=HEADERS, data={})
|
||||
logging.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
logging.info(f"---接口返回体为:: {response.json()}\n")
|
||||
|
||||
def add_weight_to_whitelist(self, GoodsInfo, MarketAndStoreInfo):
|
||||
logging.info("========== [新增重量放通白名单] ==========")
|
||||
payload = json.dumps({
|
||||
"goodsType": 4,
|
||||
"content": GoodsInfo["GoodsInputcode"],
|
||||
"type": 1,
|
||||
"dataScope": 1,
|
||||
"reason": "自动化测试之场景测试",
|
||||
"storeId": MarketAndStoreInfo["StoreId"],
|
||||
"marketId": MarketAndStoreInfo["MarketId"]
|
||||
})
|
||||
url = self.Domain + "admin/goods/weight/promotion"
|
||||
response = requests.request("POST", url, headers=self.headerss, data=payload)
|
||||
logging.info(f"-----------接口返回状态码:{response.status_code}")
|
||||
logging.info(f"-----------接口返回数据:{response.json()}\n\n")
|
||||
if response.status_code == 200:
|
||||
time.sleep(0.5)
|
||||
rspJson = response.json()
|
||||
weightWhiteListID = rspJson["data"]['id']
|
||||
writeResult = Txt().append_write_txt("ScenarioTest_WeightWhiteListID.txt", str(weightWhiteListID))
|
||||
if not writeResult:
|
||||
logging.error(f"---写入 新建重量放通白名单ID 失败!")
|
||||
|
||||
def delete_weight_whitelist_goods(self):
|
||||
logging.info("========== [删除重量放通白名单商品] ==========")
|
||||
WeightWhiteListIDList = Txt().read_txt("ScenarioTest_WeightWhiteListID.txt")
|
||||
for i in range(len(WeightWhiteListIDList)):
|
||||
if WeightWhiteListIDList[i] not in [None, '']:
|
||||
url = self.Domain + "admin/goods/weight/promotion/{WeightWhiteListID}".replace(
|
||||
"{WeightWhiteListID}", str(WeightWhiteListIDList[i]))
|
||||
logging.info(f"---删除重量放通白名单商品接口URL为:: {url}")
|
||||
response = requests.request(method="DELETE", url=url, headers=self.headerss, data={})
|
||||
logging.info(f"---接口返回状态码为:: {response.status_code}")
|
||||
logging.info(f"---接口返回体为:: {response.json()}\n\n")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
yms = YMServiceApi()
|
||||
''' 武商 '''
|
||||
ADDetail = [
|
||||
{ # 登录页
|
||||
"adsAreaId": 1, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/534ae9d7-3f65-48da-bc2e-3d5e66fe56d8.jpg",
|
||||
"showOrder": 1, "showTime": 5,
|
||||
},
|
||||
{ # 登录后弹窗
|
||||
"adsAreaId": 2, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/93e34d0e-9f4c-499b-ad8b-5741e55528b5.jpg",
|
||||
},
|
||||
{ # 购物车主页
|
||||
"adsAreaId": 3, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/581ec30a-4d90-43f3-b0e9-b5c8fe0006b4.jpg",
|
||||
"showOrder": 1, "showTime": 5,
|
||||
},
|
||||
{ # 待机页
|
||||
"adsAreaId": 4, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/8c8f6de0-6eb7-4b66-98cd-2c85eb057ed5.png",
|
||||
"showOrder": 1, "showTime": 5,
|
||||
},
|
||||
{ # 扫码
|
||||
"adsAreaId": 5, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/9d5555e3-fec1-4e1a-94e7-b517f4e88aba.jpg",
|
||||
},
|
||||
{ # 支付后
|
||||
"adsAreaId": 6, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/e2e2e892-1a81-4b0f-9af2-cb46f04a5dc4.jpg",
|
||||
},
|
||||
{ # 小票
|
||||
"adsAreaId": 7, "mediaType": 1,
|
||||
"mediaUrl": "ads/content/6d9c14ca-3fd1-4fe7-b04a-84cf18937e60.jpg",
|
||||
}
|
||||
]
|
||||
MarketAndStoreDetail = {"putMarketId": 50, "putStoreId": ["29"]}
|
||||
for ad in ADDetail:
|
||||
yms.publish_ad(ad, MarketAndStoreDetail)
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
|
||||
GoodsInfo = {"GoodsInputcode": "6924743915848"}
|
||||
MarketAndStoreInfo = {"MarketId": 50, "StoreId": 29}
|
||||
yms.add_weight_to_whitelist(GoodsInfo, MarketAndStoreInfo)
|
||||
time.sleep(10)
|
||||
yms.delete_weight_whitelist_goods()
|
Reference in New Issue
Block a user