Exemplo n.º 1
0
def get_goods_detail():

    if request.method == "POST":
        env = request.form.get('env', None)
        pid = request.form.get('pid', None)
        goodsId = request.form.get('goodsId', None)
        storeId = request.form.get('storeId', None)

        if goodsId == "" or storeId == "":
            res = {"status": 101, "message": "参数value为空"}
            return Response(json.dumps(res), mimetype='application/json')
        if goodsId == None:
            res = {"status": 102, "message": "请求参数为空"}
            return Response(json.dumps(res), mimetype='application/json')

        if env == None:
            env = "QA"
            print('-------------------------------------------------------')
            print("env参数为空,正在使用默认参数:{0}".format(env))

        # 字符串转大写
        env = env.upper()
        # 初始化修改商品价格类
        get_goods_detail = GetGoodsDetail(env=env, pid=pid)
        # 调用修改商品价格方法
        result = get_goods_detail.get_goods_detail(goodsId=goodsId,
                                                   storeId=storeId)
        res = {"code": 1, "msg": "请求成功", "请求场景": "查询商品详情", "data": result}
        return Response(json.dumps(res), mimetype='application/json')
    elif request.method == "GET":
        res = {"code": -1, "msg": '请使用POST请求方式'}
        return Response(json.dumps(res), mimetype='application/json')
Exemplo n.º 2
0
    def __init__(self, pid, env='QA'):
        self.log = Logger("debug")
        opera = OperationIni(fileName='config.ini', pathName='config')
        self.get_skuId = GetGoodsDetail(env=env, pid=pid)
        self.get_access_token = GetAccessToken(env=env, pid=pid)

        # env字符串转小写
        env = env.lower()
        key = env + '_url'

        self.base_url = opera.read_ini(section='goods', key=key)
        self.path = opera.read_ini(section='goods', key='wholeUpdateStock')
        self.access_token = self.get_access_token.get_ini_access_token()
Exemplo n.º 3
0
class updateGoodsPrice:
    def __init__(self, env='QA'):
        self.log = Logger("debug")
        self.opera = OperationIni(fileName='config.ini', pathName='config')
        self.get_skuId = GetGoodsDetail(env=env)
        self.get_access_token = GetAccessToken(env=env)

        # env字符串转小写
        env = env.lower()
        key = env + '_url'

        self.base_url = self.opera.read_ini(section='goods', key=key)
        self.path = self.opera.read_ini(section='goods', key='updatePrice')

        self.access_token = self.get_access_token.get_ini_access_token()

    def update_goods_price(self, storeId, goodsId, originalPrice, salePrice):
        '''
        修改商品价格
        :param storeId: 门店id
        :param goodsId: 商品id
        :param originalPrice: 市场价
        :param salePrice: 商家统一价
        :return: rsq
        '''

        url = self.base_url.format(self.path, self.access_token)

        # 获取skuId
        try:
            self.skuId = self.get_skuId.get_goods_detail(goodsId, storeId)[1]
            json_data = {
                'goodsId':
                goodsId,
                'skuList': [{
                    'skuId': self.skuId,
                    'originalPrice': originalPrice,
                    'salePrice': salePrice,
                }],
                'storeId':
                storeId
            }

            self.log.info('开始:调用update_goods_price方法,请求地址为:{0},入参为:{1}'.format(
                url, json_data))
            r = requests.post(url=url, json=json_data)
            # 如果access_token无效
            if r.json()['data'] == 'invalid accesstoken':
                self.log.warning('提示:ini文件中的accesstoken失效,开始获取新的accesstoken')
                # 获取最新的token并存入ini文件
                self.get_access_token.set_access_token()
                # 注意:这里一定要重新获取一次ini文件中的access_token
                new_access_token = self.get_access_token.get_ini_access_token()
                url = self.base_url.format(self.path, new_access_token)
                self.log.warning(
                    '开始:调用update_goods_price方法,请求地址为:{0},入参为:{1}'.format(
                        url, json_data))
                res = requests.post(url=url, json=json_data)
                self.log.warning('结束:调用update_goods_price方法,返回数据为:{0}'.format(
                    res.json()))
                return res.json()
            else:
                self.log.info('结束:调用update_goods_price方法,返回数据为:{0}'.format(
                    r.json()))
                return r.json()
        except Exception as f:
            self.log.error('修改商品失败,错误日志为:{0}'.format(f))
            return {'msg': '底层接口请求失败,请检查所传字段的数据是否正确'}
Exemplo n.º 4
0
class updateGoodsStock:
    def __init__(self, env='QA'):
        self.log = Logger("debug")
        opera = OperationIni(fileName='config.ini', pathName='config')
        self.get_skuId = GetGoodsDetail(env=env)
        self.get_access_token = GetAccessToken(env=env)

        # env字符串转小写
        env = env.lower()
        key = env + '_url'

        self.base_url = opera.read_ini(section='goods', key=key)
        self.path = opera.read_ini(section='goods', key='wholeUpdateStock')

        self.access_token = self.get_access_token.get_ini_access_token()

        # if env == 'QA':
        #     self.access_token = opera.read_ini(section='access_token', key='qa_access_token')
        # if env == 'DEV':
        #     self.access_token = opera.read_ini(section='access_token', key='dev_access_token')

    def update_goods_stock(self, goodsId, editStockNum, storeId=None):
        '''
        修改商品库存
        :param goodsId: 商品id
        :param editStockNum: 需要修改的库存
        :param storeId: 门店id
        :return: rsq
        '''

        url = self.base_url.format(self.path, self.access_token)
        # 获取skuId
        try:
            self.skuId = self.get_skuId.get_goods_detail(goodsId, storeId)[1]
            json_data = {
                'goodsId': goodsId,
                'storeId': storeId,
                'skuList': [{
                    'skuId': self.skuId,
                    'editStockNum': editStockNum
                }]
            }
            self.log.info('开始:调用update_goods_stock方法,请求地址为:{0},入参为:{1}'.format(
                url, json_data))
            r = requests.post(url=url, json=json_data)
            # 如果access_token无效
            if r.json()['data'] == 'invalid accesstoken':
                # 获取最新的token并存入ini文件
                self.log.warning('提示:ini文件中的accesstoken失效,开始获取新的accesstoken')
                self.get_access_token.set_access_token()
                # 注意:这里一定要重新获取一次ini文件中的access_token
                new_access_token = self.get_access_token.get_ini_access_token()
                url = self.base_url.format(self.path, new_access_token)
                self.log.warning(
                    '开始:调用update_goods_stock方法,请求地址为:{0},入参为:{1}'.format(
                        url, json_data))
                res = requests.post(url=url, json=json_data)
                self.log.warning('结束:调用update_goods_stock方法,返回数据为:{0}'.format(
                    res.json()))
                return res.json()
            else:
                self.log.info('结束:调用update_goods_stock方法,返回数据为:{0}'.format(
                    r.json()))
                return r.json()
        except Exception as f:
            self.log.error('调用获取商品详情接口失败,错误日志为:{0}'.format(f))
            return {'msg': '底层接口请求失败,请检查所传字段的数据是否正确'}