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})
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})
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})
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)
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)
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()
def put(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) data.add_argument("address_id", type=int) 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"] address_id = data.parse_args()["address_id"] if not (province_id and city_id and area_id and detailed and contact_phone and receiver and address_id): return general_response(err_code=101, status_code=400) a = user.address.filter_by(id=address_id).first() if not a: return general_response(err_code=404, status_code=404) 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) if not (detailed and contact_phone and receiver): return general_response(err_code=101, status_code=400) a.contact_phone = contact_phone a.receiver = receiver a.province = province_id a.city = city_id a.area = area_id a.detailed = detailed 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() if result["status"] == 0: a.lat = result["result"]["location"]["lat"] a.lng = result["result"]["location"]["lng"] else: return general_response(info={"message": result["message"]}, status_code=400) if update_in_db(a): return general_response() return general_response(err_code=601, status_code=400)
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)
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()
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)
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})
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)
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)
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)
def put(self, user): if not user.shop.license: return general_response(err_code=708, status_code=404) data = reqparse.RequestParser() data.add_argument("idcard_name", type=str) data.add_argument("idcard_num", type=str) data.add_argument("business_address", type=str) data.add_argument("business_name", type=str) data.add_argument("business_begin_time", type=str) data.add_argument("business_end_time", type=str) data.add_argument("business_num", type=str) data.add_argument("service_image_name", type=str) data.add_argument("service_address", type=str) data.add_argument("service_name", type=str) data.add_argument("service_begin_time", type=str) data.add_argument("service_end_time", type=str) data.add_argument("service_num", type=str) business_begin_time = data.parse_args()["business_begin_time"] business_end_time = data.parse_args()["business_end_time"] service_begin_time = data.parse_args()["service_begin_time"] service_end_time = data.parse_args()["service_end_time"] idcard_name = data.parse_args()["idcard_name"] idcard_num = data.parse_args()["idcard_num"] business_address = data.parse_args()["business_address"] business_name = data.parse_args()["business_name"] business_num = data.parse_args()["business_num"] service_address = data.parse_args()["service_address"] service_name = data.parse_args()["service_name"] service_num = data.parse_args()["service_num"] # 格式化时间 if business_begin_time and business_end_time and service_begin_time and service_end_time: try: business_begin_time = datetime.strptime( business_begin_time, "%Y-%m-%d") business_end_time = datetime.strptime(business_end_time, "%Y-%m-%d") service_begin_time = datetime.strptime(service_begin_time, "%Y-%m-%d") service_end_time = datetime.strptime(service_end_time, "%Y-%m-%d") except ValueError as e: print(e.__repr__()) return general_response(err_code=705, status_code=400) else: return general_response(err_code=101) license = user.shop.license license.idcard_name = idcard_name license.idcard_num = idcard_num license.business_address = business_address license.business_name = business_name license.business_num = business_num license.service_address = service_address license.service_name = service_name license.service_num = service_num license.business_begin_time = business_begin_time license.business_end_time = business_end_time license.service_begin_time = service_begin_time license.service_end_time = service_end_time if update_in_db(license): return general_response() else: return general_response(err_code=101)