Exemplo n.º 1
0
from fullstack.Models.Food import Food
from fullstack.utils import getCurrentTime, to_json


class AddFoods(Resource):
    def post(self):
        response = {'meta': {'status': 200, 'msg': '添加成功'}}
        rest = request.json.get('data')
        food = Food()
        food.category = rest['category']
        food.name = rest['name']
        food.priced = decimal.Decimal(rest['priced'])
        food.price = decimal.Decimal(rest['price'])
        food.stock = int(rest['stock'])
        food.description = rest['description']
        food.imageName = rest['imageName']
        food.imageURL = rest['imageURL']
        food.status = 0  # status 0:未上架 1:已上架
        food.cover = 0  #是否设为封面
        food.month_count = 0  #月销售量
        food.total_count = 0  #总销售量
        food.view_count = 0  #总浏览量
        food.comment_count = 0  #总评论量
        food.updated_time = food.created_time = getCurrentTime()
        db.session.add(food)
        db.session.commit()
        return jsonify(response)


api.add_resource(AddFoods, '/vue/addfoods')
Exemplo n.º 2
0
            )
            db.session.add(model_bind)
            db.session.commit()

            bind_info = model_bind

        member_info = Member.query.filter_by(id=bind_info.member_id).first()
        # 产生token
        token = "%s#%s" % (MemberService.geneAuthCode(member_info),
                           member_info.id)
        resp['data'] = {'token': token}
        print(resp)
        return jsonify(resp)


api.add_resource(LoginWechat, '/wechat/login')


class CheckWechat(Resource):
    def post(self):
        resp = {'code': 200, 'msg': '操作成功', 'data': {}}
        req = request.values
        code = req['code'] if 'code' in req else ''
        if not code or len(code) < 1:
            resp['code'] = -1
            resp['msg'] = "需要code"
            return jsonify(resp)

        openid = MemberService.getWeChatOpenId(code)
        if openid is None:
            resp['code'] = -1
Exemplo n.º 3
0
        default_address = {
            "name": '萌太其',
            "mobile": "15730615013",
            "address": "重庆万州"
        }

        response['data']['food_list'] = data_food_list
        response['data']['pay_price'] = str(pay_price)
        response['data']['yun_price'] = str(yun_price)
        response['data']['total_price'] = str(pay_price + yun_price)
        response['data']['default_address'] = default_address

        return jsonify(response)


api.add_resource(OrderInfo, '/wechat/api/order/info')

# 订单提交


class OrderCreate(Resource):
    def post(self):
        response = {'code': 200, 'msg': '操作成功', 'data': {}}
        res = request.values
        type = res['type'] if 'type' in res else ''
        params_goods = res['goods'] if 'goods' in res else None

        items = []
        if params_goods:
            items = json.loads(params_goods)
Exemplo n.º 4
0
        # 响应信息
        response = {'meta': {'status': 200, 'msg': '上传成功'}, 'data': {}}
        files = request.files['file']
        key = str(uuid.uuid1()) + '-' + files.filename
        imageName = files.filename
        #生成上传token token失效时间
        token = q.upload_token(bucket_name, key, 3600)
        ret, info = put_data(token, key, files.read())
        # 上传后保存的文件名
        print('ret:', ret)
        print('info:', info)
        if info.status_code != 200:
            response['meta']['status'] = -1
            response['meta']['msg'] = '上传失败'
        response['data']['imageName'] = imageName
        QINIU_DOMAIN = app.config['QINIU_DOMAIN']
        response['data']['url'] = QINIU_DOMAIN + ret.get('key')
        # response['data']['url']='http://q5w0xd46n.bkt.clouddn.com/dcb7c128-5246-11ea-a95f-1063c844e2a2-avatar.png'
        print(response)
        return jsonify(response)

    def patch(self):
        res = request.json
        key = res['data']['key']
        # ret,info=bucket.delete(bucket_name,key)
        print(key)
        return jsonify(status=200)


api.add_resource(UploadImages, '/vue/upload')
Exemplo n.º 5
0
                    tmp_food_info = food_map[item.food_id]
                    pay_order_item_map[item.pay_order_id].append({
                        'id': item.id,
                        'food_id': item.food_id,
                        'quantity': item.quantity,
                        'price': str(item.price),
                        'pic_url': tmp_food_info.imageURL,
                        'name': tmp_food_info.name
                    })

            for item in pay_order_list:
                tmp_data = {
                    'status': item.pay_status,
                    'status_desc': item.status_desc,
                    'date': item.created_time.strftime("%Y-%m-%d %H:%M:%S"),
                    'order_number': item.order_number,
                    'order_sn': item.order_sn,
                    'note': item.note,
                    'total_price': str(item.total_price),
                    'goods_list': pay_order_item_map[item.id]
                }
                print(item.id)

                data_pay_order_list.append(tmp_data)

        response['data']['pay_order_list'] = data_pay_order_list
        return jsonify(response)


api.add_resource(MineOrders, '/wechat/api/mine/order')
Exemplo n.º 6
0
    def delete(self):
        print(request.values)
        res = request.values
        id = int(res['id'])
        sql = '''
        DELETE FROM members
        WHERE id={0}
        '''.format(id)
        result = db.engine.execute(sql)
        # r=dict((zip(result.keys(), result)))
        return jsonify(status=200)

    def patch(self):
        print('&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&')
        rest = request.json
        id = rest['data']['id']
        nickname = rest['data']['nickname']
        mobile = rest['data']['mobile']
        remain = rest['data']['remain']
        sql = '''
        UPDATE members
        SET nickname='{0}',mobile={1},remain={2}
        WHERE id={3}
        '''.format(nickname, mobile, remain, id)
        db.engine.execute(sql)
        return jsonify(status=200)


api.add_resource(Members, '/vue/member')
Exemplo n.º 7
0
        return jsonify(status=200)

    def get(self):
        sql = '''
        SELECT*
        FROM category
        '''
        result = db.engine.execute(sql)
        jsonData = list()
        for row in result:
            jsonData.append(to_json(Category, row))

        return jsonData


api.add_resource(Categorys, '/vue/category')


class Categories(Resource):
    def get(self):
        # 查询参数
        res = request.values
        query = res['query']
        pagenum = int(res['pagenum'])
        pagesize = int(res['pagesize'])
        ret = paginate(pagenum, pagesize)
        flag = True
        print('++++++++++++++++++++++++++++++++++++++++++++++++++')

        # query字符串为空
        if not query.strip():
Exemplo n.º 8
0
import json,requests
from flask import Flask,jsonify,Response
from flask import request,session,g
from fullstack import app,api,db
from flask_restful import Resource
from fullstack.Models.Member import Member
from fullstack.Models.ShareHistory import ShareHistory
from fullstack.utils import getCurrentTime


class MemberShares(Resource):
    def post(self):
        print('进来了')
        response={'code':200,'msg':'操作成功','data':{}}
        res=request.values
        url=res['url'] if 'url' in res else ''
        member_info=g.member_info
        print(g.member_info)
        share=ShareHistory()
        if member_info:
            share.member_id=member_info.id
        share.share_url=url
        share.created_time=getCurrentTime()
        db.session.add(share)
        db.session.commit()
        return jsonify(response)

api.add_resource(MemberShares,'/wechat/api/member/share')
Exemplo n.º 9
0
        # 轮播图选择
        bannerResult = Food.query.filter_by(status=1, cover=1).order_by(
            Food.total_count.desc()).limit(4).all()
        bannerList = list()
        if bannerResult:
            for item in bannerResult:
                temp = {'id': item.id, 'pic_url': item.imageURL}
                bannerList.append(temp)

        response['data']['categoryList'] = categoryList
        response['data']['bannerList'] = bannerList
        return jsonify(response)


api.add_resource(FoodIndex, '/wechat/food/index')


class FoodSearch(Resource):
    def get(self):
        response = {'code': 200, 'msg': '操作成功', 'data': {}}
        # 查询参数
        res = request.values
        category_name = res[
            'category_name'] if res['category_name'] != '全部' else ''
        match_search = res['match_search']
        p = int(res['p']) if 'p' in res else 1
        query = Food.query.filter_by(status=1)
        if p < 1:
            p = 1
Exemplo n.º 10
0
#             return jsonify(status=400)

class LoginVue(Resource):
    def post(self):
        print('请求登录')
        data=json.loads(request.data)
        username=data['username']
        password=data['password']
        session['username']=username
        # 设置session过期时间 一个月
        session.permanent=True
        # 查询数据库
        admin=Admin.query.first()        
        # 验证同户名和密码是否一致
        if admin.username==username and Admin.check_password(admin,password):
            return jsonify(status=200)
        else:
            return jsonify(status=400)
        

api.add_resource(LoginVue,'/login')

# 测试用
class Test(Resource):
    def get(self):
        sql="SELECT * FROM admin"
        result=db.engine.execute(sql)
        for row in result:
            app.logger.info(row)

api.add_resource(Test,'/test')