Esempio n. 1
0
 def get(self):
     data = reqparse.RequestParser()
     data.add_argument("time", type=str)
     time = data.parse_args()["time"]
     a = datetime.strptime(time, "%Y-%m-%d")
     print(a)
     b = shop_license(business_begin_time=a, shop_id=1)
     add_in_db(b)
     return general_response()
Esempio n. 2
0
    def post(self):
        data = reqparse.RequestParser()
        data.add_argument("openid", type=str)
        data.add_argument("phone", type=str)
        data.add_argument("password", type=str)
        data.add_argument("nickname", type=str)
        openid = data.parse_args()["openid"]
        phone = data.parse_args()["phone"]
        password = data.parse_args()["password"]
        nickname = data.parse_args()["nickname"]

        if not openid:
            return general_response(err_code=201, status_code=400)
        elif get_user_shop(openid=openid):
            return general_response(err_code=102, status_code=403)
        elif get_user_shop(phone=phone):
            return general_response(err_code=103, status_code=403)
        else:
            user = user_shop(openid=openid,
                             phone=phone,
                             password=password,
                             nickname=nickname)
            if add_in_db(user):
                token = user.generate_auth_token()
                return general_response(token=token)
            else:
                return general_response(err_code=602, status_code=406)
Esempio n. 3
0
 def post(self, user):
     data = reqparse.RequestParser()
     data.add_argument("item_list", type=str)
     item_list = json.loads(data.parse_args()["item_list"])
     for item in item_list:
         category = item_category.query.filter(item_category.shop_id == user.shop.id).\
             filter_by(category_name=item["category"]).first()
         # 要判断有没有这个类别,没有就要新建一个
         if not category:
             category = item_category(category_name=item['category'],
                                      shop_id=user.shop.id)
             add_in_db(category)
         new_item = shop_items(
             item_name=item["item_info"]["item_name"],
             item_price=float(item["item_info"]["item_price"]),
             item_introduction=item["item_info"]["item_introduction"],
             shop_id=user.shop.id,
             item_category_id=category.id)
         add_in_db(new_item)
     return general_response()
Esempio n. 4
0
    def post(self, user):
        # 如果无法获取到该用户的shop再给申请
        if user.shop:
            return general_response(err_code=501, status_code=400)

        data = reqparse.RequestParser()
        data.add_argument("shop_name", type=str)
        data.add_argument("shop_introduction", type=str)

        # 改过的这些字段
        data.add_argument('province_id', type=int)
        data.add_argument('city_id', type=int)
        data.add_argument('area_id', type=int)
        data.add_argument("detailed", type=str)
        data.add_argument("contact", type=str)

        province_id = data.parse_args()["province_id"]
        city_id = data.parse_args()["city_id"]
        area_id = data.parse_args()["area_id"]
        detailed = data.parse_args()["detailed"]
        shop_name = data.parse_args()["shop_name"]
        shop_introduction = data.parse_args()["shop_introduction"]
        contact = data.parse_args()["contact"]
        contact = json.loads(contact)

        if not (shop_name and shop_introduction and detailed and province_id
                and city_id and area_id and contact):
            return general_response(err_code=101, status_code=400)

        info = shop_info(shop_name=shop_name,
                         contact=contact,
                         owner_id=user.id,
                         shop_introduction=shop_introduction,
                         province=province_id,
                         city=city_id,
                         area=area_id,
                         detailed=detailed)

        url = "https://apis.map.qq.com/ws/geocoder/v1/"
        d = {"address": info.get_address_str(), "key": glovar.map_key}
        result = requests.get(url=url, params=d).json()
        info.lat = result["result"]["location"]["lat"]
        info.lng = result["result"]["location"]["lng"]

        if add_in_db(info):
            return general_response()
        return general_response(err_code=602, status_code=400)
Esempio n. 5
0
    def post(self, user):
        data = reqparse.RequestParser()
        data.add_argument('province_id', type=int)
        data.add_argument('city_id', type=int)
        data.add_argument('area_id', type=int)
        data.add_argument("detailed", type=str)
        data.add_argument("contact_phone", type=str)
        data.add_argument("receiver", type=str)

        province_id = data.parse_args()["province_id"]
        city_id = data.parse_args()["city_id"]
        area_id = data.parse_args()["area_id"]
        detailed = data.parse_args()["detailed"]
        contact_phone = data.parse_args()["contact_phone"]
        receiver = data.parse_args()["receiver"]

        if not (province_id and city_id and area_id and detailed
                and contact_phone and receiver):
            return general_response(err_code=101, status_code=400)

        a = address(province=province_id,
                    city=city_id,
                    area=area_id,
                    detailed=detailed,
                    user_id=user.id,
                    receiver=receiver,
                    contact_phone=contact_phone)

        if not (Region.query.filter_by(parent_id=1).filter_by(
                region_id=province_id).first()
                and Region.query.filter_by(parent_id=province_id).filter_by(
                    region_id=city_id).first()
                and Region.query.filter_by(parent_id=city_id).filter_by(
                    region_id=area_id).first()):
            return general_response(err_code=402, status_code=400)

        url = "https://apis.map.qq.com/ws/geocoder/v1/"
        d = {"address": a.get_address_str(), "key": glovar.map_key}

        result = requests.get(url=url, params=d).json()
        a.lat = result["result"]["location"]["lat"]
        a.lng = result["result"]["location"]["lng"]

        if add_in_db(a):
            return general_response()
        return general_response(err_code=101, status_code=400)
Esempio n. 6
0
    def post(self, user):
        data = reqparse.RequestParser()
        data.add_argument("specification_name", type=str)
        data.add_argument("additional_costs", type=float)
        data.add_argument("item_id", type=int)
        specification_name = data.parse_args()["specification_name"]
        additional_costs = data.parse_args()["additional_costs"]
        item_id = data.parse_args()["item_id"]

        if not user.shop.items.filter_by(id=item_id).all():
            return general_response(err_code=406, status_code=404)

        a = item_specification(specification_name=specification_name,
                               additional_costs=additional_costs,
                               item_id=item_id)

        if add_in_db(a):
            return general_response()
        return general_response(err_code=602, status_code=400)
Esempio n. 7
0
    def post(self):
        data = reqparse.RequestParser()
        data.add_argument("code", type=str)
        data.add_argument("phone", type=str)
        data.add_argument("password", type=str)
        data.add_argument("nickname", type=str)
        data.add_argument("img_url", type=str)
        code = data.parse_args()["code"]
        phone = data.parse_args()["phone"]
        password = data.parse_args()["password"]
        nickname = data.parse_args()["nickname"]

        img_url = data.parse_args()["img_url"]
        if img_url:
            img = requests.get(img_url).content

        openid = get_openid(code)
        if not openid:
            return general_response(err_code=201, status_code=400)

        if not (code and phone and password and nickname and img):
            return general_response(err_code=101, status_code=400)
        elif get_user_shop(openid=openid):
            return general_response(err_code=102, status_code=403)
        elif get_user_shop(phone=phone):
            return general_response(err_code=103, status_code=403)
        else:
            user = user_shop(openid=openid,
                             phone=phone,
                             password=password,
                             nickname=nickname)
            if add_in_db(user):
                storage = FileStorage(stream=BytesIO(img),
                                      content_type="image/jpeg")
                filename = str(user.id) + user.nickname + ".jpg"
                storage.save("app/static/user_shop_head/" + filename)
                user.head_image_name = filename
                update_in_db(user)
                token = user.generate_auth_token()
                return general_response(token=token)
            else:
                return general_response(err_code=602, status_code=406)