def menutype_foods_add(): result = {"code": 10000, "value": "", "msg": "添加成功"} data = request.data data_dict = json.loads(data) print(data_dict) data_dict['sha_id'] = util.MD5(data_dict['menu_sha_id'] + data_dict['foods_sha_id']) cols = data_dict.keys() vals = data_dict.values() sql = "INSERT INTO %s (%s) VALUES(%s)" % (__table__, ",".join(cols), ",".join(["%s"] * len(vals))) print(sql) print(vals) try: dbManager.add(sql, tuple(vals)) except Exception as ex: code, err_message = ex.args result['code'] = -10000 result['msg'] = err_message return result
def menutype_add(): result = {"code": 10000, "value": "", "msg": "添加成功"} data = request.data data_dict = json.loads(data.decode('utf-8')) if data_dict == {} or len(data_dict['title'].strip()) == 0: result['code'] = -10000 result['msg'] = "菜单名称不能为空" return result data_dict['sha_id'] = util.MD5(data_dict['title']) cols = data_dict.keys() vals = data_dict.values() sql = "INSERT INTO menu_type (%s) VALUES(%s)" % (",".join(cols), ",".join( ["%s"] * len(vals))) try: dbManager.add(sql, tuple(vals)) except Exception as ex: code, err_message = ex.args result['code'] = -10000 result['msg'] = err_message return result
def _fetch(self): # 保存房产图片到本地目录 url_path, img_name = os.path.split(self.name) room_img_name = "{image_name}.{type}".format( image_name=util.MD5(self.name), type=img_name.split('.')[1]) # 保存图像到本地 image_save_path = '{}/{}/{}'.format(current_app.config['ROOM_IMG_DIR'], self.post_time.split(' ')[0], room_img_name) # 创建保存路径 util.mkdir('{}/{}'.format(current_app.config['ROOM_IMG_DIR'], self.post_time.split(' ')[0])) self.url = self.name ret = requests.get(self.name) if ret.status_code == 200: with open(image_save_path, 'wb') as file: file.write(ret.content) self.name = room_img_name self.path = "{}/{}".format( self.post_time.split(' ')[0], room_img_name) return True self.name = '' return False
def foods_add(): result = {"code": 10000, "value": "", "msg": "添加成功"} data = request.data data_dict = json.loads(data.decode('utf-8')) print(data_dict) print(data_dict.keys) if data_dict == {} or "title" not in data_dict or len(data_dict['title'].strip()) == 0: result['code'] = -10000 result['msg'] = "名称不能为空" return result if "price" not in data_dict: result['code'] = -10000 result['msg'] = "价格不能为空" return result if "total_num" not in data_dict: result['code'] = -10000 result['msg'] = "数量不能为空" return result if "unit" not in data_dict: result['code'] = -10000 result['msg'] = "单位不能为空" return result data_dict['sha_id'] = util.MD5(data_dict['title']) cols = data_dict.keys() vals = data_dict.values() sql = "INSERT INTO foods (%s) VALUES(%s)" % ( ",".join(cols), ",".join(["%s"] * len(vals)) ) try: dbManager.add(sql, tuple(vals)) except Exception as ex: code, err_message = ex.args result['code'] = -10000 result['msg'] = err_message return result
def save_avatar(self, url): # 保存用户头像 url_path, img_name = os.path.split(url) avatar_name = "{image_name}.{type}".format(image_name=util.MD5(url), type=img_name.split('.')[1]) # 保存头像到本地 image_save_path = '{}/{}'.format(current_app.config['AVATAR_DIR'], avatar_name) ret = requests.get(url) if ret.status_code == 200: with open(image_save_path, 'wb') as file: file.write(ret.content) return avatar_name return ''
def menutype_modify(sha_id): result = {"code": 10000, "value": "", "msg": "修改成功"} data = request.data data_dict = json.loads(data) print(data_dict) data_dict['sha_id'] = util.MD5(data_dict['title']) condition = {'sha_id': sha_id} try: dbManager.update('menu_type', data_dict, condition) except Exception as ex: code, err_message = ex.args result['code'] = -10000 result['msg'] = err_message return result
def tables_modify(sha_id): result = {"code": 10000, "value": "", "msg": "修改成功"} data = request.data data_dict = json.loads(data) data_dict['sha_id'] = util.MD5(data_dict['title'] + str(data_dict['number'])) condition = {'sha_id': sha_id} try: dbManager.update(__table__, data_dict, condition) except Exception as ex: code, err_message = ex.args result['code'] = -10000 result['msg'] = err_message return result
def foods_modify(sha_id): result = {"code": 10000, "value": "", "msg": "修改成功"} data = request.data data_dict = json.loads(data) if data_dict == {} or "title" not in data_dict or len(data_dict['title'].strip()) == 0: result['code'] = -10000 result['msg'] = "名称不能为空" return result if "price" not in data_dict: result['code'] = -10000 result['msg'] = "价格不能为空" return result if "total_num" not in data_dict: result['code'] = -10000 result['msg'] = "数量不能为空" return result if "unit" not in data_dict: result['code'] = -10000 result['msg'] = "单位不能为空" return result data_dict['sha_id'] = util.MD5(data_dict['title']) condition = {'sha_id': sha_id} try: dbManager.update('foods', data_dict, condition) except Exception as ex: code, err_message = ex.args result['code'] = -10000 result['msg'] = err_message return result
def tables_add(): result = {"code": 10000, "value": "", "msg": "添加成功"} data = request.data data_dict = json.loads(data.decode('utf-8')) data_dict['sha_id'] = util.MD5(data_dict['title'] + str(data_dict['number'])) cols = data_dict.keys() vals = data_dict.values() sql = "INSERT INTO %s (%s) VALUES(%s)" % (__table__, ",".join(cols), ",".join(["%s"] * len(vals))) try: dbManager.add(sql, tuple(vals)) except Exception as ex: code, err_message = ex.args result['code'] = -10000 result['msg'] = err_message return result
def order_add(): result = {"code": 10000, "value": "", "msg": "添加成功"} data = request.data data_dict = json.loads(data.decode('utf-8')) print(data_dict) print(data_dict['foods']) user = User() user_obj = user.get_user(data_dict['user_sha_id']) print(user_obj.phoneNumber) table = Table() table_obj = table.get(data_dict['table_sha_id']) if table_obj == None: result['code'] = -10000 result['msg'] = '桌号错误,找不到对应餐桌!' return result print(table_obj.title) sql_list = [] for food in data_dict['foods']: print(food['sha_id']) print(food['num']) dic_food = Food.get_food(food['sha_id'])[0] # order_item = {} # # order_item['item_sha_id'] = '' # order_item['title'] = '' print(dic_food) orderItem = OrderItem() if food['num'] > dic_food['total_num']: result['code'] = -10000 result['msg'] = '{title}数量超过库存{num}{unit},请修改订单'.format(title=dic_food['title'], num=dic_food['total_num'], unit=dic_food['unit']) return result # dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") # print(dt) orderItem.num = food['num'] orderItem.price = dic_food['price'] orderItem.title = dic_food['title'] orderItem.food_sha_id = food['sha_id'] orderItem.item_sha_id = util.MD5( orderItem.post_time + str(orderItem.num) + str(orderItem.price) + orderItem.title + orderItem.food_sha_id) orderItem.descript() sql = 'update foods set total_num =total_num-{num} where sha_id={sha_id}'.format(num=orderItem.num, sha_id=orderItem.food_sha_id) sql_list.append(sql) sql_items = '''insert into order_items(item_sha_id,food_sha_id,title,price,post_time,num) values ('{item_sha_id}','{food_sha_id}','{title}',{price},'{post_time}',{num})'''.format( item_sha_id=orderItem.item_sha_id, food_sha_id=orderItem.food_sha_id, title=orderItem.title, price=orderItem.price, post_time=orderItem.post_time, num=orderItem.num) print(sql_items) sql_list.append(sql_items) sql_oder_items = '''insert into foods_order_items(order_sha_id,item_sha_id) values ('{order_sha_id}','{item_sha_id}')'''.format( order_sha_id='', item_sha_id='') return result