def manager_login(req): """ 管理者账号登录 :param req: :return: """ resp = '' username = req.POST.get('username') password = req.POST.get('password') sql = "SELECT * from manager where username ='******' and password='******'" % ( username, password) db = Mysql() result = db.getOne(sql) if result: access_token = jwt.create_token(username) in_result = db.insertOne( "INSERT INTO `vms`.`t_token`(`user_id`,`token`, `time`) VALUES ('%s','%s', now());" % (result['id'], access_token)) if in_result: # print(access_token) resp = { "code": 0, "msg": "登入成功", "data": { "access_token": access_token } } return HttpResponse(json.dumps(resp), content_type="application/json") resp = {"code": 1, "msg": "登入失败", "data": {}} db.dispose() return HttpResponse(json.dumps(resp), content_type="application/json")
def add_server(req): """ 添加分类 :param req: :return: """ logger.debug('添加分类传入参数:' + str(req.POST)) data = req.POST.copy() db = Mysql() is_exist = db.getAll( "SELECT * from good_category where `name` ='%s' or `sort` ='%s'" % (data['name'], data['sort'])) if is_exist: # 已存在该分类 resp = {"code": 2, "msg": "server_is_exist"} logger.debug('添加失败,分类或排序已存在,请修改后添加!') else: sql = "INSERT INTO `good_category`(`name`,`sort`) VALUES ('%s','%s');" % ( data['name'], data['sort']) logger.debug(sql) dd = db.insertOne(sql) db.dispose() if dd != 0: # 分类添加成功 resp = {"code": 0, "msg": "success"} logger.debug('分类添加成功') else: # 分类添加失败 resp = {"code": 1, "msg": "internal_exceptions"} logger.debug('分类异常,分类添加失败') return HttpResponse(json.dumps(resp), content_type="application/json")
def add_server(req): """ 添加服务 :param req: :return: """ logger.debug('添加服务传入参数:' + str(req.POST)) data = req.POST.copy() db = Mysql() is_exist = db.getAll('SELECT * from server where `name` =\'%s\'' % (data['name'])) if (is_exist): # 已存在该服务无法添加 resp = {"code": 2, "msg": "server_is_exist"} logger.debug('添加失败,服务已存在') else: sql = "INSERT INTO `server` ( `name`, `server_category_id`, `price`) VALUES ('%s', '%s', '%s');" % ( data['name'], data['type'], data['price']) logger.debug(sql) dd = db.insertOne(sql) db.dispose() if dd != 0: # 服务添加成功 resp = {"code": 0, "msg": "success"} logger.debug('商品添加成功') else: # 服务添加失败 resp = {"code": 1, "msg": "internal_exceptions"} logger.debug('服务异常,商品添加失败') return HttpResponse(json.dumps(resp), content_type="application/json")
def add_vip_person(req): """ 会员添加 :param req: :return: """ # print (req) logger.debug('添加会员传入参数:'+str(req.POST)) data = req.POST.copy() if data['sex'] == '男': data['sex'] = '1' else: data['sex'] = '0' db = Mysql() is_exist = db.getAll('SELECT * from person where phone =\'%s\''%(data['phone'])) if (is_exist): # 已存在手机号无法注册会员 resp = { "code": 2, "msg": "phone_is_exist" } logger.debug('添加失败,手机号已存在') else: sql = "INSERT INTO person (`name`, `sex`, `phone`, `note`, `create_time`, `resrver1`)" \ " VALUES('%s','%s','%s','%s',now(),NULL)" %(data['username'],data['sex'],data['phone'],data['desc']) logger.debug (sql) dd = db.insertOne(sql) db.dispose() if dd != 0: # 会员添加成功 resp = { "code": 0, "msg": "success" } logger.debug('会员添加成功') else: # 会员添加失败 resp = { "code": 1, "msg": "internal_exceptions" } logger.debug('服务异常,会员添加失败') return HttpResponse(json.dumps(resp), content_type="application/json")
def add_good(req): """ 添加商品 :param req: :return: """ logger.debug('添加商品传入参数:' + str(req.POST)) data = req.POST.copy() if float(data['origin_price'])> float(data['price']): resp = { "code": 3, "msg": "price_incorrect" } logger.debug('原价低于售价,请重新添加') else: db = Mysql() is_exist = db.getAll('SELECT * from good where `name` =\'%s\'' % (data['title'])) if (is_exist): # 已存在该商品无法添加 resp = { "code": 2, "msg": "good_is_exist" } logger.debug('添加失败,商品已存在') else: # count = str(int(data['add_count'])+int(data['count'])) sql = "INSERT INTO `good` (`name`, `good_category_id`, `price`, `uploadtime`, `status`,`origin_price`) VALUES ('%s', '%s', '%s', now(), '%s','%s');"%(data['title'],data['type'],data['price'],data['count'],data['origin_price']) logger.debug(sql) dd = db.insertOne(sql) db.dispose() if dd != 0: # 会员添加成功 resp = { "code": 0, "msg": "success" } logger.debug('商品添加成功') else: # 会员添加失败 resp = { "code": 1, "msg": "internal_exceptions" } logger.debug('服务异常,商品添加失败') return HttpResponse(json.dumps(resp), content_type="application/json")
def add_ad(req): """ 添加公告 :param req: :return: """ id_list = req.POST.copy() logger.debug("添加公告传入的参数:" + str(id_list)) sql = "INSERT INTO `ad`(`info`,`atime`) VALUES ('%s', now())" % ( id_list['ad']) print(sql) db = Mysql() count = (db.insertOne(sql)) db.dispose() if count: resp = {"code": 0, "msg": "success"} else: resp = {"code": 1, "msg": "internal_exceptions"} return HttpResponse(json.dumps(resp), content_type="application/json")
def wx_add_love(req): """ 微信小程序添加收藏 :param req: :return: """ good_id = req.POST['id'] openid = req.POST['openid'] db = Mysql() sql = "INSERT INTO person_love(`good_id`,`openid`,`add_time`)VALUES(%s,'%s',now())" % ( good_id, openid) # print(sql) result = db.insertOne(sql) logger.debug(result) if int(result) > 0: resp = {"code": 1, "msg": "success", "data": ''} else: resp = {"code": 400, "msg": "fail", "data": ''} return HttpResponse(json.dumps(resp), content_type="application/json")
def add_good(req): """ 添加商品 :param req: :return: """ logger.debug('添加商品传入参数:' + str(req.POST)) data = req.POST.copy() db = Mysql() resp = '' is_exist = db.getAll('SELECT * from good where `name` =\'%s\'' % (data['title'])) if is_exist: # 已存在该商品无法添加 resp = {"code": 2, "msg": "good_is_exist"} logger.debug('添加失败,商品已存在') else: sql = "INSERT INTO `good` (`name`, `good_category_id`, `price`, `uploadtime`, `status`,`img_url`,`img_urls`,`origin_price`,`good_info`) VALUES ('%s', '%s', '%s', now(), '%s','%s','%s',0,'%s');" % ( data['title'], data['category'], data['price'], 1, data['image_url'], data['image_url2'][1:], data['bz']) logger.debug(sql) dd = db.insertOne(sql) if dd != 0: # 商品添加成功 resp = {"code": 0, "msg": "success"} logger.debug('商品添加成功') else: # 会员添加失败 resp = {"code": 1, "msg": "internal_exceptions"} logger.debug('分类异常,商品添加失败') db.dispose() return HttpResponse(json.dumps(resp), content_type="application/json")
def add_order(req): """ 订单添加 :param req: :return: """ logger.debug('订单生成传入参数:' + str(req.POST)) data = req.POST.copy() db = Mysql() resp = '' good_list = [] server_list = [] sql_list = [] for x in data: if 'good' in x and data[x] != '0': if x[4:] != '': good_list.append(x[4:] + '-' + data[x]) else: logger.debug("未选取任何商品") elif 'server' in x and data[x] != '0': if x[6:] != '': server_list.append(x[6:7]) else: logger.info("未选取任何服务") else: pass logger.info('本次商品清单:'.join(good_list)) logger.info('本次服务清单:'.join(server_list)) if 'new_dd' not in data: num = 1 is_exist = db.getAll("SELECT * from vip_order where `person_id` ='%s' and order_status = 0 " % (data['id'])) if (is_exist): # 该会员已存在订单无法继续添加 resp = { "code": 2, "msg": "main_order_is_exist" } logger.debug('订单生成失败,该会员主订单已存在') db.dispose() else: serial_num = time.strftime("%Y%m%d%H%M%S", time.localtime()) # price = db.getAll("SELECT price FROM order_category WHERE id ='%s'"%data['type']) #if price: sql = "INSERT INTO vip_order(`person_id`,`order_serial_number`, `order_status`, `order_category_id`, `create_time`, `notes`,`lay_value`, `free_value`) VALUES ('%s','%s','0', '%s', now(), '%s' ,'0','0');" % ( data['id'],serial_num,data['type'], data['vip_notes']) dd = db.insertOne(sql) # print (dd) if dd != 0: # print (good_list) #print (server_list) for good in good_list: sql_list.append("INSERT INTO `order_good_item`( `order_id`, `good_id`, `good_count`) VALUES ( '%s', '%s', '%s');"%(dd,good.split('-')[0],good.split('-')[1])) now_count = db.getAll("select status from good WHERE id = '%s'"%(good.split('-')[0])) # print(now_count) if now_count: # print (int(now_count[0]['status'])) # print (int(good.split('-')[1])) left_count = (int(now_count[0]['status'])-int(good.split('-')[1])) # print("UPDATE good SET status = '%s' WHERE id = '%s'"%(str(left_count),good.split('-')[0])) sql_list.append("UPDATE good SET status = '%s' WHERE id = '%s'"%(str(left_count),good.split('-')[0])) else: return for server in server_list: sql_list.append("INSERT INTO `vms`.`order_server_item` ( `order_id`, `server_id`, `server_count`) VALUES ('%s', '%s', '1');"%(dd,server)) # print (sql_list) # print (len(sql_list)) dd2 = db.inserGoodServer(num,dd,sql_list) logger.info('插入影响行数:'+str(dd2)) db.dispose() if dd2 == len(sql_list): resp = { "code": 0, "msg": "success" } logger.debug('订单生成成功') else: resp = { "code": 1, "msg": "internal_exceptions" } logger.debug('订单生成失败') else: num = 2 # 查询出主订单的id dd = db.getOne("SELECT id,free_value,lay_value FROM vip_order WHERE person_id ='%s' and order_status = 0"%data['id']) if dd: # 新增商品的sql语句插入sql_list以及商品消费 for good in good_list: sql_list.append("INSERT INTO `order_good_item`( `order_id`, `good_id`, `good_count`) VALUES ( '%s', '%s', '%s');" % ( dd['id'], good.split('-')[0], good.split('-')[1])) now_count = db.getAll("select status from good WHERE id = '%s'" % (good.split('-')[0])) # print(now_count) if now_count: left_count = (int(now_count[0]['status']) - int(good.split('-')[1])) # print("UPDATE good SET status = '%s' WHERE id = '%s'"%(str(left_count),good.split('-')[0])) sql_list.append( "UPDATE good SET status = '%s' WHERE id = '%s'" % (str(left_count), good.split('-')[0])) else: return # 新增服务的sql语句插入sql_list for server in server_list: sql_list.append("INSERT INTO `vms`.`order_server_item` ( `order_id`, `server_id`, `server_count`) VALUES ('%s', '%s', '1');" % ( dd['id'], server)) # # 延时费用和优惠费用的sql语句插入sql_list # if data['free_value'] == '' and data['lay_value'] == '': # pass # else: # if data['free_value'] == '': # data['free_value'] = 0 # if data['lay_value'] == '': # data['lay_value'] = 0 # free = float(dd['free_value']) + float(data['free_value']) # lay = float(dd['lay_value']) + float(data['lay_value']) # sql_list.append("UPDATE vip_order SET free_value ='%s' ,lay_value ='%s' WHERE id ='%s'"%(free,lay,dd['id'])) # print(sql_list) # print(len(sql_list)) # 执行新增消费的记录插入,包括延时费用和优惠费用的更新 if len(sql_list) != 0: dd2 = db.inserGoodServer(num,dd,sql_list) logger.info('插入影响行数:' + str(dd2)) if dd2 == len(sql_list): resp = { "code": 0, "msg": "success" } logger.debug('新增消费成功') else: resp = { "code": 1, "msg": "internal_exceptions" } logger.debug('新增消费失败') else: resp = { "code": 3, "msg": "nothing_is_changed" } logger.debug('新增消费失败') db.dispose() return HttpResponse(json.dumps(resp), content_type="application/json")