Ejemplo n.º 1
0
def burse_balance():
    token = request.args.get('token', None)
    print(token)
    if token:
        user_id = cache.get_token_user_id(token)
        print(user_id)
        vip_fee = request.args.get('vip_fee')
        burse_balance = UserDao().get_burse(user_id)[0]['u_burse_balance']
        print(burse_balance)
        if burse_balance:
            if int(vip_fee) > int(burse_balance):
                api_logger.warning("余额不足")
                return jsonify({
                    "code":207,
                    'msg':'您的余额不足!'
                })
            else:
                burse_balance = int(burse_balance) - int(vip_fee)
                UserDao().burse_change(user_id,burse_balance)
                api_logger.info("充值成功")
                return jsonify({
                    'code':200,
                    'msg':'恭喜您,您已成功充值会员!'
                })
        else:
            api_logger.warning("余额为0")
            return jsonify("您还没有余额,请充值")
    else:
        api_logger.info("user_id为空")
        return jsonify('查无此用户')
Ejemplo n.º 2
0
def user_regist():
    # 前端请求的Content-Type: application/json
    req_data = None
    api_logger.info(request.headers)
    if request.headers['Content-Type'].startswith('application/json'):
        req_data = request.get_json()

    if req_data is None:
        api_logger.warn('%s 请求参数未上传-json' % request.remote_addr)
        return jsonify({'code': 9000, 'msg': '请上传json数据,且参数必须按api接口标准给定'})

    api_logger.debug(req_data)

    # 验证上传的必须的数据是否存在
    if all((req_data.get('login_name',
                         False), req_data.get('login_auth_str', False))):

        req_data['create_time'] = datetime.now().strftime('%Y-%m-%d')
        req_data['update_time'] = req_data['create_time']
        req_data['activated'] = 1  # 默认激活

        dao = UserDao()
        if dao.check_login_name(req_data.get('login_name')):

            if dao.save(**req_data):
                return jsonify({'code': 200, 'msg': 'ok'})

            return jsonify({'code': 300, 'msg': '插入数据失败, 可能存在某一些字段没有给定值'})
        else:
            return jsonify({'code': 201, 'msg': '用户名已存在,不能再注册'})
Ejemplo n.º 3
0
 def update_asset(self, user_id, asset):
     api_logger.info('db update jd_user: <%s>' % 'user_id')
     sql = "update jd_user set asset=%s" \
           "where user_id=%s"
     user_asset = self.query(sql, asset, user_id)
     if user_asset:
         return True
Ejemplo n.º 4
0
def get_shop_storeinfo():
    shop_id = request.args.get('shop_id')
    shop_address = dao.get_shop(shop_id)['shop_address']
    shop_time = dao.get_shop(shop_id)['shop_time']
    app_delivery_tip = dao.get_shop(shop_id)['app_delivery_tip']
    shop_tel = dao.get_shop(shop_id)['shop_tel']
    shop_discounts2 = dao.get_discounts2(shop_id)
    shop_poi_env = dao.get_poi_env(shop_id)
    shop_poi_service = dao.get_poi_service(shop_id)
    api_logger.info("商家信息查询成功")
    return jsonify({
        'code': 200,
        'msg': '商家信息查询成功',
        'data': {
            'data': {
                'shop_address': shop_address,
                'shop_time': shop_time,
                'app_delivery_tip': app_delivery_tip,
                'shop_tel': shop_tel
            },
            'discounts': shop_discounts2,
            'poi_env': shop_poi_env,
            'poi_service': shop_poi_service
        }
    })
Ejemplo n.º 5
0
    def count(self,
              first_table_name,
              *fields,
              arg,
              alias,
              second_table_name=None,
              b_con=None,
              a_con=None,
              b_arg=None,
              a_arg=None,
              args):
        if not second_table_name:
            sql = "select {}, count({}) as {} from {} group by {}".format \
                (','.join(*fields), arg, alias, first_table_name, args)

        else:
            sql = "select {}, count({}) as {} from {} join {} on {}={} and {}={} group by {}".format \
                (','.join(*fields), arg, alias, first_table_name, second_table_name, b_con, a_con, b_arg, a_arg, args)

        with self.db as c:
            c.execute(sql)
            data = c.fetchall()
            api_logger.info('%s ok!' % sql)
            if data:
                data = list(data)
        return data
Ejemplo n.º 6
0
 def baselist(cls, sql):
     dao = BaseDao()
     with dao.db as c:
         c.execute(sql)
         items = c.fetchall()
         api_logger.info('select %s ok!' % sql)
     return items
Ejemplo n.º 7
0
def msglogin():
    api_logger.debug('user phone_login get action!')
    resp = eval(request.get_data())
    if resp:
        u_phone = resp.get('phone')
        u_auth_string = resp.get('auth_string')
        if all((bool(u_phone), bool(u_auth_string))):
            udao = UserDao()
            # 验证手机号在数据库中是否存在
            if udao.check_login_phone(u_phone):
                try:
                    # 验证密码是否正确
                    login_user = udao.pwdlogin(u_phone, u_auth_string)[0]
                    if login_user.get('id'):
                        token = cache_.new_token()
                        cache_.save_token(token, login_user.get('id'))
                        udao.user_update('is_active', 1, 'u_phone', u_phone)
                        return jsonify({
                            'code': 200,
                            'token': token,
                            'user_data': login_user
                        })
                    return jsonify(login_user)
                except Exception as e:
                    api_logger.info(e)
                    return jsonify({'code': 202, 'msg': str(e)})
            return jsonify({'code': 203, 'msg': '该手机尚未注册'})
        else:
            return jsonify({
                'code': 204,
                'msg': '请求参数u_phone和u_auth_string必须存在'
            })
    return jsonify({'code': 304, 'msg': '传入数据为空'})
Ejemplo n.º 8
0
def send_msg():
    resp = eval(request.get_data())
    if resp:
        u_phone = resp.get('u_phone')
        code = ''.join([str(random.randint(0, 9)) for _ in range(6)])
        res = eval(send_sms_code(u_phone, code).decode())
        if res['Code'] == 'OK':
            try:
                rd.setex(u_phone, code, 120)  # 保存到redis缓存
            except Exception as e:
                api_logger.error(e)
                return jsonify({'code': 802,
                                'msg': '短信验证码保存失败'
                                })
            api_logger.info('发送手机号:%s,短信验证码为:%s' % (u_phone, code))
            return jsonify({'code': 200,
                            'msg': '短信验证码发送成功!'
                            })
        if res['Code'] == 'isv.BUSINESS_LIMIT_CONTROL':
            return jsonify({'code': 303,
                            'msg': '频繁验证,请稍后再试'
                            })
        return jsonify({'code': 303,
                        'msg': '请输入正确的手机号码'
                        })
Ejemplo n.º 9
0
 def type_list(self, countryid):
     api_logger.info('db insert tn_user: <%s>' % "类型查询")
     sql = "select * from cities where country_id=%s and is_popular=1" % countryid
     with self.db as c:
         c.execute(sql)
         items = c.fetchall()
     return items
Ejemplo n.º 10
0
def lendrecords():
    req_data = None
    api_logger.info(request.headers)
    if request.headers['Content-Type'].startswith('application/json'):
        req_data = request.get_json()
    if req_data is None:
        api_logger.warn('%s 请求参数未上传-json' % request.remote_addr)
        return jsonify({'code': 9000, 'msg': '请上传json数据,且参数必须按api接口标准给定'})

    api_logger.debug(req_data)

    # 验证上传的必须的数据是否存在
    if all((req_data.get('productId', False), )):
        all_lendrecords = dao.all_lendrecords(req_data.get('productId'))
        if all_lendrecords:
            datas = []
            for i in all_lendrecords:
                data = {}
                data["lendMoney"] = i["lendMoney"]
                data["lendTime"] = str(i["lendTime"])
                data['lendUserTel'] = i['lendUserTel']
                datas.append(data)
            return jsonify(datas)
        else:
            return jsonify({'code': 202, 'msg': '没有该出借记录'})
    else:
        return jsonify({"code": 201, "msg": "产品id输入有误"})
Ejemplo n.º 11
0
def user_add():
    token = request.args.get('token', None)
    user_id = get_token_user_id(token)
    if user_id:
        r_data = request.get_json()
        print(r_data)
        phone = r_data['phone']
        address = r_data['address']
        linkman = r_data['name']
        num = r_data['bottom']
        sex = r_data['sex']
        tag = r_data['tag']

        # user_id = r_data['user_id
        data = {
            'address': address,  # 地址
            'bottom': num,  # 门牌号
            'name': linkman,  # 联系人
            'phone': phone,  # 手机
            'user_id': user_id,
            'sex': sex,
            'tag': tag
        }
        User_Featuare_Dao().saves(**data)
        api_logger.info("地址成功添加")
        return jsonify({'code': 200, 'msg': '地址添加成功', 'data': data})
    return jsonify({'code': 207, 'msg': '你还未登录请登录'})
Ejemplo n.º 12
0
def rzlend():
    req_data = None
    api_logger.info(request.headers)
    if request.headers['Content-Type'].startswith('application/json'):
        req_data = request.get_json()
    if req_data is None:
        api_logger.warn('%s 请求参数未上传-json' % request.remote_addr)
        return jsonify({
            'code': 9000,
            'msg': '请上传json数据,且参数必须按api接口标准给定'
        })

    api_logger.debug(req_data)

    # 验证上传的必须的数据是否存在
    if all((req_data.get('token', False),)):
        token=req_data.get('token')
        user_id = get_token_user_id(token)
        if dao.user_verify(user_id):
            return jsonify({
            "code":200,
            "msg":"已认证"
            })
        else:
            return jsonify({
            "code": 201,
            "msg": "未认证"
            })
    return jsonify({
        "code": 203,
        "msg": "未获得token"
    })
Ejemplo n.º 13
0
def main_view():
    if request.method == "POST":
        # r_data = request.get_json()
        r_data = request.get_json()
        print(r_data)
        print(type(r_data))
        try:
            lat = r_data['lat']
            print(lat)
            lon = r_data['lon']
            if all((lat, lon)):
                wheel = dao.wheel()
                main_type_img = dao.main_type()
                main_small_img = dao.main_small_img()
                shops = dao.youxuan_shops()
                foodlists = []
                for shop in shops:
                    food_data = {}
                    shop_id = shop['id']
                    good_pic = dao.get_goodpic(shop_id)
                    food_data['shop_id'] = shop_id
                    food_data['shop_name'] = shop['shop_name']
                    food_data['shop_img'] = shop['img_url']
                    food_data['good_img'] = good_pic
                    food_data['app_delivery_tip'] = shop['app_delivery_tip']
                    foodlists.append(food_data)
                # goodfood = dao.youxuan_goods()
                goodfood = dao.youxuan_goods()
                for good in goodfood:
                    good['shop_name'] = dao.get_shopname(good['g_shop_id'])
                    good['shop_img'] = dao.get_shop_head_pic(good['g_shop_id'])
                shoplists = dao.shoplists()
                nearbylists = dao.shop_nearby(lat, lon)
                shop_discounts2 = []
                for shop in shops:
                    shop_id = shop['id']
                    shop_discounts2.append(ShopDao().get_discounts2(shop_id))
                result = {
                    "code": 200,
                    "msg": "ok",
                    "data": {
                        "wheel": wheel,
                        "main_type_img": main_type_img,
                        "main_small_img": main_small_img,
                        "foodlist": foodlists,
                        "goodfood": goodfood,
                        "shoplists": shoplists,
                        "nerbylists": nearbylists,
                        "shop_discounts2": shop_discounts2
                    }
                }
                api_logger.info("主页面显示成功")
                return jsonify(result)
        except Exception as e:
            api_logger.error("参数错误%s" % e)
            return jsonify({'code': 207, 'msg': '请传入正确的参数lat和lon'})
    else:
        api_logger.error("请求方式错误")
        return jsonify({"code": 207, "msg": "请求参数错误"})
Ejemplo n.º 14
0
 def query(self, sql, *args):
     with self.db as c:
         c.execute(sql, args=args)
         api_logger.info('%s ok!' % sql)
         data = c.fetchall()
         if data:
             data = list(data)
         return data
Ejemplo n.º 15
0
def shop_pl():
    v_shop_id = request.args.get('v_shop_id')
    data = User_Featuare_Dao().shop_pl(v_shop_id)
    api_logger.info("显示所有评论")
    return jsonify({
        'code': 200,
        'data': data,
    })
Ejemplo n.º 16
0
 def delete(self, table_name, where=None, args=None):
     sql = "delete from {} where {}='{}'".format(table_name, where, args)
     success = False
     with self.db as c:
         c.execute(sql)
         api_logger.info('%s ok!' % sql)
         success = True
     return success
Ejemplo n.º 17
0
 def get_asset(self, user_id):
     api_logger.info('db get jd_user: <%s>' % 'user_id')
     # 获取用户的详细信息
     sql = "select user_id,user_name, tel, u_img, u_email, is_val,asset from jd_user " \
           "where user_id=%s"
     user_profile = self.query(sql, user_id)
     if user_profile:
         return user_profile[0]
Ejemplo n.º 18
0
 def update(self,user_id_id,goods_id,goods_cart_num):
     api_logger.info('db insert goods_details: <%s>' % user_id_id)
     sql = "update goods_details set goods_num=goods_num-%s"\
           "where goods_id=%s"
     success = False
     with self.db as c:
         c.execute(sql,goods_cart_num,goods_id)
         success = True
     return success
Ejemplo n.º 19
0
 def get_addr(self,user_id_id):
     api_logger.info('db insert jd_user: <%s>' % user_id_id)
     sql = "select * from u_address " \
           "where user_id_id=%s"
     resp = self.query(sql, user_id_id)
     if resp:
         return resp[0]["user_address"]
     else:
         return "北京"
Ejemplo n.º 20
0
 def update(self, table_name, key, value, where=None, args=None):
     sql = "update {} set {}='{}' where {}='{}' ".format(
         table_name, key, value, where, args)
     succuss = False
     with self.db as c:
         c.execute(sql)
         api_logger.info('%s ok!' % sql)
         succuss = True
     return succuss
Ejemplo n.º 21
0
 def delete_tab(self, talbe_name, goods_id, user_id):
     sql = "delete from %s where c_goods_id=%s and c_user_id=%s" % (
         talbe_name, goods_id, user_id)
     success = False
     with self.db as c:
         c.execute(sql)
         api_logger.info('delete %s ok!' % sql)
         success = True
     return success
Ejemplo n.º 22
0
 def UpdateOrder(self,user_id,state,o_num):
     api_logger.info('db update o_detail: <%s>' % user_id)
     sql = "update o_detail set o_status=%s " \
           "where o_num=%s"%(state,o_num)
     succuss = False
     with self.db as c:
         c.execute(sql)
         api_logger.info('%s ok!' % sql)
         succuss = True
     return succuss
Ejemplo n.º 23
0
    def save(self, table_name, **values):
        sql = 'insert into %s(%s) values(%s)' % \
              (table_name,
               ','.join(values.keys()),
               ','.join(["'" + v + "'" for v in values.values()]))

        with self.db as c:
            c.execute(sql, args=values)

        api_logger.info('insert %s ok!' % sql)
Ejemplo n.º 24
0
def del_address():
    token = request.args.get('token', None)
    # r_data = request.get_data()
    # print(r_data)
    sid = request.args.get('id')
    user_id = get_token_user_id(token)
    # user_id = r_data['user_id']
    User_Featuare_Dao().del_address(sid, user_id)
    api_logger.info("地址删除成功")
    return jsonify({"code": 200, "msg": "删除成功!"})
Ejemplo n.º 25
0
def user_comment():
    token = request.args.get('token', None)
    if token is None:
        api_logger.warning("未登录")
        return jsonify({'code': 207, 'msg': '未登录,请登录'})
    if check_token(token):
        user_id = get_token_user_id(token)
        data = User_Featuare_Dao().user_comment(user_id)
        api_logger.info("评论显示成功")
        return jsonify({"code": 200, "data": data, "msg": "查询成功"})
Ejemplo n.º 26
0
 def sort_down(self):
     # 按金额升序排序
     sql = "select * from jd_coupon order by minusprice desc"
     with self.db as c:
         c.execute(sql)
         data = c.fetchall()
         api_logger.info('%s ok!' % sql)
         if data:
             data = list(data)
     return data
Ejemplo n.º 27
0
 def tn_list(self,
             table_name,
             *fields,
             where=None,
             args=None,
             page=1,
             page_size=20):
     api_logger.info('db insert tn_user: <%s>' % table_name)
     items = super(CountryDao, self).tn_list(table_name)
     return items
Ejemplo n.º 28
0
def to_rzlend():
    req_data = None
    api_logger.info(request.headers)
    if request.headers['Content-Type'].startswith('application/json'):
        req_data = request.get_json()
    if req_data is None:
        api_logger.warn('%s 请求参数未上传-json' % request.remote_addr)
        return jsonify({
            'code': 9000,
            'msg': '请上传json数据,且参数必须按api接口标准给定'
        })

    api_logger.debug(req_data)

    # 验证上传的必须的数据是否存在
    if all((req_data.get('userName', False),
            req_data.get('userCard', False),
            req_data.get('token',False))):
        userName = req_data['userName']
        userCard = req_data["userCard"]
        token = req_data['token']
        data={}
        data['user_id'] = get_token_user_id(token)
        if dao.toverify(userName,userCard):
            data['verify_id']= dao.toverify(userName,userCard)['id']
            if not dao.query_user_verify(data['verify_id']):
                if dao.save_verify(**data):
                    print(data['user_id'])
                    if dao.update_user(data['user_id']):
                        return jsonify({
                            'code': 200,
                            'msg': "姓名和身份证号,对上了"
                        })
                else:
                    return jsonify({
                        'code': 201,
                        'msg': "认证失败"
                    })
            else:
                return jsonify({
                    'code': 202,
                    'msg': "此卡已被绑定"
                })

        else:
            return jsonify({
                'code':203,
                'msg':"请输入正确的姓名和身份证号"
            })
    else:
        return jsonify({
            'code':204,
            'msg': "传入参数不足"
        })
Ejemplo n.º 29
0
def get_shop_goodsinfo():
    shop_id = request.args.get('shop_id')
    shop_goods_data = dao.get_shop_goods(shop_id)
    api_logger.info("商品信息查询成功")
    return jsonify({
        'code': 200,
        'msg': '商品信息查询成功',
        'data': {
            'data': shop_goods_data,
        }
    })
Ejemplo n.º 30
0
 def delete_user_cart_course(self, cid, uid):
     api_logger.info("%s have been delete", cid)
     sql = "delete from carts where course_id = %s and user_id=%s"
     try:
         success = False
         with self.db as c:
             c.execute(sql,(cid,uid))
             success = True
         return success
     except Exception as e:
         api_logger.error("delete cart_course failed", e )