예제 #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, '提交成功')
예제 #2
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, '未知错误')
예제 #3
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, '留言成功')
예제 #4
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, '新增成功')
예제 #5
0
    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, '用户已存在')
예제 #6
0
    def handle(self):
        parser = reqparse.RequestParser()
        parser.add_argument('productId', required=True)
        parser.add_argument('from_account', required=True)
        parser.add_argument('from_email', required=True)
        parser.add_argument('from_nickname', required=True)
        parser.add_argument('message', required=True)
        parser.add_argument('platform', required=True)
        args = parser.parse_args()

        product = DB.session.query(Product).filter(Product.record_id == args.productId).first()
        merchant = DB.session.query(Merchant).filter(Merchant.id == product.merchant_id).first()

        if product is None or merchant is None:
            return CommonUtil.json_response(-1, '商品查询失败')

        stock = DB.session.query(ProductStock).filter(ProductStock.product_id == product.id).first()
        if stock is None:
            return CommonUtil.json_response(-1, '商品库存不足')

        if product.is_on_sell == 0:
            return CommonUtil.json_response(-1, '商品已下架')

        if Valid.is_non_empty_str(args.from_account) is False:
            return CommonUtil.json_response(-1, '支付账号不能为空')

        if Valid.is_non_empty_str(args.from_email) is False:
            return CommonUtil.json_response(-1, '收货邮箱不能为空')

        secret_key = CommonUtil.md5(str(time.time()) + args.from_account + args.productId + 'secret_key')

        order_no = CommonUtil.md5(str(time.time()) + args.from_account + args.productId)

        if int(args.platform) == 0:
            payment = '支付宝'
        else:
            payment = '微信支付'

        email_head = '<div style="display:flex;justify-content:center"><div style="margin-top:40px;background-color:#fff;width:375px">'
        email_tail = '<div style="margin-top:20px;display:flex;justify-content:center"><a style="color:#fff;text-decoration:none;padding:0 10px;height:34px;background-color:#409EFF;text-align:center;line-height:34px;font-size:14px;border-radius:3px" href="%s">我已收到转账,点击确认收款</a></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>' % (
            Config.NOTIFY_ROOT_URL + '/confirm.html?secretkey=' + secret_key + '&orderno=' + order_no
        )
        email_order_no = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '订单号', order_no)
        email_time = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '提交时间', CommonUtil.timestamp_to_time(int(time.time())))
        email_payment = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '支付方式', payment)
        email_product_name = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '商品名称', product.name)
        email_product_price = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '商品价格', str(product.price / 100) + '元')
        email_account = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '支付账号', args.from_account)
        email_email = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '收货邮箱', args.from_email)
        email_nickname = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '支付昵称', args.from_nickname)
        email_message = '<div style="background-color:#fafaf8;border-bottom:1px solid #e6e6e6;display:flex;justify-content:space-between;padding:10px 10px"><span style="color:#333;font-size:14px">%s</span> <span style="color:#333;font-size:14px">%s</span></div>' % (
            '买家留言', args.message)

        info = '%s%s%s%s%s%s%s%s%s%s%s' % (email_head, email_order_no, email_time, email_payment, email_product_name, email_product_price, email_account, email_email, email_nickname, email_message, email_tail)

        result = EmailUtil.send_html_email('收到新的商品订单,买家正在付款中~', info, merchant.email)

        if result is True:
            order = Order(
                merchant_id=merchant.id,
                product_id=product.id,
                order_no=order_no,
                platform=args.platform,
                create_at=CommonUtil.time_format_str(),
                cost=product.price,
                from_account=args.from_account,
                from_nickname=args.from_nickname,
                from_email=args.from_email,
                message=args.message,
                confirm_secret_key=secret_key
            )

            DB.session.add(order)
            DB.session.commit()

            return CommonUtil.json_response(0, '下单成功')
        else:
            return CommonUtil.json_response(-1, '邮件通知商户失败,请重试')
예제 #7
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, '新增成功')