コード例 #1
0
ファイル: merchant.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('email', required=True)
        parser.add_argument('online_from', required=True)
        parser.add_argument('online_to', required=True)
        parser.add_argument('alipay_name', required=True)
        parser.add_argument('alipay_account', required=True)
        parser.add_argument('wechat_name', required=True)
        parser.add_argument('wechat_account', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        if Valid.is_non_empty_str(args.email) is False:
            return CommonUtil.json_response(-1, '确认邮箱不能为空')

        merchant = DB.session.query(Merchant).filter(
            Merchant.id == result.data.id).first()
        merchant.email = args.email
        merchant.online_from = args.online_from
        merchant.online_to = args.online_to
        merchant.alipay_name = args.alipay_name
        merchant.alipay_account = args.alipay_account
        merchant.wechat_name = args.wechat_name
        merchant.wechat_account = args.wechat_account

        DB.session.commit()

        return CommonUtil.json_response(0, '保存成功')
コード例 #2
0
ファイル: common.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('type')
        args = parser.parse_args()

        usage = ''
        if args.type is None:
            return CommonUtil.json_response(-1, '缺少参数:type')
        elif args.type == '0':
            usage = 'regAccount'  # 注册账号
        elif args.type == '1':
            usage = 'findPassword'  # 找回密码
        elif args.type == '2':
            usage = 'adminLogin'  # 管理台登录
        else:
            return CommonUtil.json_response(-1, 'type参数格式错误')

        # 用客户端ip来作为sendId是为了使频繁请求时可以替换这个key下面原来的验证码
        md5 = hashlib.md5()
        md5.update("validimage_{}_{}".format(request.environ['REMOTE_ADDR'],
                                             usage).encode('utf-8'))
        sendId = md5.hexdigest()
        validImage = ValidImage.create()

        Redis.setex(sendId, 60, validImage['code'])

        data = {"img": validImage['img'], "sendId": sendId}

        Logger.log("生成图片验证码 ip:{} sendId:{} code:{}".format(
            request.environ['REMOTE_ADDR'], sendId, validImage['code']))

        return CommonUtil.json_response(0, "success", data)
コード例 #3
0
ファイル: merchant.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        merchant = DB.session.query(Merchant).filter(
            Merchant.id == result.data.id).first()

        dic = {
            'email': fields.String,
            'online_from': fields.String,
            'online_to': fields.String,
            'alipay_name': fields.String,
            'alipay_account': fields.String,
            'wechat_name': fields.String,
            'wechat_account': fields.String
        }

        result = marshal(merchant, dic)
        result['mch_url'] = Config.NOTIFY_ROOT_URL + '/buy.html?mch=' + str(
            merchant.merchant_no)

        return CommonUtil.json_response(0, '获取成功', result)
コード例 #4
0
ファイル: product.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('name', required=True)
        parser.add_argument('desc', required=True)
        parser.add_argument('price', required=True)
        parser.add_argument('alipay_qrcode', required=True)
        parser.add_argument('wechat_qrcode', required=True)
        parser.add_argument('productId', required=True)
        parser.add_argument('is_on_sell', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        if Valid.is_non_empty_str(args.name) is False:
            return CommonUtil.json_response(-1, '商品名称不能为空')

        if Valid.is_non_empty_str(args.price) is False:
            return CommonUtil.json_response(-1, '商品单价不能为空')

        if len(args.productId) == 0:
            product = DB.session.query(Product).filter(
                Product.name == args.name).filter(
                    Product.merchant_id == result.data.id).first()
            if product:
                return CommonUtil.json_response(-1, '商品名称已存在')

            product = Product(merchant_id=result.data.id,
                              record_id=CommonUtil.md5(args.name + args.token +
                                                       str(time.time())),
                              name=args.name,
                              desc=args.desc,
                              price=args.price,
                              is_on_sell='1',
                              create_at=CommonUtil.time_format_str(),
                              alipay_qrcode=args.alipay_qrcode,
                              wechat_qrcode=args.wechat_qrcode)
            DB.session.add(product)
            DB.session.commit()

            return CommonUtil.json_response(0, '新增成功')
        else:
            product = DB.session.query(Product).filter(
                Product.record_id == args.productId).filter(
                    Product.merchant_id == result.data.id).first()
            if product:
                product.price = args.price
                product.desc = args.desc
                product.alipay_qrcode = args.alipay_qrcode
                product.wechat_qrcode = args.wechat_qrcode
                product.is_on_sell = args.is_on_sell

                DB.session.commit()

                return CommonUtil.json_response(0, '修改成功')

        return CommonUtil.json_response(-1, '未知错误')
コード例 #5
0
ファイル: product.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('page', required=True)
        parser.add_argument('size', required=True)
        parser.add_argument('searchType')
        parser.add_argument('searchWords')
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        page = int(args.page)
        size = int(args.size)

        if Valid.is_non_empty_str(args.searchType) and Valid.is_non_empty_str(
                args.searchWords):
            if args.searchType == 'product_name':
                products = DB.session.query(Product). \
                    filter(Product.merchant_id == result.data.id). \
                    filter(Product.name.like('%' + args.searchWords + '%')). \
                    order_by(Product.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(Product).\
                    filter(Product.merchant_id == result.data.id). \
                    filter(Product.name.like('%' + args.searchWords + '%')). \
                    count()
        else:
            products = DB.session.query(Product). \
                filter(Product.merchant_id == result.data.id). \
                order_by(Product.create_at.desc()).limit(size).offset((page - 1) * size). \
                all()
            count = DB.session.query(Product).filter(
                Product.merchant_id == result.data.id).count()

        dic = {
            'productId': fields.String(attribute='record_id'),
            'create_at': ConvertFormatTime(),
            'is_on_sell': fields.Integer,
            'name': fields.String,
            'desc': fields.String,
            'price': fields.String,
            'alipay_qrcode': fields.String,
            'wechat_qrcode': fields.String
        }

        data = {'list': marshal(products, dic), 'totalCount': math.ceil(count)}

        return CommonUtil.json_response(0, '获取成功', data)
コード例 #6
0
ファイル: message.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token')
        parser.add_argument('record_id', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_admin_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        board = DB.session.query(MessageBoard).\
            filter(MessageBoard.record_id == args.record_id).\
            first()
        if board is None:
            return CommonUtil.json_response(-1, '记录不存在')

        # 用户留言
        user_msgs = DB.session.query(MessageBoardMsg.message_id, MessageBoardMsg.message, MessageBoardMsg.create_at,
                                MessageBoardMsg.is_admin, User.username, User.avatar).\
            join(User). \
            filter(MessageBoardMsg.board_id == board.id).\
            order_by(MessageBoardMsg.create_at.desc()).\
            all()
        user_msgs = CommonUtil.sql_result_to_json(user_msgs)

        # 管理呐留言,因为没有user_id,所以分两次查询
        admin_msgs = DB.session.query(MessageBoardMsg.message_id, MessageBoardMsg.message, MessageBoardMsg.create_at,
                         MessageBoardMsg.is_admin). \
            filter(MessageBoardMsg.is_admin == 1). \
            filter(MessageBoardMsg.board_id == board.id). \
            order_by(MessageBoardMsg.create_at.desc()). \
            all()
        admin_msgs = CommonUtil.sql_result_to_json(admin_msgs)

        msgs = user_msgs + admin_msgs
        # 排序
        msgs = sorted(msgs, key=lambda x: x['create_at'])

        dic = {
            'message_id': fields.String,
            'message': fields.String,
            'create_at': ConvertTimeStamp(),
            'is_admin': fields.Integer,
            'username': ConvertEmptyStr(),
            'avatar': ConvertEmptyStr,
        }

        return CommonUtil.json_response(0, '获取成功', marshal(msgs, dic))
コード例 #7
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('secret_key', required=True)
        parser.add_argument('order_no', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        order = DB.session.query(Order).filter(
            Order.order_no == args.order_no).first()
        if order is None:
            return CommonUtil.json_response(-1, '订单不存在')

        if order.confirm_secret_key != args.secret_key:
            return CommonUtil.json_response(-1, '订单密钥错误')

        if order.confirm_at:
            return CommonUtil.json_response(-1, '订单已确认过')

        merchant = DB.session.query(Merchant).filter(
            Merchant.id == order.merchant_id).first()
        # 二次密码核对
        if merchant and merchant.password == CommonUtil.create_user_password(
                merchant.username, args.password):
            stock = DB.session.query(ProductStock).\
                filter(order.product_id == ProductStock.product_id).\
                filter(ProductStock.sold_at == None). \
                first()
            if stock:
                stock.sold_at = CommonUtil.time_format_str()
                stock.order_id = order.id
                DB.session.commit()

                order.confirm_at = CommonUtil.time_format_str()
                DB.session.commit()

                info = '<div style="display:flex;justify-content:center"><div style="width:375px"><div><p style="color:#000;font-size:40px;font-weight:700">“</p><p style="color:#333;font-size:14px;line-height:20px;letter-spacing:2px">%s</p><p style="color:#000;font-size:40px;font-weight:700;text-align:right">”</p></div><div style="margin-top:140px;display:flex;justify-content:center"><span style="color:#999;font-size:10px">Copyright@2018 51shuaba.xyz All Rights Reseved.</span></div></div></div>' % (
                    stock.content)

                result = EmailUtil.send_html_email(
                    '订单' + args.order_no + '发货通知', info, order.from_email)

                if result is True:
                    return CommonUtil.json_response(0, '确认成功,已邮件通知买家')
                else:
                    return CommonUtil.json_response(0, '确认成功,但是发货邮件未能送达,请联系买家')
            else:
                return CommonUtil.json_response(-1, '库存不足')

        return CommonUtil.json_response(-1, '密码错误')
コード例 #8
0
ファイル: common.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        cred = CredInfo(1252137158, u'密钥', u'密钥')
        auth_obj = Auth(cred)
        sign_str = auth_obj.sign_more(u'bucket', u'/文件夹/',
                                      int(time.time()) + 60)
        return CommonUtil.json_response(0, '获取成功', {'sign': sign_str})
コード例 #9
0
ファイル: common.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_admin_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        cred = CredInfo(Config.QCLOUD_COS_APP_ID, Config.QCLOUD_COS_SECRET_ID,
                        Config.QCLOUD_COS_SECRET_KEY)
        auth_obj = Auth(cred)
        sign_str = auth_obj.sign_more(Config.QCLOUD_COS_BUCKET,
                                      Config.QCLOUD_COS_DIR_PATH,
                                      int(time.time()) + 60)
        return CommonUtil.json_response(0, '获取成功', {'sign': sign_str})
コード例 #10
0
    def handle(self):
        now = int(time.time())
        # 已经开始 还未结束 上线中
        notice = DB.session.query(Notice).filter(Notice.type == 2).filter(Notice.begin_time < now). \
            filter(Notice.end_time > now).filter(Notice.enable == 1).all()

        if notice is None:
            return CommonUtil.json_response(0, '获取成功', [])

        dic = {
            'record_id': fields.String,
            'remark': fields.String,
            'picture_url': fields.String,
            'url': fields.String
        }

        return CommonUtil.json_response(0, '获取成功',
                                        {"list": marshal(notice, dic)})
コード例 #11
0
def get_luanch_notice(notice_type):
    now = int(time.time())
    # 已经开始 还未结束 上线中
    notice = DB.session.query(Notice).filter(Notice.type == notice_type).filter(Notice.begin_time < now). \
        filter(Notice.end_time > now).filter(Notice.enable == 1).first()

    if notice is None:
        return CommonUtil.json_response(-1, '获取失败')

    dic = {
        'record_id': fields.String,
        'title': fields.String,
        'content': fields.String,
        'picture_url': fields.String,
        'url': fields.String
    }

    return CommonUtil.json_response(0, '获取成功', marshal(notice, dic))
コード例 #12
0
ファイル: product.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('productId', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        DB.session.query(Product).\
            filter(Product.record_id == args.productId).\
            filter(Product.merchant_id == result.data.id).\
            delete()
        DB.session.commit()

        return CommonUtil.json_response(0, '删除成功')
コード例 #13
0
ファイル: notice.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('record_id', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_admin_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        notice = DB.session.query(Notice).filter(Notice.record_id == args.record_id).first()
        if notice.enable is False:
            return CommonUtil.json_response(-1, '已经是下线状态')
        else:
            notice.enable = False
            DB.session.commit()

            return CommonUtil.json_response(0, '操作成功')
コード例 #14
0
ファイル: merchant.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        parser.add_argument('password2', required=True)
        parser.add_argument('validId', required=True)
        parser.add_argument('validValue', required=True)
        args = parser.parse_args()

        # 效验验证码
        result = CheckUtil.check_valid_image(args.validId, args.validValue)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        if Valid.is_username(args.username) is None:
            return CommonUtil.json_response(-1, "用户名必须是6-16位英文或数字")

        if Valid.is_password(args.password) is None:
            return CommonUtil.json_response(-1, "密码必须是6-16位英文或数字")

        if args.password != args.password2:
            return CommonUtil.json_response(-1, "两次密码不一致")

        merchant = DB.session.query(Merchant).filter(
            Merchant.username == args.username).first()
        if merchant:
            return CommonUtil.json_response(-1, "用户名已存在")

        # 生成唯一的商户id
        merchant_no = None
        while merchant_no is None:
            random_id = CommonUtil.random_id()
            merchant = DB.session.query(Merchant).filter(
                Merchant.merchant_no == random_id).first()
            if merchant is None:
                merchant_no = random_id

        merchant = Merchant(merchant_no=merchant_no,
                            username=args.username,
                            password=CommonUtil.create_user_password(
                                args.username, args.password),
                            create_at=CommonUtil.time_format_str(),
                            create_ip=request.environ['REMOTE_ADDR'],
                            is_frozen=0)
        DB.session.add(merchant)
        DB.session.commit()
        return CommonUtil.json_response(0, "注册成功")
コード例 #15
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('record_id')
        args = parser.parse_args()

        # 效验token
        res = CheckUtil.check_user_token(args.token)
        if res.code != 0:
            return CommonUtil.json_response(res.code, res.message)

        board = DB.session.query(MessageBoard).filter(
            MessageBoard.record_id == args.record_id).first()
        if board is None:
            return CommonUtil.json_response(-1, '留言记录不存在')

        board.close_at = int(time.time())
        DB.session.commit()

        return CommonUtil.json_response(0, '关闭成功')
コード例 #16
0
ファイル: product.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('stockId', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        stock = DB.session.query(ProductStock).filter(
            ProductStock.record_id == args.stockId).first()
        order = DB.session.query(Order).filter(
            Order.id == stock.order_id).first()
        if stock and order:
            return CommonUtil.json_response(0, '获取成功',
                                            {'order_no': order.order_no})
        else:
            return CommonUtil.json_response(-1, '获取失败')
コード例 #17
0
ファイル: user.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        user = DB.session.query(User).filter(
            User.username == args.username).first()
        if user is None:
            return CommonUtil.json_response(-1, "用户不存在")

        if user.password == CommonUtil.create_user_password(
                args.username, args.password):
            # 生成新token
            user.token = CommonUtil.create_user_token(args.username)
            DB.session.commit()

            user = DB.session.query(User).filter(
                User.username == args.username).first()
            dic = {
                'token': fields.String,
                'user_id': fields.String,
                'username': fields.String,
                'phone': fields.String,
                'email': fields.String,
                'expire_at': fields.String,
                'last_login_ip': fields.String,
                'last_login_time': fields.String,
                'real_name': fields.String,
                'id_card': fields.String,
                'address': fields.String,
                'create_at': fields.String,
                'nike_name': fields.String,
                'is_identity': fields.String,
                'avatar': fields.String,
                'sex': fields.String
            }

            return CommonUtil.json_response(0, "登录成功", marshal(user, dic))
        else:
            return CommonUtil.json_response(-1, "密码错误")
コード例 #18
0
ファイル: merchant.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        merchant = DB.session.query(Merchant).filter(
            Merchant.username == args.username).first()
        if merchant is None:
            return CommonUtil.json_response(-1, "用户名不存在")

        if merchant.password == CommonUtil.create_user_password(
                args.username, args.password):
            # 生成新token
            merchant.token = CommonUtil.create_admin_token(args.username)
            DB.session.commit()

            merchant = DB.session.query(Merchant).filter(
                Merchant.username == args.username).first()
            dic = {'token': fields.String}

            return CommonUtil.json_response(0, "登录成功", marshal(merchant, dic))
        else:
            print(merchant.password)
            print(CommonUtil.create_user_password(args.username,
                                                  args.password))
            return CommonUtil.json_response(-1, "密码错误")
コード例 #19
0
ファイル: admin.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        parser.add_argument('validId', required=True)
        parser.add_argument('validValue', required=True)
        args = parser.parse_args()

        # 效验验证码
        result = CheckUtil.check_valid_image(args.validId, args.validValue)
        if result.code != 0:
            CommonUtil.json_response(result.code, result.message)

        admin = DB.session.query(Admin).filter(Admin.username == args.username).first()
        if admin is None:
            return CommonUtil.json_response(-1, "账号不存在")

        if admin.password == args.password:
            # 生成新token
            admin.token = CommonUtil.create_admin_token(args.username)
            DB.session.commit()

            admin = DB.session.query(Admin).filter(Admin.username == args.username).first()
            dic = {
                'token': fields.String
            }

            return CommonUtil.json_response(0, "登录成功", marshal(admin, dic))
        else:
            return CommonUtil.json_response(-1, "密码错误")
コード例 #20
0
ファイル: message.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token')
        parser.add_argument('record_id', required=True)
        parser.add_argument('message', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_admin_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        if Valid.is_non_empty_str(args.message) is False:
            return CommonUtil.json_response(-1, '回复内容不能为空')

        board = DB.session.query(MessageBoard). \
            filter(MessageBoard.record_id == args.record_id). \
            first()
        if board is None:
            return CommonUtil.json_response(-1, '记录不存在')
        elif board.close_at is not None:
            return CommonUtil.json_response(-1, '已结单不能再回复了')

        msg = MessageBoardMsg(
            board_id=board.id,
            message_id=CommonUtil.md5(str(time.time()) + 'admin'),
            message=args.message,
            create_at=int(time.time()),
            is_admin=True)

        DB.session.add(msg)
        DB.session.commit()

        return CommonUtil.json_response(0, '提交成功')
コード例 #21
0
ファイル: user.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        user = DB.session.query(User).filter(
            User.username == args.username).first()
        if user is None:

            now = int(time.time())

            user = User(user_id=CommonUtil.md5(now),
                        username=args.username,
                        password=CommonUtil.create_user_password(
                            args.username, args.password))
            DB.session.add(user)
            DB.session.commit()

            return CommonUtil.json_response(0, '注册成功')
        else:
            return CommonUtil.json_response(-1, '用户已存在')
コード例 #22
0
ファイル: notice.py プロジェクト: HJaycee/app_admin_api
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('type', required=True)
        parser.add_argument('page', type=int, required=True)
        parser.add_argument('size', type=int, required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_admin_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        notices = DB.session.query(Notice).filter(Notice.type == args.type).order_by(Notice.create_at.desc())\
            .limit(args.size).offset((args.page - 1) * args.size).all()
        count = DB.session.query(Notice).filter(Notice.type == args.type).count()

        dic = {
            'title': fields.String,
            'content': fields.String,
            'create_at': ConvertTimeStamp(),
            'type': fields.Integer,
            'update_at': ConvertTimeStamp(),
            'record_id': fields.String,
            'picture_url': fields.String,
            'begin_time': ConvertTimeStamp,
            'end_time': ConvertTimeStamp,
            'enable': fields.Integer,
            'url': fields.String,
            'remark': fields.String
        }

        data = {
            'list': marshal(notices, dic),
            'totalCount': math.ceil(count)
        }

        return CommonUtil.json_response(0, '获取成功', data)
コード例 #23
0
    def handle(self):
        config = DB.session.query(AppConfig).first()
        dic = {
            'ios_ver': fields.String,
            'ios_force_update': fields.Boolean,
            'ios_update_url': fields.String,
            'ios_update_content': fields.String,
            'ios': fields.Integer(attribute='ios_review'),
            'android_ver': fields.String,
            'android_force_update': fields.Boolean,
            'android_update_url': fields.String,
            'android_update_content': fields.String
        }

        return CommonUtil.json_response(0, '获取成功', marshal(config, dic))
コード例 #24
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('mch', required=True)
        args = parser.parse_args()

        merchant = DB.session.query(Merchant).filter(Merchant.merchant_no == args.mch).first()
        if merchant is None:
            return CommonUtil.json_response(-1, '商户不存在')

        products = DB.session.query(Product).join(Merchant).filter(Product.merchant_id == merchant.id).order_by(Product.create_at.desc()).all()

        dic = {
            'productId': fields.String(attribute='record_id'),
            'is_on_sell': fields.Integer,
            'name': fields.String,
            'desc': fields.String,
            'price': fields.String,
            'alipay_qrcode': fields.String,
            'wechat_qrcode': fields.String
        }

        mch_dic = {
            'online_from': fields.String,
            'online_to': fields.String,
            'alipay_name': fields.String,
            'alipay_account': fields.String,
            'wechat_name': fields.String,
            'wechat_account': fields.String
        }

        data = {
            'list': marshal(products, dic),
            'mch': marshal(merchant, mch_dic)
        }

        return CommonUtil.json_response(0, '获取成功', data)
コード例 #25
0
ファイル: product.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('stockId', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        stock = DB.session.query(ProductStock).filter(
            ProductStock.record_id == args.stockId).first()
        if stock:
            product = DB.session.query(Product).filter(
                Product.id == stock.product_id).filter(
                    Product.merchant_id == result.data.id).first()
            if product:
                DB.session.query(ProductStock).filter(
                    ProductStock.record_id == args.stockId).delete()
                DB.session.commit()
                return CommonUtil.json_response(0, '删除成功')

        return CommonUtil.json_response(-1, '删除失败')
コード例 #26
0
ファイル: checkUtil.py プロジェクト: yucz/PersonalPay
 def check_merchant_token(cls, token):
     if token is None:
         return Response(1001, '身份信息不存在')
     else:
         admin = DB.session.query(Merchant).filter(
             Merchant.token == token).first()
         if admin is None:
             return Response(1001, '请登录')
         elif admin.token != token:
             return Response(1001, '身份信息已过期')
         elif admin.is_frozen == 1:
             return Response(1001, '账号异常')
         else:
             admin.login_at = CommonUtil.time_format_str()
             admin.login_ip = request.environ['REMOTE_ADDR']
             DB.session.commit()
             return Response(0, '', admin)
コード例 #27
0
ファイル: product.py プロジェクト: yucz/PersonalPay
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('productId', required=True)
        parser.add_argument('content', required=True)
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        if Valid.is_non_empty_str(args.content) is False:
            return CommonUtil.json_response(-1, '内容不能为空')

        product = DB.session.query(Product).filter(
            Product.record_id == args.productId).filter(
                Product.merchant_id == result.data.id).first()
        if product is None:
            return CommonUtil.json_response(-1, '商品不存在')
        if product.is_on_sell == 0:
            return CommonUtil.json_response(-1, '商品已下架')

        contents = args.content.split('#separator#')
        create_at = CommonUtil.time_format_str()

        for index in range(len(contents)):
            content = contents[index]
            # 去首尾回车
            if len(content) > 2:
                if content[:1] == '\n':
                    content = content[1:]
            if len(content) > 2:
                if content[-1:] == '\n':
                    content = content[:-1]
            if len(content) > 0 and content != '\n':
                productStock = ProductStock(
                    product_id=product.id,
                    record_id=CommonUtil.md5(args.productId + args.token +
                                             create_at + str(index)),
                    content=content,
                    create_at=create_at)
                DB.session.add(productStock)
        DB.session.commit()

        return CommonUtil.json_response(0, '新增成功')
コード例 #28
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('record_id')  # 如果是新增record_id传空
        parser.add_argument('message', required=True, type=str)
        args = parser.parse_args()

        # 效验token
        res = CheckUtil.check_user_token(args.token)
        if res.code != 0:
            return CommonUtil.json_response(res.code, res.message)
        user = res.data

        if Valid.is_non_empty_str(args.message) is False:
            return CommonUtil.json_response(-1, '内容不能为空')

        if Valid.is_non_empty_str(args.record_id) is False:
            board = MessageBoard(record_id=CommonUtil.md5(
                str(time.time()) + 'msg_board' + args.token),
                                 create_at=int(time.time()),
                                 user_id=user.id)
            DB.session.add(board)
            DB.session.commit()
        else:
            board = DB.session.query(MessageBoard).filter(
                MessageBoard.record_id == args.record_id).first()
            if board is None:
                return CommonUtil.json_response(-1, '留言记录不存在')

        msg = MessageBoardMsg(
            board_id=board.id,
            message_id=CommonUtil.md5(str(time.time()) + 'msg' + args.token),
            user_id=user.id,
            message=args.message,
            create_at=int(time.time()),
            is_admin=False)

        DB.session.add(msg)
        DB.session.commit()

        return CommonUtil.json_response(0, '留言成功')
コード例 #29
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('page', required=True)
        parser.add_argument('size', required=True)
        parser.add_argument('searchType')
        parser.add_argument('searchWords')
        args = parser.parse_args()

        # 效验token
        result = CheckUtil.check_merchant_token(args.token)
        if result.code != 0:
            return CommonUtil.json_response(result.code, result.message)

        page = int(args.page)
        size = int(args.size)

        if Valid.is_non_empty_str(args.searchType) and Valid.is_non_empty_str(
                args.searchWords):
            if args.searchType == 'order_no':
                orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                    join(Product) .\
                    filter(Product.id == Order.product_id) .\
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.order_no.like('%' + args.searchWords + '%')). \
                    order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size).\
                    all()
                count = DB.session.query(Order).\
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.order_no.like('%' + args.searchWords + '%')). \
                    count()
                orders = CommonUtil.sql_result_to_json(orders)
            elif args.searchType == 'from_account':
                orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                    join(Product) .\
                    filter(Product.id == Order.product_id) .\
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.from_account.like('%' + args.searchWords + '%')). \
                    order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(Order). \
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.from_account.like('%' + args.searchWords + '%')). \
                    count()
                orders = CommonUtil.sql_result_to_json(orders)
            elif args.searchType == 'from_email':
                orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                    join(Product) .\
                    filter(Product.id == Order.product_id) .\
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.from_email.like('%' + args.searchWords + '%')). \
                    order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(Order). \
                    filter(Order.merchant_id == result.data.id). \
                    filter(Order.from_email.like('%' + args.searchWords + '%')). \
                    count()
                orders = CommonUtil.sql_result_to_json(orders)
            else:
                orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                    join(Product) .\
                    filter(Product.id == Order.product_id) .\
                    filter(Order.merchant_id == result.data.id). \
                    order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size).all()
                count = DB.session.query(Order). \
                    filter(Order.merchant_id == result.data.id). \
                    count()
                orders = CommonUtil.sql_result_to_json(orders)
        else:
            orders = DB.session.query(Order.order_no, Order.platform_order_no, Order.platform, Order.create_at,
                                      Order.confirm_at, Order.cost, Order.from_account, Order.from_email,
                                      Order.from_nickname, Order.message, Product.name, Product.record_id).\
                join(Product) .\
                filter(Product.id == Order.product_id) .\
                filter(Order.merchant_id == result.data.id). \
                order_by(Order.create_at.desc()).limit(size).offset((page - 1) * size).all()
            count = DB.session.query(Order).\
                filter(Order.merchant_id == result.data.id).\
                count()
            orders = CommonUtil.sql_result_to_json(orders)

        dic = {
            'order_no': fields.String,
            'platform_order_no': fields.String,
            'platform': fields.Integer,
            'create_at': ConvertFormatTime(),
            'confirm_at': ConvertFormatTime(),
            'cost': fields.String,
            'from_account': fields.String,
            'from_email': fields.String,
            'from_nickname': fields.String,
            'message': fields.String,
            'product_name': fields.String(attribute='name'),
            'productId': fields.String(attribute='record_id')
        }

        data = {'list': marshal(orders, dic), 'totalCount': math.ceil(count)}

        return CommonUtil.json_response(0, '获取成功', data)
コード例 #30
0
 def format(self, value):
     ret = CommonUtil.timestamp_to_time(value)
     if ret is None:
         return ''
     else:
         return ret