예제 #1
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, '密码错误')
예제 #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('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, "注册成功")
예제 #4
0
 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)
예제 #5
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, '新增成功')
예제 #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, '邮件通知商户失败,请重试')