Exemplo n.º 1
0
Arquivo: API.py Projeto: zzhangdi/ZD
 def put(self, token):
     args = parser.parse_args()
     result = {}
     mq = Mysqllink()
     now_time = time.strftime('%Y-%m-%d %H:%M:%S',
                              time.localtime(time.time()))
     sql = 'update orders set status=%s,update_at=%s where id=%s'
     valu = (args['status'], now_time, args['order_id'])
     mq.update(sql, valu)
     sql = 'select * from orders where id=%s'
     mq.select(sql, args['order_id'])
     orders = mq.cursor.fetchall()[0]
     sql = 'select * from order_detail where order_id=%s'
     mq.select(sql, orders['id'])
     order_detail = mq.cursor.fetchall()
     data = []
     for i in order_detail:
         dic = {}
         subtotal = str(i['subtotal'])
         dic.update({'id': i['goods_id'], 'subtotal': subtotal})
         data.append(dic)
     total_price = str(orders['total_price'])
     result['code'] = 200
     result['data'] = {
         'order': {
             'id': orders['id'],
             'status': orders['status'],
             'address': orders['addr_id'],
             'production': data,
             'price': total_price,
             'create_at': orders['create_at'],
             'update_at': orders['update_at']
         }
     }
     return jsonify(result)
Exemplo n.º 2
0
Arquivo: API.py Projeto: zzhangdi/ZD
 def put(self, token):
     args = parser.parse_args()
     result = {}
     admin_user_id = args['admin_user_id']
     if args['name']=="" or args['phone']=="" or args['pwd']=="" or args['des']=="" or args['post_id'] =="" \
         or args['is_super']=="":
         result = 4026
         result = "信息不完善!"
         return jsonify(result)
     elif re.match(r'^1[345789]\d{9}$', args['phone']) is None:
         result['code'] = 4020
         result['message'] = "此号码不存在!"
         return jsonify(result)
     mq = Mysqllink()
     sql = 'select * from admin_users where phone=%s and id!=%s'
     valu = (args['phone'], admin_user_id)
     n = mq.select(sql, valu)
     if n:
         result['code'] = 4022
         result['message'] = "此号码已注册!"
         return jsonify(result)
     #查看此管理员是不是超级管理员
     sql = 'select is_super from admin_users where id=%s'
     mq.select(sql, admin_user_id)
     super = mq.cursor.fetchall()[0]
     is_super = super['is_super']
     if is_super != 1:
         result['code'] = 4002
         result['message'] = "无此权限!"
         return jsonify(result)
     now_time = time.strftime('%Y-%m-%d %H:%M:%S',
                              time.localtime(time.time()))
     sql = 'update admin_users set name=%s,phone=%s,pwd=%s,des=%s,update_at=%s,post_id=%s,is_super=%s where id=%s'
     valu = (args['name'], args['phone'], args['pwd'], args['des'],
             now_time, args['post_id'], args['is_super'], args['id'])
     mq.update(sql, valu)
     sql = 'select create_at from admin_users where id=%s'
     mq.select(sql, admin_user_id)
     create_at = mq.cursor.fetchall()[0]['create_at']
     print(create_at)
     result['code'] = 200
     result['data'] = {
         'admin_user': [{
             'id': admin_user_id,
             'name': args['name'],
             'phone': args['phone'],
             'des': args['des'],
             'create_at': create_at,
             'update_at': now_time
         }]
     }
     return jsonify(result)
Exemplo n.º 3
0
Arquivo: API.py Projeto: zzhangdi/ZD
 def put(self, token):
     args = parser.parse_args()
     result = {}
     admin = args['admin_user_id']
     # print(admin)
     if args['name'] == "" or args['price'] == "" or args['img'] == "" or args['origin'] == "" or \
             args['unit'] == "" or args['sales'] == "" or args['des'] == "" or args['class_id'] == "":
         result['code'] = 4033
         result['message'] = "数据不完善!"
         return jsonify(result)
     qr = Query_rules()
     sql = 'select post_id from admin_users where id=%s'
     qr.select(sql, admin)
     au_post_id = qr.cursor.fetchall()[0]['post_id']
     qr.query_rule(au_post_id)
     admin_rules = qr.cursor.fetchall()
     rules = []
     for i in admin_rules:
         rules.append(i['name'])
     if 'update_goods' not in rules:
         result['code'] = 4002
         result['code'] = "无此权限!"
         return jsonify(result)
     mq = Mysqllink()
     now_time = time.strftime('%Y-%m-%d %H:%M:%S',
                              time.localtime(time.time()))
     sql = 'update goods set name=%s,img=%s,unit=%s,price=%s,sales=%s,des=%s,origin=%s,update_at=%s,class_id=%s where id=%s'
     valu = (args['name'], args['img'], args['unit'], args['price'],
             args['sales'], args['des'], args['origin'], now_time,
             args['class_id'], args['id'])
     n = mq.update(sql, valu)
     if n:
         sql = 'select create_at from goods where id=%s'
         mq.select(sql, args['id'])
         create_at = mq.cursor.fetchall()
         result['code'] = 200
         result['data'] = {
             'id': args['id'],
             'name': args['name'],
             'price': args['price'],
             'img': args['img'],
             'origin': args['origin'],
             'unit': args['unit'],
             'sales': args['sales'],
             'des': args['des'],
             'class_id': args['class_id'],
             'create_at': create_at,
             'update_at': now_time
         }
         return jsonify(result)
     else:
         result['code'] = 4028
         result['message'] = "更新失败!"
         return jsonify(result)
Exemplo n.º 4
0
Arquivo: API.py Projeto: zzhangdi/ZD
    def put(self, token):
        args = parser.parse_args()
        result = {}
        user_id = args['user_id'].strip()
        name = args['name'].strip()
        id = args['id'].strip()
        phone = args['phone'].strip()
        des = eval(args['des'])
        province = des['province'].strip()
        city = des['city'].strip()
        area = des['area'].strip()
        detail = des['detail'].strip()
        is_default = args['is_default'].strip()

        if user_id == "":
            result['code'] = 4025
            result['message'] = "未登录!"
            return jsonify(result)
        elif city == "" or area == "" or detail == "" or name == "" or phone == "":
            result['code'] = 4026
            result['message'] = "地址信息不完善!"
            return jsonify(result)
        elif re.match(r'^1[345789]\d{9}$', phone) is None:
            result['code'] = 4020
            result['message'] = "此号码不存在!"
            return jsonify(result)
        mq = Mysqllink()
        now_time = time.strftime('%Y-%m-%d %H:%M:%S',
                                 time.localtime(time.time()))
        sql = 'update addrs set name=%s,phone=%s,province=%s,city=%s,area=%s,detail=%s,is_default=%s,update_at=%s where id=%s'
        valu = (name, phone, province, city, area, detail, is_default,
                now_time, id)
        n = mq.update(sql, valu)
        if n:
            result['code'] = 200
            result['data'] = {
                'id': id,
                'user_id': user_id,
                'phone': phone,
                'name': name,
                'des': {
                    'province': province,
                    'city': city,
                    'area': area,
                    'detail': detail
                },
                'is_default': is_default
            }
            return jsonify(result)
        else:
            result['code'] = 430
            result['message'] = "修改失败!"
            return jsonify(result)