Example #1
0
 def test():
     redis = Redis()
     for i in range(160):
         j = redis.get("image%s" % str(i))
         if j is None:
             print("image%s" % str(i))
         else:
             pass
Example #2
0
 def delete_user_by_mobile(self, mobile):
     user_info = Tool.query_user_info_by_mobile(mobile)
     if user_info:
         redis = Redis()
         user_index = int(redis.get('user_index'))
         DataBaseOperate().operate(
             "39.104.28.40", "farm-uc",
             'UPDATE t_user SET mobile = "%s" WHERE mobile = "%s";' %
             (str(user_index), str(mobile)))
         self.L.logger.debug('原手机号 %s 修改为 %s' %
                             (str(mobile), str(user_index)))
         redis.set('user_index', user_index + 1)
     else:
         raise Exception('手机号输入错误: %s' % str(mobile))
Example #3
0
 def upload_image(self):
     redis = Redis()
     get_index = int(redis.get('get_index')) - 15
     for i in range(1, 16):
         if round((os.path.getsize("./Images/banner" + str(i) + ".jpg")) /
                  1000.0 / 1000.0, 1) < 5:
             Request().post_file(
                 url="http://39.104.28.40:9600/common/farm/upload-img",
                 file_path="./Images/banner%s.jpg" % str(i))
             # zyp_url = json.loads(response)["content"]
             # redis.set("image%s" % str(get_index + i), zyp_url)
             self.L.logger.debug("image%s uploaded !" % str(get_index + i))
         else:
             self.L.logger.debug("image%s exceed size !" %
                                 str(get_index + i))
Example #4
0
 def get_images(self, key='farm'):
     redis = Redis()
     # redis.set('get_index', 0)
     get_index = int(redis.get('get_index'))
     response = Request().get(
         'https://www.pexels.com/search/%s/?page=%s&format=html' %
         (key, str((get_index / 15) + 1)))
     soup = BeautifulSoup(response)
     images = soup.findAll('a', attrs={'href': re.compile("(^https.*)\?")})
     # list_start = get_index
     # list_end = list_start + 15
     i = 0
     for link in images:
         image_url = '%s&auto=compress\n' % link.get('href')
         self.L.logger.debug(image_url)
         image = Request().get(image_url)
         i += 1
         with open('./Images/banner%s.jpg' % str(i), 'wb') as picture:
             picture.write(image)
class SupplierAction(object):
    hosts = Config('config').data['hosts'][Config('config').data['run']]

    def __init__(self, supplier):
        self.log = Log('SupplierAction')
        self.supplier = supplier
        self.request = Request()
        self.tool = Tool()
        self.redis = Redis()
        self.db = DataBaseOperate()
        self.ps = 10

    def supp_upload(self, address, name):
        """
            上传供应商身份证照片
            :return:
            """
        response = self.request.post_file(
            url=self.hosts['MS_USER'] + '/mobile/supplier/upload',
            file_path=address,
            data_dict={
                "_tk_": self.supplier.token,
                "_deviceId_": self.supplier.device_id,
                "identityFile": name
            },
            file_key="identityFile")
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def supp_update(self, positive_img, negative_img):
        """
        提交供应商身份证认证资料
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "userId": self.supplier.user_id,
            "positive": positive_img,
            "negative": negative_img
        }
        rul = self.hosts['MS_USER'] + "/mobile/supplier/update"
        data = bind_data
        response = self.request.post(rul, data)
        json_response = json.loads(response)
        query_re = self.tool.ms_query_supplier_supp_update_by_user_id(
            self.supplier.user_id)
        if query_re is not None:
            query_re = query_re[0]
        if json_response["status"] == "OK":
            assert query_re['positive'] == positive_img
            assert query_re['negative'] == negative_img
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def supp_get_fail(self):
        """
        获取未通过的供应商身份认证资料
        断言需优化
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "userId": self.supplier.user_id
        }
        rul = self.hosts['MS_USER'] + "/mobile/supplier/get-fail"
        data = bind_data
        response = self.request.post(rul, data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def shop_get(self):
        """
        通过当前用户,获取店铺信息
        断言需优化
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     '/mobile/shop/get',
                                     data=bind_data)
        json_response = json.loads(response)
        query_re = self.tool.ms_query_supplier_shop_get_by_user_id(
            self.supplier.user_id)
        if query_re is not None:
            query_re = query_re[0]
        if json_response["status"] == "OK":
            assert query_re['id'] == json_response["content"]["shopId"]
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def upload_avatar(self, address, name):
        """
        上传店铺头像
        :return:
        """
        response = self.request.post_file(
            url=self.hosts['MS_SHOP'] + '/mobile/shop/upload-avatar',
            file_path=address,
            data_dict={
                "_tk_": self.supplier.token,
                "_deviceId_": self.supplier.device_id,
                "avatar": name
            },
            file_key='avatar')
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def shop_send_verify_code(self, shop_mobile):
        """
        发送修改店铺联系电话验证码
        断言需优化
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "mobile": shop_mobile
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/shop/send-verify-code",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def shop_update_mobile(self, shop_mobile):
        """
        提交修改店铺联系电话验证码
        断言需优化
        :return:
        """
        bind_data = {
            "_tk_":
            self.supplier.token,
            "_deviceId_":
            self.supplier.device_id,
            "mobile":
            shop_mobile,
            "verifyCode":
            int(
                self.redis.get('ShopManagerImpl:modify_shop_mobile:%s_%s' %
                               (str(self.supplier.user_id), str(shop_mobile))))
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/shop/update-mobile",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def update_shop_info(self, shop):
        """
        更新店铺信息
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "sellerId": self.supplier.user_id,
            "name": shop.name,
            "shopId": self.supplier.supplier_shop_id,
            # "mobile": shop.mobile,
            "contact": shop.contact,
            "avatar": shop.avatar
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     '/mobile/shop/update-shop-info',
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def update_address(self, province, city, area, address):
        """
        更新供应商店铺地址
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "sellerId": self.supplier.user_id,
            "province": province,
            "city": city,
            "area": area,
            "address": address
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/supplier/update-address",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_update_address_by_shop_id(
                self.shop_get()["shopId"])
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['province'] == province
                assert query_re['city'] == city
                assert query_re['area'] == area
                assert query_re['address'] == address
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def switch_status(self, switch_status):
        """
        更新店铺营业状态(10 营业中 20 休息)
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "status": switch_status,
            "check": "true"
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/shop/switch-status",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_switch_status_by_shop_id(
                self.shop_get()["shopId"])
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['status'] == switch_status
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def category_list(self, category_id):
        """
        查询分类
        :return:
        """
        bind_data = {"categoryId": category_id}
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/category/list",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_category_list_by_category_id(
                category_id)
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['count(*)'] == len(json_response['content'])
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def category_list_all(self):
        """
        查询所有分类
        :return:
        """
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/category/list",
                                     data={})
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_category_list_all_by_status(
                10)
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['count(*)'] == len(json_response['content'])
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def store_unit_list(self):
        """
        查询库存单位列表
        :return:
        """
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/store-unit/list",
                                     data={})
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_store_unit_list_by_is_delete(
                0)
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['count(*)'] == len(json_response['content'])
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"][0]["id"]

    def freight_template_all(self):
        """
        获取运费模板
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/freightTemplate/all",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_freight_template_all_by_shop_id(
                self.shop_get()["shopId"])
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['count(*)'] == len(json_response['content'])
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def freight_template_add(self, title, freigh_per_km, free_price,
                             free_distance, free_price_status,
                             free_distance_status):
        """
        新建运费模板
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "title": title,
            "freighPerKm": freigh_per_km,
            "freePrice": free_price,
            "freeDistance": free_distance,
            "freePriceStatus": free_price_status,
            "freeDistanceStatus": free_distance_status
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/freightTemplate/add",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_freight_template_add_by_freight_id(
                json_response["content"])
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                # assert query_re['shop_id'] == self.shop_get()["shopId"]
                # assert query_re['title'] == title
                # assert query_re['freigh_per_km'] == freigh_per_km
                # assert query_re['free_price'] == free_price
                # assert query_re['free_distance'] == free_distance
                # assert query_re['free_price_status'] == free_price_status
                # assert query_re['free_distance_status'] == free_distance_status
                pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def freight_template_delete(self, freight_id):
        """
        删除运费模板
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "id": freight_id
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/freightTemplate/delete",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_freight_template_delete_by_freight_id(
                freight_id)
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['shop_id'] == self.shop_get()["shopId"]
                assert query_re['id'] == freight_id
                assert query_re['is_delete'] == 1
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def freight_template_edit(self,
                              freight_id,
                              title=None,
                              freigh_per_km=None,
                              free_price=None,
                              free_distance=None,
                              free_price_status=None,
                              free_distance_status=None):
        """
        修改运费模板
        :return:
        """
        query_re = self.tool.ms_query_supplier_freight_template_edit_by_freight_id(
            freight_id)[0]
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "id": freight_id
        }
        if title is None:
            bind_data['title'] = query_re['title']
        else:
            bind_data['title'] = title
        if freigh_per_km is None:
            bind_data['freighPerKm'] = query_re['freigh_per_km']
        else:
            bind_data['freighPerKm'] = freigh_per_km
        if free_price is None:
            bind_data['freePrice'] = query_re['free_price']
        else:
            bind_data['freePrice'] = free_price
        if free_price is None:
            bind_data['freeDistance'] = query_re['free_distance']
        else:
            bind_data['freeDistance'] = free_distance
        if free_price is None:
            bind_data['freePriceStatus'] = query_re['free_price_status']
        else:
            bind_data['freePriceStatus'] = free_price_status
        if free_price is None:
            bind_data['freeDistanceStatus'] = query_re['free_distance_status']
        else:
            bind_data['freeDistanceStatus'] = free_price
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/freightTemplate/edit",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_freight_template_edit_by_freight_id(
                freight_id)
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                if bind_data['title'] != query_re['title']:
                    assert query_re['title'] == title
                if bind_data['freighPerKm'] != query_re['freigh_per_km']:
                    assert query_re['freigh_per_km'] == freigh_per_km
                if bind_data['freePrice'] != query_re['free_price']:
                    assert query_re['free_price'] == free_price
                if bind_data['freeDistance'] != query_re['free_distance']:
                    assert query_re['free_distance'] == free_distance
                if bind_data['freePriceStatus'] != query_re[
                        'free_price_status']:
                    assert query_re['free_price_status'] == free_price_status
                if bind_data['freeDistanceStatus'] != query_re[
                        'free_distance_status']:
                    assert query_re[
                        'free_distance_status'] == free_distance_status
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def freight_template_get(self, freight_id):
        """
        获取单个运费模板
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "id": freight_id
        }
        url = self.hosts['MS_SHOP'] + "/mobile/freightTemplate/get/%s" % str(
            freight_id)
        response = self.request.post(url=url, data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_freight_template_get_by_freight_id(
                freight_id)
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['title'] == json_response["content"]["title"]
                assert query_re['freigh_per_km'] == json_response["content"][
                    "freighPerKm"]
                assert query_re['free_price'] == json_response["content"][
                    "freePrice"]
                assert query_re['free_distance'] == json_response["content"][
                    "freeDistance"]
                assert query_re['free_price_status'] == json_response[
                    "content"]["freePriceStatus"]
                assert query_re['free_distance_status'] == json_response[
                    "content"]["freeDistanceStatus"]
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def upload_img(self, img_address, img_name):
        """
        上传图片
        :return:
        """
        response = self.request.post_file(
            url=self.hosts['MS_PRODUCT'] + '/common/product/upload-img',
            file_path=img_address,
            data_dict={
                "_tk_": self.supplier.token,
                "_deviceId_": self.supplier.device_id,
                "file": img_name
            },
            file_key="file")
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def status_list(self):
        """
        查询商品状态
        :return:
        """
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/product/status-list",
                                     data={})
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            assert json_response["content"][0]["id"] == 0
            assert json_response["content"][1]["id"] == 10
            assert json_response["content"][2]["id"] == 20
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def product_list(self,
                     parent_id=None,
                     category_id=None,
                     status=None,
                     sort=None,
                     search=None):
        """
        供应商商品列表
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "shopId": self.shop_get()["shopId"],
            "parentId": parent_id,
            "categoryId": category_id,
            "status": status,
            "sort": sort,
            "search": search
        }
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/product/list",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_product_list_by_shop_id(
                self.shop_get()["shopId"])
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['count(*)'] == json_response["content"]["tc"]
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]["datas"]

    def product_find(self, product_pcode):
        """
        供应商商品详情
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "pcode": product_pcode
        }
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/product/find",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def status_update(self, product_pcode, product_operation):
        """
        商品上架/下架/删除
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "pcode": product_pcode,
            "operation": product_operation
        }
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/product/status-update",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_status_update_by_product_pcode(
                product_pcode)
            if query_re is not None:
                query_re = query_re[0]
                if product_operation == 30:
                    assert query_re['is_delete'] == 1
                else:
                    assert query_re['status'] == product_operation
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def product_update(self,
                       pn,
                       parent_id=None,
                       category_id=None,
                       product_name=None,
                       store_unit_id=None,
                       product_content=None,
                       price=None,
                       store=None,
                       freight_id=None,
                       status=None,
                       img=None):
        """
        更新商品信息
        :return:
        """
        query_re = self.tool.ms_query_supplier_product_update_by_pcode(
            self.product_list()[pn]["pcode"])[0]
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "shopId": self.shop_get()["shopId"],
            "pcode": self.product_list()[pn]["pcode"],
            "parentId": parent_id,
            "categoryId": category_id,
            "name": product_name,
            "storeUnitId": store_unit_id,
            "content": product_content,
            "price": price,
            "store": store,
            "freightId": freight_id,
            "status": status,
            "serviceType": 30,
            "imgs": img
        }
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/product/update",
                                     data=bind_data)
        if parent_id is None:
            bind_data['parentId'] = query_re['parent']
        else:
            bind_data['parentId'] = parent_id
        if category_id is None:
            bind_data['categoryId'] = query_re['category_id']
        else:
            bind_data['categoryId'] = category_id
        if product_name is None:
            bind_data['name'] = query_re['name']
        else:
            bind_data['name'] = product_name
        if store_unit_id is None:
            bind_data['storeUnitId'] = query_re['store_unit_id']
        else:
            bind_data['storeUnitId'] = store_unit_id
        if product_content is None:
            bind_data['content'] = query_re['content']
        else:
            bind_data['content'] = product_content
        if price is None:
            bind_data['price'] = query_re['price']
        else:
            bind_data['price'] = price
        if store is None:
            bind_data['store'] = query_re['store']
        else:
            bind_data['store'] = store
        if freight_id is None:
            bind_data['freightId'] = query_re['freight_id']
        else:
            bind_data['freightId'] = freight_id
        if status is None:
            bind_data['status'] = query_re['STATUS']
        else:
            bind_data['status'] = status
        if img is None:
            bind_data['imgs'] = query_re['url']
        else:
            bind_data['imgs'] = img
        response = self.request.post(
            url="http://192.168.62.253:31005/mobile/product/update",
            data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            if json_response["status"] == "OK":
                query_re = self.tool.ms_query_supplier_product_update_by_pcode(
                    self.product_list()[pn]["pcode"])[0]
                if bind_data['parentId'] != query_re['parent']:
                    assert query_re['parent'] == parent_id
                if bind_data['categoryId'] != query_re['category_id']:
                    assert query_re['category_id'] == category_id
                if bind_data['name'] != query_re['name']:
                    assert query_re['name'] == product_name
                if bind_data['storeUnitId'] != query_re['store_unit_id']:
                    assert query_re['store_unit_id'] == store_unit_id
                if bind_data['content'] != query_re['content']:
                    assert query_re['content'] == product_content
                if bind_data['price'] != query_re['price']:
                    assert query_re['price'] == price
                if bind_data['store'] != query_re['store']:
                    assert query_re['store'] == store
                if bind_data['freightId'] != query_re['freight_id']:
                    assert query_re['freight_id'] == freight_id
                if bind_data['status'] != query_re['STATUS']:
                    assert query_re['STATUS'] == status
                if bind_data['imgs'] != query_re['url']:
                    assert query_re['url'] == img
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def store_list(self):
        """
        库存列表
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "shopId": self.shop_get()["shopId"],
            "pn": 1,
            "ps": 20
        }
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/product/store-list",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_store_list_by_shop_id(
                self.shop_get()["shopId"])
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['count(*)'] == json_response["content"]["tc"]
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]["datas"]

    def store_update(self, stores):
        """
        库存更新
        断言需优化
        :return:
        """

        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/product/store-update",
                                     bind_data={
                                         "_tk_": self.supplier.token,
                                         "_deviceId_": self.supplier.device_id,
                                         "shopId": self.shop_get()["shopId"],
                                         "stores": stores
                                     })
        pcode_list = []
        for i in list(stores):
            pcode_list.append(i['pcode'])
        store_list = []
        for j in list(stores):
            store_list.append(j['store'])
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            query_re = self.tool.ms_query_supplier_store_update_by_pcode(
                pcode_list)
            if query_re is not None:
                query_re = query_re[0]
            if json_response["status"] == "OK":
                assert query_re['store'] == store_list
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def supp_order_list(self):
        """
        供应商订单列表
        断言需优化
        :return:
        """
        bind_data = {"shopId": self.shop_get()["shopId"]}
        response = self.request.post(url=self.hosts['MS_ORDER'] +
                                     "/mobile/supply/order/list",
                                     data=bind_data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")

    def _mobile_supply_channel_order_list(self, orderStatus, pn, ps):
        '''
        baiying:基地查看商品列表
        :param orderStatus:
        :param pn:
        :param ps:
        :return:
        '''
        data = {
            '_tk_': self.supplier.token,
            '_deviceId_': self.supplier.device_id,
            'orderStatus': orderStatus,
            'pn': pn,
            'ps': ps
        }
        response = self.request.post(
            url='http://dev.ms.order.sjnc.com/mobile/supply/channel/order/list',
            data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def _mobile_supply_channel_order_detail(self, orderNo):
        '''
        baiying:基地查看订单详情
        :param orderNo:
        :return:
        '''
        data = {
            '_tk_': self.supplier.token,
            '_deviceId_': self.supplier.device_id,
            'orderNo': orderNo
        }
        response = self.request.post(
            url=
            'http://dev.ms.order.sjnc.com/mobile/supply/channel/order/detail',
            data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def _mobile_supply_channel_order_refuse(self, orderNo):
        '''
        baiying:基地拒绝苗叔的取消订单申请
        :param orderNo:
        :return:
        '''
        data = {
            '_tk_': self.supplier.token,
            '_deviceId_': self.supplier.device_id,
            'orderNo': orderNo
        }
        response = self.request.post(
            url=
            'http://dev.ms.order.sjnc.com/mobile/supply/channel/order/refuse',
            data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def _mobile_supply_channel_order_agree(self, orderNo):
        '''
        baiying:基地同意苗叔的取消订单申请
        :param orderNo:
        :return:
        '''
        data = {
            '_tk_': self.supplier.token,
            '_deviceId_': self.supplier.device_id,
            'orderNo': orderNo
        }
        response = self.request.post(
            url=
            'http://dev.ms.order.sjnc.com/mobile/supply/channel/order/agree',
            data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def _mobile_supply_channel_order_finish_send(self, orderNo):
        '''
        baiying:基地完成配送订单
        :param orderNo:
        :return:
        '''
        data = {
            '_tk_': self.supplier.token,
            '_deviceId_': self.supplier.device_id,
            'orderNo': orderNo
        }
        response = self.request.post(
            url=
            'http://dev.ms.order.sjnc.com/mobile/supply/channel/order/finish-send',
            data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")

    def _mobile_supply_channel_order_pending_count(self, shopId):
        data = {
            '_tk_': self.supplier.token,
            '_deviceId_': self.supplier.device_id,
            'shopId': shopId
        }
        response = self.request.post(
            url=
            'http://dev.ms.order.sjnc.com/mobile/supply/channel/order/pending-count',
            data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def get_shop_id_by_type(self, seller_id, type=30):
        """
        张鹏飞:根据user_id获取店铺信息
        :param seller_id: user_id
        :param type: 店铺类型,20是苗叔,30是基地
        :return: 返回店铺的基本信息
        """
        data = {
            '_tk_': self.supplier.token,
            '_deviceId_': self.supplier.device_id,
            'sellerId': seller_id,
            'type': type
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     '/mobile/shop/get-by-type',
                                     data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    # def update_shop_info(self, shop):
    #     """
    #     张鹏飞:更新店铺信息
    #     :return:
    #     """
    #     bind_data = {"_tk_": self.supplier.token,
    #                  "_deviceId_": self.supplier.device_id,
    #                  "sellerId": self.supplier.user_id,
    #                  "name": shop.name,
    #                  "shopId": self.supplier.channel_shop_id,
    #                  # "mobile": shop.mobile,
    #                  "contact": shop.contact,
    #                  "avatar": shop.avatar}
    #     response = self.request.post(url=self.hosts['MS_SHOP'] + '/mobile/shop/update-shop-info',
    #                                  data=bind_data)
    #     json_response = json.loads(response)
    #     update_shop_info = self.tool.ms_query_update_shop_info_by_seller_id(self.supplier.user_id)[0]
    #     if json_response["status"] == "OK":
    #         assert update_shop_info["name"] == bind_data['name']
    #         # assert update_shop_info["mobile"] == bind_data['mobile']
    #         assert update_shop_info["contact"] == bind_data['contact']
    #     elif json_response["status"] == "ERROR":
    #         raise Exception("status返回ERROR")
    #     else:
    #         raise Exception("status未返回OK或ERROR")
    #     return json_response["content"]

    def product_save(self, product):
        """
        上架新商品
        :param product: 传入商品对象,Product.py
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "parentId": product.parent_category_id,
            "categoryId": product.category_id,
            "name": product.name,
            "shopId": product.supplier_shop_id,
            "price": product.price,
            "storeUnitId": product.unit_id,
            "content": product.content,
            "store": product.store,
            "freightId": product.freight_id,
            "status": product.status,
            "serviceType": product.product_serviceType,
            "imgs": product.image
        }
        response = self.request.post(url=self.hosts['MS_PRODUCT'] +
                                     "/mobile/product/save",
                                     data=bind_data)
        product_info = self.tool.ms_query_channel_product_info_by_shop_id(
            self.get_shop_id_by_type(
                self.supplier.user_id).get('content').get('shopId'))
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def add_address(self, shop):
        """
        新增地址
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "_language_": 'zh',
            "addressId": shop.addressId,
            "shopId": shop.shopId,
            "lng": shop.lng,
            "lat": shop.lat,
            "province": shop.province,
            "city": shop.city,
            "area": shop.area,
            "address": shop.address
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/address/add",
                                     data=bind_data)
        add_address_info = self.tool.ms_query_latest_address_info_by_shop_id(
            self.get_shop_id_by_type(
                self.supplier.user_id).get('content').get('shopId'))[0]
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def switch_status(self, shop_id, status=10, check="true"):
        """
        更新店铺营业状态(10 营业中 20 休息)
        :return:
        """
        bind_data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "shopId": shop_id,
            "status": status,
            "check": check
        }
        response = self.request.post(url=self.hosts['MS_SHOP'] +
                                     "/mobile/shop/switch-status",
                                     data=bind_data)
        json_response = json.loads(response)
        update_shop_info = self.tool.ms_query_update_shop_info_by_seller_id(
            self.supplier.user_id)[0]
        if json_response["status"] == "OK":
            assert update_shop_info["status"] == status
        elif json_response["status"] == "ERROR":
            raise Exception("status返回ERROR")
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response["content"]

    def _mobile_address_add(self, receiver, contact_number, province, city,
                            address, door_number, lng, lat, is_default):
        """
        陈秀娟:添加收货地址
        :param receiver:
        :param contact_number:
        :param province:
        :param city:
        :param address:
        :param door_number:
        :param lng:
        :param lat:
        :param is_default:
        :return:
        """
        data = {
            '_tk_': self.supplier.token,
            '_deviceId_': self.supplier.device_id,
            'receiver': receiver,
            'contactNumber': contact_number,
            'province': province,
            'city': city,
            'address': address,
            'doorNumber': door_number,
            'lng': lng,
            'lat': lat,
            'isDefault': is_default
        }
        response = self.request.post(url=self.hosts['MS_USER'] +
                                     '/mobile/address/add',
                                     data=data)
        print(response)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response

    def history_address(self, shop_id):
        """
        获取历史地址列表
        :return:
        """
        data = {
            "_tk_": self.supplier.token,
            "_deviceId_": self.supplier.device_id,
            "shopId": shop_id
        }
        response = self.request.post(
            url='http://dev.ms.shop.sjnc.com/mobile/address/history',
            data=data)
        json_response = json.loads(response)
        if json_response["status"] == "OK":
            pass
        elif json_response["status"] == "ERROR":
            pass
        else:
            raise Exception("status未返回OK或ERROR")
        return json_response
Example #6
0
 def __init__(self,
              farm_name="自动化默认农场名",
              state_name="北部地区",
              farm_type="综合",
              area_range="500亩以下",
              price_range="500万以下"):
     farm_type_dict = {
         "休闲": 1,
         "畜牧": 2,
         "养殖": 2,
         "种植": 6,
         "酒庄": 3,
         "葡萄园": 3,
         "林木": 4,
         "狩猎": 4,
         "综合": 5
     }
     farm_area_dict = {
         "500亩以下": self.fake.random_int(1, 82),
         "500亩-5000亩": self.fake.random_int(83, 823),
         "5000亩-10000亩": self.fake.random_int(824, 1647),
         "10000亩-50000亩": self.fake.random_int(1648, 8236),
         "50000亩以上": self.fake.random_int(8237, 16473)
     }
     total_price_dict = {
         "500万以下": self.fake.random_int(1, 980392),
         "500万-2000万": self.fake.random_int(1020408, 3921568),
         "2000万-3500万": self.fake.random_int(4081632, 6862745),
         "3500万-5000万": self.fake.random_int(7142857, 9803921),
         "5000万以上": self.fake.random_int(10204081, 19607843)
     }
     city = Tool().query_random_city(state_name)
     self.farm_name = farm_name
     self.farm_name_en = self.fake_en.name() + " Farm"
     self.L.logger.debug("中文农场名 为 %s" % self.farm_name)
     self.L.logger.debug("英文农场名 为 %s" % self.farm_name_en)
     self.farm_type = farm_type_dict[farm_type]
     self.L.logger.debug("农场类型 为 %s %s" % (self.farm_type, farm_type))
     city_name = city[0]
     self.L.logger.debug("农场的州-市 为 %s %s" % (state_name, city_name))
     self.farm_address = city[1]["address"]
     self.L.logger.debug("中文农场地址 为 %s" % self.farm_address)
     self.farm_address_en = city[1]["address"]
     self.L.logger.debug("英文农场地址 为 %s" % self.farm_address_en)
     self.lat = city[1]["lat"]
     self.L.logger.debug("农场维度lat 为 %s" % self.lat)
     self.lng = city[1]["lng"]
     self.L.logger.debug("农场经度lng 为 %s" % self.lng)
     self.nation_id = 25
     self.L.logger.debug("农场的nationId 为 %d" % self.nation_id)
     self.province_id = city[1]["state"]
     self.L.logger.debug("农场的provinceId 为 %d" % self.province_id)
     self.city_id = city[1]["city"]
     self.L.logger.debug("农场的cityId 为 %d" % self.city_id)
     self.area = farm_area_dict[area_range]
     self.L.logger.debug("农场的面积 为 %s 英亩" % str(self.area))
     self.total_price = total_price_dict[price_range]
     self.L.logger.debug("农场的总价 为 %s 澳元" % str(self.total_price))
     self.unitCode = "AUD"
     self.L.logger.debug("农场的货币单位 为 %s" % self.unitCode)
     self.unit_price = self.total_price / self.area
     self.L.logger.debug("农场的单价 为 %s 澳元" % str(self.unit_price))
     self.water_rights = "中文水权描述:" + self.fake.text().replace('\n', ' ')
     self.L.logger.debug(self.water_rights)
     self.water_rights_en = "英文水权描述:" + self.fake_en.text().replace(
         '\n', ' ')
     self.L.logger.debug(self.water_rights_en)
     self.regulations = "中文土地使用规定:" + self.fake.text().replace('\n', ' ')
     self.L.logger.debug(self.regulations)
     self.regulations_en = "英文土地使用规定:" + self.fake_en.text().replace(
         '\n', ' ')
     self.L.logger.debug(self.regulations_en)
     self.rainfall = self.fake.random_int(20, 1000)
     self.L.logger.debug("降雨量 %s毫升/年" % self.rainfall)
     self.disadvantage = "中文杂草和虫害:" + self.fake.text().replace('\n', ' ')
     self.L.logger.debug(self.disadvantage)
     self.disadvantage_en = "英文杂草和虫害:" + self.fake_en.text().replace(
         '\n', ' ')
     self.L.logger.debug(self.disadvantage_en)
     self.area_code = 'mu'
     self.L.logger.debug("中文面积单位: %s" % self.area_code)
     self.area_code_en = 'acre'
     self.L.logger.debug("英文面积单位: %s" % self.area_code_en)
     self.soil_ph = 3  #float(self.fake.random_int(-10, 150)/10)
     self.L.logger.debug("土壤PH值: %s" % self.soil_ph)
     self.soil_type = self.fake.random_int(1, 3)
     redis = Redis()
     self.images = '[{"type":"1", ' \
                   '"url":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                   '{"type":"2", ' \
                   '"url":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                   '{"type":"3", ' \
                   '"url":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                   '{"type":"4", ' \
                   '"url":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"}]'
     self.L.logger.debug("农场Banner 为 %s " % str(self.images))
     self.content = '[{"type":"1", ' \
                    '"value":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},'\
                    '{"type":"2", ' \
                    '"value":"' + self.fake.text().replace("\n", " ") + '"},' \
                    '{"type":"1", ' \
                    '"value":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                    '{"type":"2", ' \
                    '"value":"' + self.fake.text().replace("\n", " ") + '"}]'
     self.L.logger.debug("中文农场介绍 为 %s " % str(self.content))
     self.content_en = '[{"type":"1", ' \
                       '"value":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},'\
                       '{"type":"2", ' \
                       '"value":"' + self.fake_en.text().replace("\n", " ") + '"},' \
                       '{"type":"1", ' \
                       '"value":"' + redis.get("image%s" % str(self.fake.random_int(1, 75))) + '"},' \
                       '{"type":"2", ' \
                       '"value":"' + self.fake_en.text().replace("\n", " ") + '"}]'
     self.L.logger.debug("英文农场介绍 为 %s " % str(self.content_en))