Exemple #1
0
    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, '提交成功')
Exemple #2
0
    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, "密码错误")
Exemple #3
0
    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, '保存成功')
Exemple #4
0
    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, '未知错误')
Exemple #5
0
    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)
Exemple #6
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 == '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)
Exemple #7
0
    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))
Exemple #8
0
    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})
Exemple #9
0
    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, "注册成功")
Exemple #10
0
    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, '新增成功')
Exemple #11
0
    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})
Exemple #12
0
    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, '删除成功')
Exemple #13
0
    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, '操作成功')
Exemple #14
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('order_no', 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)

        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_at:
            return CommonUtil.json_response(-1, '订单已确认过')

        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, '确认成功,但是发货邮件未能送达,请联系买家')

        return CommonUtil.json_response(-1, '库存不足')
Exemple #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, '关闭成功')
Exemple #16
0
    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, '获取失败')
Exemple #17
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, '留言成功')
Exemple #18
0
    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)
Exemple #19
0
    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, '删除失败')
Exemple #20
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)
Exemple #21
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token')
        parser.add_argument('page', type=int, required=True)
        parser.add_argument('size', type=int, required=True)
        parser.add_argument('searchType')
        parser.add_argument('searchWords')
        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.searchType) and Valid.is_non_empty_str(
                args.searchWords):
            if args.searchType == 'username':
                users = DB.session.query(User).\
                    filter(User.username.like('%' + args.searchWords + '%')).\
                    order_by(User.create_at.desc()).\
                    limit(args.size).offset((args.page - 1) * args.size).\
                    all()
                count = DB.session.query(User).\
                    filter(User.username.like('%' + args.searchWords + '%')).\
                    count()
            elif args.searchType == 'nick_name':
                users = DB.session.query(User).\
                    filter(User.nick_name.like('%' + args.searchWords + '%')).\
                    order_by(User.create_at.desc()).\
                    limit(args.size).offset((args.page - 1) * args.size).\
                    all()
                count = DB.session.query(User).\
                    filter(User.nick_name.like('%' + args.searchWords + '%')).\
                    count()
            elif args.searchType == 'phone':
                users = DB.session.query(User).\
                    filter(User.phone.like('%' + args.searchWords + '%')).\
                    order_by(User.create_at.desc()).\
                    limit(args.size).offset((args.page - 1) * args.size).\
                    all()
                count = DB.session.query(User).\
                    filter(User.phone.like('%' + args.searchWords + '%')).\
                    count()
            elif args.searchType == 'email':
                users = DB.session.query(User).\
                    filter(User.email.like('%' + args.searchWords + '%')).\
                    order_by(User.create_at.desc()).\
                    limit(args.size).offset((args.page - 1) * args.size).\
                    all()
                count = DB.session.query(User).\
                    filter(User.email.like('%' + args.searchWords + '%')).\
                    count()
            else:
                users = None
                count = 0
        else:
            users = DB.session.query(User).\
                order_by(User.create_at.desc()).\
                limit(args.size).offset((args.page - 1) * args.size).\
                all()
            count = DB.session.query(User).count()

        dic = {
            'user_id': fields.String,
            'username': fields.String,
            'phone': fields.String,
            'email': fields.String,
            'expire_at': ConvertTimeStamp(),
            'last_login_ip': fields.String,
            'last_login_time': ConvertTimeStamp(),
            'real_name': fields.String,
            'id_card': fields.String,
            'address': fields.String,
            'create_at': ConvertTimeStamp(),
            'create_ip': fields.String,
            'nick_name': fields.String,
            'is_identity': fields.String,
            'avatar': fields.String,
            'sex': fields.String
        }

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

        return CommonUtil.json_response(0, '获取成功', data)
Exemple #22
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('productId', 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)

        product = DB.session.query(Product).filter(
            Product.record_id == args.productId).filter(
                Product.merchant_id == result.data.id).first()
        if product is None:
            if Valid.is_non_empty_str(
                    args.searchType) and Valid.is_non_empty_str(
                        args.searchWords):
                if args.searchType == 'content':
                    stocks = DB.session.query(ProductStock.record_id, ProductStock.content, ProductStock.create_at,
                                              ProductStock.sold_at, Product.name). \
                        join(Product). \
                        filter(Product.merchant_id == result.data.id). \
                        filter(Product.id == ProductStock.product_id). \
                        filter(ProductStock.content.like('%' + args.searchWords + '%')). \
                        order_by(ProductStock.create_at.desc()).limit(size).offset((page - 1) * size). \
                        all()
                    count = DB.session.query(ProductStock). \
                        join(Product). \
                        filter(Product.merchant_id == result.data.id). \
                        filter(Product.id == ProductStock.product_id). \
                        filter(ProductStock.content.like('%' + args.searchWords + '%')). \
                        count()
                    stocks = CommonUtil.sql_result_to_json(stocks)
            else:
                stocks = DB.session.query(ProductStock.record_id, ProductStock.content, ProductStock.create_at,
                                          ProductStock.sold_at, Product.name). \
                    join(Product). \
                    filter(Product.merchant_id == result.data.id). \
                    filter(Product.id == ProductStock.product_id). \
                    order_by(ProductStock.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(ProductStock). \
                    join(Product). \
                    filter(Product.merchant_id == result.data.id). \
                    filter(Product.id == ProductStock.product_id). \
                    count()
                stocks = CommonUtil.sql_result_to_json(stocks)
        else:
            if Valid.is_non_empty_str(
                    args.searchType) and Valid.is_non_empty_str(
                        args.searchWords):
                if args.searchType == 'content':
                    stocks = DB.session.query(ProductStock.record_id, ProductStock.content, ProductStock.create_at,
                                              ProductStock.sold_at, Product.name). \
                        join(Product). \
                        filter(Product.merchant_id == result.data.id). \
                        filter(ProductStock.product_id == product.id). \
                        filter(ProductStock.content.like('%' + args.searchWords + '%')). \
                        order_by(ProductStock.create_at.desc()).limit(size).offset((page - 1) * size). \
                        all()
                    count = DB.session.query(ProductStock). \
                        filter(Product.merchant_id == result.data.id). \
                        filter(ProductStock.product_id == product.id). \
                        filter(ProductStock.content.like('%' + args.searchWords + '%')). \
                        count()
                    stocks = CommonUtil.sql_result_to_json(stocks)
            else:
                stocks = DB.session.query(ProductStock.record_id, ProductStock.content, ProductStock.create_at,
                                          ProductStock.sold_at, Product.name). \
                    join(Product). \
                    filter(Product.merchant_id == result.data.id). \
                    filter(ProductStock.product_id == product.id). \
                    order_by(ProductStock.create_at.desc()).limit(size).offset((page - 1) * size). \
                    all()
                count = DB.session.query(ProductStock).\
                    filter(ProductStock.product_id == product.id). \
                    filter(Product.merchant_id == result.data.id). \
                    count()
                stocks = CommonUtil.sql_result_to_json(stocks)

        dic = {
            'stockId': fields.String(attribute='record_id'),
            'content': fields.String,
            'create_at': ConvertFormatTime(),
            'sold_at': ConvertFormatTime(),
            'order_no': fields.String,
            'product_name': fields.String(attribute='name')
        }

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

        return CommonUtil.json_response(0, '获取成功', data)
Exemple #23
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token', required=True)
        parser.add_argument('type', required=True, type=int)  # 0闪屏 1公告 2banner
        parser.add_argument('style', required=True, type=int)  # 0文字公告 1图片公告
        parser.add_argument('beginTime', required=True, dest='begin_time')
        parser.add_argument('endTime', required=True, dest='end_time')
        parser.add_argument('title', type=str)
        parser.add_argument('content', type=str)
        parser.add_argument('pic', type=str)
        parser.add_argument('record_id', type=str)
        parser.add_argument('remark', type=str)
        parser.add_argument('url', type=str)
        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 args.style == 0:
            if Valid.is_non_empty_str(args.title) is False or Valid.is_non_empty_str(args.content) is False:
                return CommonUtil.json_response(-1, '标题内容不能为空')
        elif Valid.is_non_empty_str(args.pic) is False:
            return CommonUtil.json_response(-1, '图片不能为空')

        begin_time = CommonUtil.time_to_timestamp(args.begin_time)
        end_time = CommonUtil.time_to_timestamp(args.end_time)

        if begin_time >= end_time:
            return CommonUtil.json_response(-1, '开始时间必须小于结束时间')

        if Valid.is_non_empty_str(args.record_id):  # 修改
            notice = DB.session.query(Notice).filter(Notice.record_id == args.record_id).filter(Notice.type == args.type).first()
            if notice is None:
                return CommonUtil.json_response(-1, '记录不存在')
            elif notice.enable is False:
                return CommonUtil.json_response(-1, '已下线不能编辑')
            elif notice.end_time < time.time():
                return CommonUtil.json_response(-1, '已过期不能编辑')

            notice.title = args.title
            notice.content = args.content
            notice.picture_url = args.pic
            notice.url = args.url
            notice.remark = args.remark
            notice.update_at = int(time.time())
            DB.session.commit()

            return CommonUtil.json_response(0, '修改成功')
        else:  # 新增
            # 闪屏、公告同一时段只能有一个
            if args.type == 0 or args.type == 1:
                is_exist = DB.session.query(Notice).filter(Notice.type == args.type).\
                    filter(begin_time <= Notice.end_time).filter(Notice.enable == 1).first()
                if is_exist:
                    return CommonUtil.json_response(-1, '该时段内还有未下线的闪屏公告')

            now = int(time.time())

            notice = Notice(
                type=args.type,
                title=args.title,
                content=args.content,
                picture_url=args.pic,
                url=args.url,
                begin_time=begin_time,
                end_time=end_time,
                remark=args.remark,
                create_at=now,
                update_at=now,
                record_id=CommonUtil.md5(now),
                enable=True
            )
            DB.session.add(notice)
            DB.session.commit()

            return CommonUtil.json_response(0, '新增成功')
Exemple #24
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('token')
        parser.add_argument('page', type=int, required=True)
        parser.add_argument('size', type=int, required=True)
        parser.add_argument('searchType')
        parser.add_argument('searchWords')
        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.searchType) and Valid.is_non_empty_str(
                args.searchWords):
            if args.searchType == 'username':
                boards = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                          User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(User.username.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    order_by(MessageBoard.create_at.desc()). \
                    limit(args.size).offset((args.page - 1) * args.size). \
                    all()
                boards = CommonUtil.sql_result_to_json(boards)
                count = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                         User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(User.username.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    count()
            elif args.searchType == 'nick_name':
                boards = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                          User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(User.nick_name.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    order_by(MessageBoard.create_at.desc()). \
                    limit(args.size).offset((args.page - 1) * args.size). \
                    all()
                boards = CommonUtil.sql_result_to_json(boards)
                count = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                         User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(User.nick_name.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    count()
            elif args.searchType == 'message':
                boards = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                          User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(MessageBoardMsg.message.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    order_by(MessageBoard.create_at.desc()). \
                    limit(args.size).offset((args.page - 1) * args.size). \
                    all()
                boards = CommonUtil.sql_result_to_json(boards)
                count = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                         User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                    join(User, MessageBoardMsg). \
                    filter(MessageBoard.user_id == User.id). \
                    filter(MessageBoardMsg.message.like('%' + args.searchWords + '%')). \
                    filter(MessageBoard.id == MessageBoardMsg.board_id). \
                    count()
            else:
                boards = None
                count = 0
        else:
            boards = DB.session.query(MessageBoard.record_id, MessageBoard.create_at, MessageBoard.close_at,
                                      User.username, User.nick_name, User.avatar, MessageBoardMsg.message). \
                join(User, MessageBoardMsg). \
                filter(MessageBoard.user_id == User.id). \
                filter(MessageBoard.id == MessageBoardMsg.board_id). \
                order_by(MessageBoard.create_at.desc()). \
                limit(args.size).offset((args.page - 1) * args.size). \
                all()
            boards = CommonUtil.sql_result_to_json(boards)
            count = DB.session.query(MessageBoard).count()

        dic = {
            'record_id': fields.String,
            'create_at': ConvertTimeStamp(),
            'close_at': ConvertTimeStamp(),
            'username': fields.String,
            'message': fields.String,
            'avatar': fields.String,
            'nick_name': fields.String
        }

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

        return CommonUtil.json_response(0, '获取成功', data)