# coding:utf-8
# @fileName :2.每次随机生成有销售库存有实际库存的1个店铺商品和对应的2个店铺商品sku.py
# @createTime :2020/4/4 10:33
# @author :hongjingsheng
# @email :727803257@qq.com
# @software :PyCharm
# 请从下一行开始编写脚本
from testcase.goodsAPI.goodsSave.createData.create_one_goods_of_have_twoSku import Create_one_goods_of_have_twoSku
from testcase.goodsStockAPI.realStockSet.createData.set_real_stock_of_have_twoSku import Set_real_stock_of_have_twosSku
from testcase.itemAPI.itemSalesStockUpdate.createData.set_sales_stock_of_have_twoSku import Set_sales_stock_of_have_twoSku
from config.config import relationshipOfShopAndWarehouses
from model.m_kd_goods import M_kd_goods
from model.m_kd_item import M_kd_item
from model.m_kd_item_sku import M_kd_item_sku
m_kd_goods = M_kd_goods()
m_kd_item = M_kd_item()
m_kd_item_sku = M_kd_item_sku()
class run:
'''
1.该工具类实现功能:每次随机生成有销售库存有实际库存的1个店铺商品和对应的2个店铺商品sku;
2.生成数据用于:下订单、关联优惠券、用于拼团/秒杀/满减送活动等;
'''
def __init__(self,goods_lib_id:int,whatGroupOfDataDoYouChoose:str):
'''
:param goods_lib_id 参数含义:商品库id;数据类型:int
:param whatGroupOfDataDoYouChoose 参数含义:用户选择哪一组门店仓库关系
'''
self.goods_lib_id = goods_lib_id
self.whatGroupOfDataDoYouChoose = whatGroupOfDataDoYouChoose
self.oneRelationshipOfShopAndWarehouse = self.__oneRelationshipOfShopAndWarehouse()
self.sys_item_id = self.__get_one_sys_item_id()
self.two_sysSkuIds_skuIds = self.__get_two_sysSkuIds_skuIds()
self.sys_sku_id_of_sku_a = self.two_sysSkuIds_skuIds['商品A的第一个商品sku-a的信息']["sys_sku_id"]
self.sku_id_of_sku_a = self.two_sysSkuIds_skuIds['商品A的第一个商品sku-a的信息']["sku_id"]
self.sys_sku_id_of_sku_b = self.two_sysSkuIds_skuIds['商品A的第二个商品sku-b的信息']["sys_sku_id"]
self.sku_id_of_sku_b = self.two_sysSkuIds_skuIds['商品A的第二个商品sku-b的信息']["sku_id"]
self.out_item_id= self.realStockSet_of_DigitalStoreA()
self.realStockSet_of_OfflineStoreB()
self.realStockSet_of_OfflineStoreC()
self.set_sales_stock_of_have_twoSku()
self.log()
def __oneRelationshipOfShopAndWarehouse(self):
'''
:return 返回一组门店仓库关联数据;数据类型为int
'''
if self.whatGroupOfDataDoYouChoose == "第一组门店仓库关联数据":
return relationshipOfShopAndWarehouses["第一组门店仓库关联数据"]
elif self.whatGroupOfDataDoYouChoose == "第二组门店仓库关联数据":
return relationshipOfShopAndWarehouses["第二组门店仓库关联数据"]
elif self.whatGroupOfDataDoYouChoose == "第三组门店仓库关联数据":
return relationshipOfShopAndWarehouses["第三组门店仓库关联数据"]
else:
raise Exception("whatGroupOfDataDoYouChoose入参值输入错误;用户只能输入这三者中其中一个值:第一组门店仓库关联数据、第二组门店仓库关联数据、第三组门店仓库关联数据")
def __get_one_sys_item_id(self):
'''
:return 返回一个新增商品后的sys_item_id值;数据类型为int
'''
create_one_goods_of_have_twoSku = Create_one_goods_of_have_twoSku()
create_one_goods_of_have_twoSku.goodsLibId = self.goods_lib_id
r = create_one_goods_of_have_twoSku.sendRequest()
sys_item_id = r["result"]["sysItemId"]
return sys_item_id
def __get_two_sysSkuIds_skuIds(self):
'''
:return 返回一个商品的两个商品sku的sys_sku_id和sku_id等信息;数据类型为dict
'''
r = m_kd_goods.mysql_getRows_new("select sys_item_id,sys_sku_id,sku_id from kd_goods_sku where sys_item_id = %s"%self.sys_item_id)
result ={
"商品A的第一个商品sku-a的信息":{"sys_item_id":r[0][0],"sys_sku_id":r[0][1],"sku_id":r[0][2]},
"商品A的第二个商品sku-b的信息":{"sys_item_id":r[1][0],"sys_sku_id":r[1][1],"sku_id":r[1][2]}
}
print(result)
return result
def realStockSet_of_DigitalStoreA(self):
'''
:return 返回数字门店A的一个店铺商品的out_item_id值
1.接口主要实现功能: 设置店铺商品配置仓A的实际库存
'''
set_real_stock_of_have_twosSku = Set_real_stock_of_have_twosSku()
set_real_stock_of_have_twosSku.goodsLibId = self.goods_lib_id
set_real_stock_of_have_twosSku.realStockA = 100
set_real_stock_of_have_twosSku.sysSkuIdA = self.sys_sku_id_of_sku_a
set_real_stock_of_have_twosSku.realStockB = 100
set_real_stock_of_have_twosSku.sysSkuIdB = self.sys_sku_id_of_sku_b
set_real_stock_of_have_twosSku.sysItemId = self.sys_item_id
set_real_stock_of_have_twosSku.warehouseId = self.oneRelationshipOfShopAndWarehouse["数字门店A"]["绑定仓库id"]
r = set_real_stock_of_have_twosSku.sendRequest()
print(r)
# 当上面的接口请求成功后,会在kd_item表生成一条数字门店A的店铺商品A数据,可以获取到字段out_item_id的值
out_item_id = m_kd_item.get_one_random_value_of_one_tableField("out_item_id",[["sys_item_id",self.sys_item_id],["digit_shop_id",self.oneRelationshipOfShopAndWarehouse["数字门店A"]["门店id"]]])
return out_item_id
def realStockSet_of_OfflineStoreB(self):
'''
:return None
1.接口主要实现功能: 设置店铺商品一个线下仓B的实际库存
'''
set_real_stock_of_have_twosSku = Set_real_stock_of_have_twosSku()
set_real_stock_of_have_twosSku.goodsLibId = self.goods_lib_id
set_real_stock_of_have_twosSku.realStockA = 200
set_real_stock_of_have_twosSku.sysSkuIdA = self.sys_sku_id_of_sku_a
set_real_stock_of_have_twosSku.realStockB = 200
set_real_stock_of_have_twosSku.sysSkuIdB = self.sys_sku_id_of_sku_b
set_real_stock_of_have_twosSku.sysItemId = self.sys_item_id
set_real_stock_of_have_twosSku.warehouseId = self.oneRelationshipOfShopAndWarehouse["线下门店B"]["绑定仓库id"]
set_real_stock_of_have_twosSku.sendRequest()
def realStockSet_of_OfflineStoreC(self):
'''
:return None
1.接口主要实现功能: 设置店铺商品一个线下仓C的实际库存
'''
set_real_stock_of_have_twosSku = Set_real_stock_of_have_twosSku()
set_real_stock_of_have_twosSku.goodsLibId = self.goods_lib_id
set_real_stock_of_have_twosSku.realStockA = 300
set_real_stock_of_have_twosSku.sysSkuIdA = self.sys_sku_id_of_sku_a
set_real_stock_of_have_twosSku.realStockB = 300
set_real_stock_of_have_twosSku.sysSkuIdB = self.sys_sku_id_of_sku_b
set_real_stock_of_have_twosSku.sysItemId = self.sys_item_id
set_real_stock_of_have_twosSku.warehouseId = self.oneRelationshipOfShopAndWarehouse["线下门店C"]["绑定仓库id"]
set_real_stock_of_have_twosSku.sendRequest()
def set_sales_stock_of_have_twoSku(self):
'''
:return None
1.接口主要实现功能: 设置店铺商品和2个店铺商品sku的最大销售库存
'''
set_sales_stock_of_have_twoSku = Set_sales_stock_of_have_twoSku()
set_sales_stock_of_have_twoSku.goodsLibId = self.goods_lib_id
set_sales_stock_of_have_twoSku.salesStock_of_skuA = 600
set_sales_stock_of_have_twoSku.skuIdA = self.sku_id_of_sku_a
set_sales_stock_of_have_twoSku.salesStock_of_skuB = 600
set_sales_stock_of_have_twoSku.skuIdB = self.sku_id_of_sku_b
set_sales_stock_of_have_twoSku.outItemId = self.out_item_id
set_sales_stock_of_have_twoSku.salesStock_of_good = 1200
set_sales_stock_of_have_twoSku.shopId = self.oneRelationshipOfShopAndWarehouse["数字门店A"]["门店id"]
set_sales_stock_of_have_twoSku.sendRequest()
def log(self):
'''
:return None
1.接口主要实现功能: 输出相关日志
'''
print("1.生成一个商品A的sys_item_id值是:%s; --->值可以在kd_goods表里找到;"%self.sys_item_id)
print("2.生成一个商品A的两个商品sku的sys_sku_id和sku_id的信息:%s; --->值可以在kd_goods_sku表里找到;"%self.two_sysSkuIds_skuIds)
print("3.生成一个商品A的数字门店A的店铺商品A的out_item_id值是:%s; --->值可以在kd_item表里找到;"%self.out_item_id)
r1 = m_kd_item.get_one_random_value_of_one_tableField("sales_stock",[["sys_item_id",self.sys_item_id],["out_item_id",self.out_item_id],["digit_shop_id",self.oneRelationshipOfShopAndWarehouse["数字门店A"]["门店id"]],["goods_lib_id",self.goods_lib_id]])
r2 = m_kd_item_sku.get_one_random_value_of_one_tableField("sales_stock",[["out_item_id",self.out_item_id],["digit_shop_id",self.oneRelationshipOfShopAndWarehouse["数字门店A"]["门店id"]],["goods_lib_id",self.goods_lib_id],["sku_id",self.sku_id_of_sku_a]])
r3 = m_kd_item_sku.get_one_random_value_of_one_tableField("sales_stock",[["out_item_id",self.out_item_id],["digit_shop_id",self.oneRelationshipOfShopAndWarehouse["数字门店A"]["门店id"]],["goods_lib_id",self.goods_lib_id],["sku_id",self.sku_id_of_sku_b]])
print("4.生成一个店铺商品A的最大销售库存值是:%s --->值可以在kd_item表里找到;"%r1)
print("5.生成一个店铺商品A的一个店铺商品sku-a最大销售库存值是:%s --->值可以在kd_item_sku表里找到;"%r2)
print("6.生成一个店铺商品A的一个店铺商品sku-b最大销售库存值是:%s --->值可以在kd_item_sku表里找到;"%r3)
print("7.生成该店铺商品A和店铺商品sku-a&sku-b涉及的数字门店/线下门店/仓库等等信息为:%s"%self.oneRelationshipOfShopAndWarehouse)
if __name__ == "__main__":
r = run(100009,"第一组门店仓库关联数据")
2.相关调试结果(调试通过;数据库相关表信息都存储正确;)
3.备注
(1).类属性、类的实例化、类继承、类方法/属性重写, 等理论需熟悉;
(2).类被实例化后,属性和初始化参数会自动分配物理内存;