def change_assword(req): resp = '' token = req.POST.get('access_token') db =Mysql() result = db.getOne("select * from t_token a INNER JOIN manager b ON a.user_id = b.id and b.`password` ='%s' and a.token = '%s'"%(req.POST.get('oldPassword'),token)) if result: sql2 = "UPDATE manager SET `password` ='%s' WHERE id = '%s'"%(req.POST.get('password'),result['user_id']) if db.update(sql2): resp ={ "code": 0 ,"msg": "success" ,"data": { } } else: resp = { "code": 1 , "msg": "failed" , "data": { } } else: resp = { "code": 2 , "msg": "failed" , "data": { } } return HttpResponse(json.dumps(resp), content_type="application/json")
def delonsale_good(req): """ 清除特价 :param req: :return: """ logger.debug('清除特价商品传入参数:' + str(req.POST)) id_list = req.POST.copy()['checkData'] if id_list: if 'all' in id_list: logger.debug("待清除所有特价商品") sql = 'UPDATE good SET origin_price =0' else: logger.debug("待清除的特价商品的ID:" + str(id_list)) sql = 'UPDATE good SET origin_price = 0 WHERE id IN (%s)' % ( id_list) else: resp = {"code": 1, "msg": "internal_exceptions"} db = Mysql() result = db.update(sql) # print(result) if result != 0: resp = {"code": 0, "msg": "success"} else: resp = {"code": 1, "msg": "internal_exceptions"} return HttpResponse(json.dumps(resp), content_type="application/json")
def __deco(request, *para, **kw): if debug: print("JWT debug状态,未校验!") return func(request, *para, **kw) else: token = '' db = Mysql() if request.method == 'GET': token = request.GET.get('access_token') elif request.method == 'POST': token = request.POST.get('access_token') else: print('尚未处理的请求类型') if token is not None: try: payload = jwt.decode(token, 'mothanty', algorithms=['HS256']) except Exception as e: db.delete("DELETE FROM t_token WHERE token='%s'" % token) print(e) resp = { "code": 1001, "msg": "", "count": 0, "data": [] } return HttpResponse(json.dumps(resp), content_type="application/json") result = db.getAll( "select * from t_token where token = '%s' and DATE_SUB(now(), INTERVAL 1 HOUR)<time" % token) if payload: if result: db.update("UPDATE t_token set time = now() WHERE token ='%s'" % token) print (func.__name__ + '方法token校验--成功') return func(request, *para, **kw) print (func.__name__ + '方法token校验--失败') db.delete("DELETE FROM t_token WHERE token='%s'" % token) resp = { "code": 1001, "msg": "", "count": 0, "data": [] } return HttpResponse(json.dumps(resp), content_type="application/json")
def edit_server(req): """ 编辑服务 :param req: :return: """ logger.debug('更新服务传入参数:' + str(req.POST)) data = req.POST.copy() logger.debug(data) sql2 = "SELECT * from server where `name` ='%s' and id != '%s'" % (data['name'], data['id']) logger.debug(sql2) db = Mysql() is_exist = db.getAll(sql2) if(is_exist): # 无法更新为已存在服务 resp = { "code": 2, "msg": "server_is_exist" } logger.debug('更新失败,商品已存在') else: result = db.getOne("SELECT * from server where id = '%s'" % data['id']) # print(result) if result['name']== data['name'] and float(result['price']) == float(data['price']) and int(result['server_category_id']) == int(data['type']) : # 服务未更改无需更新 resp = { "code": 2, "msg": "nothing is changed" } logger.debug('服务异常,服务更新失败') else: sql = "UPDATE server SET `name` = '%s',server_category_id= '%s',price='%s' WHERE id='%s'" % (data['name'], data['type'], data['price'],data['id']) logger.debug(sql) dd = db.update(sql) # print(dd) 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 edit_good(req): """ 编辑商品 :param req: :return: """ logger.debug('更新商品传入参数:' + str(req.POST)) data = req.POST.copy() logger.debug(data) sql2 = "SELECT * from good where `name` ='%s' and id != '%s'" % (data['title'], data['id']) logger.debug(sql2) if float(data['origin_price']) > float(data['price']): resp = { "code": 3, "msg": "price_incorrect" } logger.debug('原价低于售价,请重新更新') else: db = Mysql() is_exist = db.getAll(sql2) if(is_exist): # 无法更新为已存在商品 resp = { "code": 2, "msg": "good_is_exist" } logger.debug('更新失败,商品已存在') else: count = str(int(data['count'])+int(data['add_count'])) sql = "UPDATE good SET `name` = '%s',good_category_id= '%s',price='%s',status='%s',uploadtime = now(),origin_price='%s' WHERE id=%s" % ( data['title'], data['type'], data['price'], count, data['origin_price'],data['id']) logger.debug(sql) dd = db.update(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 edit_vip_person(req): """ 更新会员信息 :param req: :return: """ logger.debug('更新会员传入参数:' + str(req.POST)) data = req.POST.copy() logger.debug(data) if data['sex'] == '男': data['sex'] = '1' else: data['sex'] = '0' db = Mysql() sql2 = "SELECT * from person where phone ='%s' and id != '%s'" %(data['phone'],data['id']) logger.debug(sql2) is_exist = db.getAll(sql2) if (is_exist): # 无法更新为已存在的手机号 resp = { "code": 2, "msg": "phone_is_exist" } logger.debug('更新失败,手机号已存在') else: sql = "UPDATE person SET name = '%s',sex= '%s',phone='%s',note='%s',create_time = now() WHERE id=%s" % (data['username'], data['sex'], data['phone'], data['desc'],data['id']) logger.debug(sql) dd = db.update(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 del_order(req): """ 废弃订单,将订单状态修改为2,此单消费货物返还。 :param req: :return: """ logger.debug('订单废弃传入参数:' + str(req.GET)) data = req.GET.copy() sql_list = [] sql = "UPDATE vip_order SET order_status = 2,all_value = '0',end_time=now() WHERE order_serial_number = '%s'"%data['order_serial_number'] sql2 = "select a.good_id,a.good_count from order_good_item a INNER JOIN vip_order b ON a.order_id = b.id and b. order_serial_number = '%s'" %data['order_serial_number'] db = Mysql() result = db.getAll(sql2) # print(result) if result: for x in result: good_id = x['good_id'] good_count = int(x['good_count']) sql_list.append("UPDATE good SET status = status+'%d' WHERE id = '%s'"%(good_count,good_id)) sql_list.append(sql) count = db.excuteManysql(sql_list) # print(count) if count == 1+len(result): resp = { "code": 0, "msg": "success" } logger.debug('订单废弃成功') else: resp = { "code": 1, "msg": "internal_exceptions" } else: count = db.update(sql) if count == 1: resp = { "code": 0, "msg": "success" } logger.debug('订单废弃成功') else: resp = { "code": 1, "msg": "internal_exceptions" } db.dispose() return HttpResponse(json.dumps(resp), content_type="application/json")
def edit_server(req): """ 编辑分类 :param req: :return: """ logger.debug('更新传入参数:' + str(req.POST)) data = req.POST.copy() logger.debug(data) sql2 = "SELECT * from good_category where `name` ='%s' and id != '%s'" % ( data['name'], data['id']) logger.debug(sql2) db = Mysql() is_exist = db.getAll(sql2) if is_exist: # 无法更新为已存在分类 resp = {"code": 2, "msg": "server_is_exist"} logger.debug('更新失败,分类已存在') else: result = db.getOne("SELECT * from good_category where id = '%s'" % data['id']) # print(result) if result['name'] == data['name'] and int(result['sort']) == int( data['sort']): # 分类未更改无需更新 resp = {"code": 2, "msg": "nothing is changed"} logger.debug('未变更,无需更新') else: sql = "UPDATE good_category SET `name` = '%s',`sort`= '%s' WHERE id='%s'" % ( data['name'], data['sort'], data['id']) logger.debug(sql) dd = db.update(sql) # print(dd) 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 grounding_good(req): """ 上架商品 :param req: :return: """ logger.debug('上架商品传入参数:' + str(req.POST)) id_list = req.POST.copy()['checkData'] logger.debug("上架商品的ID:" + str(id_list)) sql = 'UPDATE good SET status=1 WHERE id IN (%s)' % (id_list) db = Mysql() result = db.update(sql) print(result) if result == len(id_list.split(",")): resp = {"code": 0, "msg": "success"} else: resp = {"code": 1, "msg": "internal_exceptions"} return HttpResponse(json.dumps(resp), content_type="application/json")
def onsale_good(req): """ 特价商品 :param req: :return: """ logger.debug('特价商品传入参数:' + str(req.POST)) orgin_price = req.POST.copy()['origin_price'] id = req.POST.copy()['id'] logger.debug("特价商品的ID:" + id) sql = 'UPDATE good SET origin_price=%s WHERE id = %s' % (orgin_price, id) db = Mysql() try: result = db.update(sql) except Exception as e: print(e) print(result) if result == 1: resp = {"code": 0, "msg": "success"} else: resp = {"code": 1, "msg": "internal_exceptions"} return HttpResponse(json.dumps(resp), content_type="application/json")