Exemplo n.º 1
0
    def post(self, user):
        path = "app/static/shop_image/"
        file = request.files.get("file")
        shop = user.shop
        if not shop:
            return general_response(err_code=303, status_code=404)
        if not file:
            return general_response(err_code=101, status_code=400)
        if file.filename.split(".")[-1] not in ["jpg", "jpeg", "png"]:
            return general_response(err_code=108, status_code=400)
        file.seek(0, 2)
        if file.tell() > 1048576:
            return general_response(err_code=107, status_code=403)
        file.seek(0)
        if shop.shop_img_name:
            if not shop.shop_img_name == "default.jpg":
                try:
                    os.remove(path + user.head_image_name)
                except FileNotFoundError as e:
                    print(e.__repr__())

        filename = str(shop.id) + file.filename
        file.save(path + filename)
        shop.shop_img_name = filename
        update_in_db(shop)
        return general_response({"success": shop.shop_img_name})
Exemplo n.º 2
0
    def post(self, user):
        data = reqparse.RequestParser()
        data.add_argument("item_id", type=int)
        item_id = data.parse_args()["item_id"]
        path = "app/static/shop_item_image/"
        file = request.files.get("file")
        item = user.shop.items.filter_by(id=item_id).first()
        if not item:
            return general_response(err_code=406, status_code=404)
        if not file:
            return general_response(err_code=101, status_code=400)
        if file.filename.split(".")[-1] not in ["jpg", "jpeg", "png"]:
            return general_response(err_code=108, status_code=400)
        file.seek(0, 2)
        if file.tell() > 1048576:
            return general_response(err_code=107, status_code=403)
        file.seek(0)
        if item.item_image_name:
            try:
                os.remove(path + user.head_image_name)
            except FileNotFoundError as e:
                print(e.__repr__())

        filename = str(item.id) + file.filename
        file.save(path + filename)
        item.item_image_name = filename
        update_in_db(item)
        return general_response({"success": item.item_image_name})
Exemplo n.º 3
0
    def post(self, user):
        license = user.shop.license
        if not license:
            return general_response(err_code=708)
        path = "app/static/shop_license_service/"
        file = request.files.get("file")
        if not file:
            return general_response(err_code=101, status_code=400)
        if file.filename.split(".")[-1] not in ["jpg", "jpeg", "png"]:
            return general_response(err_code=108, status_code=400)
        file.seek(0, 2)
        if file.tell() > 1048576 * 3:
            return general_response(err_code=107, status_code=403)
        file.seek(0)
        if license.service_image_name:
            try:
                os.remove(path + license.service_image_name)
            except FileNotFoundError as e:
                print(e.__repr__())

        filename = str(user.id) + file.filename
        file.save(path + filename)
        license.service_image_name = filename
        update_in_db(license)
        return general_response(
            {"license_service_image_name": license.service_image_name})
Exemplo n.º 4
0
    def get(self):
        data = reqparse.RequestParser()
        data.add_argument("shop_id", type=int)
        id = data.parse_args()["shop_id"]
        shop = shop_info.query.filter_by(id=id).first()
        if not shop:
            return general_response(err_code=407, status_code=404)
        category_list = shop.item_category.all()
        shop_items_list = shop.items.all()
        a_list = []
        for a in category_list:
            one_dict = {
                "category_id": a.id,
                "category_name": a.category_name,
            }
            a_list.append(one_dict)

        b_list = []
        for b in shop_items_list:
            b_list.append(b.get_item_detail())

        info = {
            "category_list": a_list,
            "shop_items_list": b_list,
            "shop_info": shop.get_shop_info()
        }

        return general_response(info=info)
Exemplo n.º 5
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)
Exemplo n.º 6
0
 def get(self, parent_id):
     region_list = Region.query.filter_by(parent_id=parent_id).all()
     if not region_list:
         return general_response(err_code=410, status_code=404)
     region_dict = {}
     for a in region_list:
         region_dict[a.region_name] = a.region_id
     return general_response(info=region_dict)
Exemplo n.º 7
0
    def put(self, user):
        shop = user.shop

        if not 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)
        shop.shop_name = shop_name
        shop.contact = contact
        shop.shop_introduction = shop_introduction
        shop.province = province_id
        shop.city = city_id
        shop.area = area_id
        shop.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()
        shop.lat = result["result"]["location"]["lat"]
        shop.lng = result["result"]["location"]["lng"]

        if update_in_db(info):
            return general_response()

        return general_response(err_code=601, status_code=400)
Exemplo n.º 8
0
 def put(self, user):
     data = reqparse.RequestParser()
     data.add_argument("nickname", type=str)
     nickname = data.parse_args()["nickname"]
     if not nickname:
         return general_response(err_code=101, status_code=400)
     user.nickname = nickname
     if not update_in_db(user):
         return general_response(err_code=601, status_code=400)
     return general_response()
Exemplo n.º 9
0
    def delete(self, user):
        data = reqparse.RequestParser()
        data.add_argument('address_id', type=int)
        address_id = data.parse_args()['address_id']
        a = user.address.filter_by(id=address_id).first()
        if not a:
            return general_response(err_code=404, status_code=404)

        delete_in_db(a)

        return general_response()
Exemplo n.º 10
0
 def get(self, image_name):
     try:
         f = open("app/static/user_shop_head/" + image_name, "rb")
         file = f.read()
         resp = Response(file, mimetype="image/jpeg")
         return resp
     except FileNotFoundError as e:
         print(e.__repr__())
         return general_response(err_code=409, status_code=404)
     except TypeError as e:
         print(e.__repr__())
         return general_response(err_code=702, status_code=400)
Exemplo n.º 11
0
 def put(self, user):
     data = reqparse.RequestParser()
     data.add_argument("order_id", type=int)
     order_id = data.parse_args()["order_id"]
     order = user.shop.order.filter_by(
         status=order_status.waiting_for_receive).filter_by(
             id=order_id).first()
     if order:
         order.status = order_status.waiting_for_delivery
         update_in_db(order)
         return general_response()
     else:
         return general_response(err_code=408, status_code=404)
Exemplo n.º 12
0
    def get(self):
        data = reqparse.RequestParser()
        data.add_argument('openid', type=str)
        openid = data.parse_args()["openid"]

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

        user = get_user_personal(openid)
        if user:
            token = user.generate_auth_token()
            return general_response(token=token)
        else:
            return general_response(err_code=202, status_code=404)
Exemplo n.º 13
0
    def delete(self, user):
        data = reqparse.RequestParser()
        data.add_argument("specification_id", type=int)
        specification_id = data.parse_args()["specification_id"]

        a = item_specification.query.filter_by(id=specification_id).first()

        if a:
            if a.item in user.shop.items.all():
                if delete_in_db(a):
                    return general_response()
                else:
                    return general_response(err_code=603, status_code=400)
        else:
            return general_response(err_code=405, status_code=404)
Exemplo n.º 14
0
 def get(self, user):
     a = user.address.order_by(address.weights.desc()).first()
     if a:
         info = {
             "address_str": a.get_address_str(),
             "address_dict": a.get_address_dict(),
             "lat": a.lat,
             "lng": a.lng,
             "contact_phone": a.contact_phone,
             "receiver": a.receiver,
             "address_id": a.id
         }
         return general_response(info=info)
     else:
         return general_response(err_code=403, status_code=404)
Exemplo n.º 15
0
    def put(self, user):
        data = reqparse.RequestParser()
        data.add_argument("order_id", type=int)
        order_id = data.parse_args()["order_id"]

        order = user.shop.order.filter_by(
            status=order_status.personal_cancel).filter_by(
                id=order_id).first()

        if order:
            # 处理商家接受退款的
            order.status = order_status.shut_down_return_to_personal
            update_in_db(order)
            return general_response()
        else:
            return general_response(err_code=408, status_code=404)
Exemplo n.º 16
0
 def post(self):
     data = reqparse.RequestParser()
     data.add_argument("file", type=str)
     file = request.files.get("file")
     if file:
         file.seek(0)
         return general_response()
Exemplo n.º 17
0
 def get(self, user):
     address_list = user.address.order_by(address.weights.desc()).all()
     info = []
     if address_list:
         for a in address_list:
             info.append({
                 "address_str": a.get_address_str(),
                 "address_dict": a.get_address_dict(),
                 "lat": a.lat,
                 "lng": a.lng,
                 "contact_phone": a.contact_phone,
                 "receiver": a.receiver,
                 "address_id": a.id
             })
         return general_response(info=info)
     else:
         return general_response(err_code=403, status_code=404)
Exemplo n.º 18
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)
Exemplo n.º 19
0
    def put(self, user):
        data = reqparse.RequestParser()
        data.add_argument('address_id', type=int)
        address_id = data.parse_args()['address_id']

        a = user.address.filter_by(id=address_id).first()
        b = user.address.order_by(address.weights.desc()).first()

        if not a:
            return general_response(err_code=404, status_code=404)
        a.weights = 100
        b.weights = 1

        update_in_db(a)
        update_in_db(b)

        return general_response()
Exemplo n.º 20
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()
Exemplo n.º 21
0
    def get(self):
        # 获取小程序传来的json,从中获取code
        data = reqparse.RequestParser()
        data.add_argument('code', type=str)

        code = data.parse_args()["code"]

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

        # 个人用户,如果已经验证过手机,就返回一个token
        # 否则返回错误代码,小程序跳转但验证手机页面
        user = get_user_personal(openid)
        if user:
            token = user.generate_auth_token()
            return general_response(token=token)
        else:
            return general_response(err_code=202, status_code=404)
Exemplo n.º 22
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)
Exemplo n.º 23
0
    def put(self, user):
        data = reqparse.RequestParser()
        data.add_argument("specification_name", type=str)
        data.add_argument("additional_costs", type=float)
        data.add_argument("specification_id", type=int)
        specification_name = data.parse_args()["specification_name"]
        additional_costs = data.parse_args()["additional_costs"]
        specification_id = data.parse_args()["specification_id"]

        a = item_specification.query.filter_by(id=specification_id).first()

        if a:
            if a.item in user.shop.items.all():
                a.specification_name = specification_name
                a.additional_costs = additional_costs
                if update_in_db(a):
                    return general_response()
                return general_response(err_code=601, status_code=400)
        return general_response(err_code=405, status_code=404)
Exemplo n.º 24
0
 def get(self, user):
     data = reqparse.RequestParser()
     data.add_argument("page", type=int)
     page = data.parse_args()["page"]
     pagination = user.shop.order.order_by(orders.id.desc()).paginate(
         page, per_page=15, error_out=False)
     a = pagination.items
     info = []
     for i in a:
         info.append(i.get_order_dict_shop())
     return general_response(info={"message": info})
Exemplo n.º 25
0
    def get(self):
        data = reqparse.RequestParser()
        data.add_argument("item_id", type=str)
        item_id = data.parse_args()["item_id"]

        item = shop_items.query.filter_by(id=item_id).first()
        specification_list = item.specification.all()
        info = []
        for i in specification_list:
            info.append(i.get_specification_dict())

        return general_response(info={"specification_list": info})
Exemplo n.º 26
0
    def post(self, user):
        path = "app/static/user_personal_head/"
        file = request.files.get("file")
        if not file:
            return general_response(err_code=101, status_code=400)
        if file.filename.split(".")[-1] not in ["jpg", "jpeg", "png"]:
            return general_response(err_code=108, status_code=400)
        file.seek(0, 2)
        if file.tell() > 1048576:
            return general_response(err_code=107, status_code=403)
        file.seek(0)
        if user.head_image_name:
            try:
                os.remove(path + user.head_image_name)
            except FileNotFoundError as e:
                print(e.__repr__())

        filename = str(user.id) + file.filename
        file.save(path + filename)
        user.head_image_name = filename
        update_in_db(user)
        return general_response({"success": user.head_image_name})
Exemplo n.º 27
0
    def put(self, user):
        data = reqparse.RequestParser()
        data.add_argument("floor_send_cost", type=float)
        data.add_argument("send_cost", type=float)
        data.add_argument("notic", type=str)
        data.add_argument("box_price", type=float)

        floor_send_cost = data.parse_args()["floor_send_cost"]
        send_cost = data.parse_args()["send_cost"]
        notic = data.parse_args()["notic"]
        box_price = data.parse_args()["box_price"]
        shop = user.shop
        if not shop:
            return general_response(err_code=303, status_code=404)

        shop.floor_send_cost = floor_send_cost
        shop.send_cost = send_cost
        shop.notic = notic
        shop.box_price = box_price
        if update_in_db(shop):
            return general_response()
        return general_response(err_code=601, status_code=406)
Exemplo n.º 28
0
    def post(self, user):
        data = reqparse.RequestParser()
        data.add_argument("order_id", type=int)
        data.add_argument("shop_reason", type=str)
        order_id = data.parse_args()["order_id"]
        shop_reason = data.parse_args()["shop_reason"]

        order = user.shop.order.filter_by(
            status=order_status.personal_cancel).filter_by(
                id=order_id).first()

        if order:
            if shop_reason:
                charge = order.charge_back_info
                charge.shop_reason = shop_reason
                order.status = order_status.shop_refuse
                update_in_db(order)
                update_in_db(charge)
            else:
                return general_response(err_code=101, status_code=400)
            return general_response()
        else:
            return general_response(err_code=408, status_code=404)
Exemplo n.º 29
0
    def get(self, user):
        data = reqparse.RequestParser()
        data.add_argument("page", type=int)
        page = data.parse_args()["page"]
        order_list = user.shop.order.filter_by(status=order_status.waiting_for_receive).order_by(orders.id).\
            paginate(page, per_page=15, error_out=False)
        a = []
        for i in order_list.items:
            a.append(i.get_order_dict_shop())

        info = {
            "order_list": a,
            "has_next": order_list.has_next,
            "page_here": order_list.page,
            "per_page": order_list.per_page,
            "total_pages": order_list.pages,
            "total": order_list.total
        }
        return general_response(info=info)
Exemplo n.º 30
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()