Пример #1
0
def recharge_save():
    """充值"""

    admin_uid = session.get('admin_uid', None)
    if not admin_uid:
        return_url = request.args.get('return_url', '/admin/dashboard')
        return redirect(url_for('admin.auth.login', return_url=return_url))

    form = RechargeForm(request.form)
    form.avatar.data = request.args.get('avatar')

    if not form.validate_on_submit():
        return render_template('admin/user/recharge.html.j2', form=form)

    recharge_amount = Decimal(form.recharge_amount.data).quantize(
        Decimal('0.00'))
    remark_user = _(u'充值成功')
    remark_sys = _(u'充值: 订单ID:%s, 充值方式:%s, 充值金额:%s' %
                   (u"无", u"管理员打款", recharge_amount))
    fs = FundsService(form.uid.data, recharge_amount, 1, 2, 0, remark_user,
                      remark_sys, current_timestamp())
    if not fs.check():
        log_error(
            '[ErrorServiceApiOrderPaidServicePaid][FundsServiceError01]  remark_sys:%s'
            % remark_sys)
        return redirect(url_for('admin.user.recharge', form=form))
    # 更新余额 - 充值
    fs.update()
    fs.commit()

    return redirect(url_for('admin.user.detail', uid=form.uid.data))
Пример #2
0
    def __init__(self, uid, order_id, ua_id, shipping_id=0, coupon_id=0):
        """初始化更新订单服务"""

        self.uid = uid  # 购买人
        self.order_id = order_id  # 订单ID
        self.ua_id = ua_id  # 收货地址ID
        self.shipping_id = shipping_id  # 配送方式ID
        self.coupon_id = coupon_id  # 优惠券ID
        self.current_time = current_timestamp()  # 当前时间

        self.order = None  # 订单实例
        self.shipping_address = None  # 收货地址实例
        self.order_address = None  # 已用订单地址实例
        self.shipping = None  # 配送方式实例
        self.coupon = None  # 优惠券实例
        self._coupon = None   # 已用优惠券实例
        self.items_amount = Decimal('0.00')  # 订单商品总金额
        self.shipping_amount = Decimal('0.00')   # 快递费用
        # 订单金额: items_amount + shipping_amount
        self.order_amount = Decimal('0.00')
        self.discount_amount = Decimal('0.00')  # 订单优惠金额: 使用优惠券等优惠金额
        # 订单应付金额: order_amount - discount_amount
        self.pay_amount = Decimal('0.00')

        # 是否检查
        self.__is_check_order = False
        self.__is_check_shipping_address = False
        self.__is_check_shipping = False
        self.__is_check_coupon = False
        self.__is_check = False
Пример #3
0
def sms_code():
    """获取短信验证码"""
    resjson.action_code = 10

    mobile = request.form.get('mobile', '').strip()
    log_info(mobile)
    if not mobile:
        return resjson.print_json(11, _(u'请输入手机号'))

    if len(mobile) != 11:
        return resjson.print_json(12, _(u'请输入正确的手机号'))

    # 随机生成4位验证码,并session保存
    code = randomstr(4, 1)
    expire_time = current_timestamp() + 300
    sms = SmsServiceFactory.get_smsservice()
    try:
        sms.send_sms_code(mobile, code)
        # 本地缓存
        session['code_expire_time'] = expire_time
        session['code'] = code
        session['code_mobile'] = mobile
    except SmsException as e:
        log_info(e.msg)
        return resjson.print_json(12, _(u'获取验证码失败'))

    return resjson.print_json(0, u'ok')
Пример #4
0
def forget_password():
    """忘记密码"""

    args = request.args
    mobile = args.get('mobile', '')
    code = args.get('code', '')
    password = args.get('password1', '')

    current_time = current_timestamp()
    ucc = UserCheckCode.query.filter(UserCheckCode.mobile == mobile).\
                filter(UserCheckCode.check_code == code).\
                filter(UserCheckCode.check_type == 2).\
                order_by(UserCheckCode.ucc_id.desc()).first()
    if ucc is None:
        return u'验证码错误'

    if ucc.expire_time < current_time:
        return u'验证码已经过期,请重新获取'

    user = User.query.filter(User.mobile == mobile).first()
    if user is None:
        return u'{mobile}帐号不存在'.format(mobile=mobile)

    up = UserPassword.query.filter(UserPassword.uid == user.uid).first()
    password = sha256(password).hexdigest()
    password = sha256(password + up.salt).hexdigest()
    up.password = password
    db.session.commit()

    return u'ok'
Пример #5
0
def update():
    """更新个人资料"""
    resjson.action_code = 11

    if not check_login():
        return resjson.print_json(resjson.NOT_LOGIN)
    uid = get_uid()

    wtf_form = ProfileForm()
    current_time = current_timestamp()

    if not wtf_form.validate_on_submit():
        for key, value in wtf_form.errors.items():
            msg = value[0]
        return resjson.print_json(11, msg)

    data = {
        'nickname': wtf_form.nickname.data,
        'avatar': wtf_form.avatar.data,
        'gender': wtf_form.gender.data,
        'update_time': current_time
    }

    user = User.query.get(uid)
    model_update(user, data, commit=True)

    set_user_session(user)

    return resjson.print_json(0, u'ok')
Пример #6
0
def save_comment():
    """评价订单商品"""
    resjson.action_code = 17

    if not check_login():
        return resjson.print_json(resjson.NOT_LOGIN)
    uid = get_uid()
    nickname = get_nickname()
    avatar = get_avatar()

    wtf_form = CommentOrderGoodsForm()
    current_time = current_timestamp()

    if not wtf_form.validate_on_submit():
        for key, value in wtf_form.errors.items():
            msg = value[0]
        return resjson.print_json(11, msg)

    og_id = wtf_form.og_id.data
    order_goods = OrderGoods.query.get(og_id)
    if not order_goods:
        return resjson.print_json(12, _(u'订单商品不存在'))

    order = Order.query.filter(Order.order_id == order_goods.order_id).filter(
        Order.uid == uid).first()
    if not order:
        return resjson.print_json(13, _(u'订单商品不存在'))

    data = {'uid': uid, 'nickname': nickname, 'avatar': avatar, 'ttype': 1, 'tid': order_goods.goods_id,
            'rating': wtf_form.rating.data, 'content': wtf_form.content.data,
            'img_data': wtf_form.img_data.data, 'add_time': current_time}
    comment = model_create(Comment, data, commit=True)

    item = Goods.query.get(order_goods.goods_id)
    if item:
        comment_count = Comment.query.\
            filter(Comment.ttype == 1).\
            filter(Comment.tid == order_goods.goods_id).count()
        good_count = Comment.query.\
            filter(Comment.ttype == 1).\
            filter(Comment.tid == order_goods.goods_id).\
            filter(Comment.rating == 3).count()
        comment_good_rate = round(
            (Decimal(good_count)/Decimal(comment_count)) * 100)
        model_update(item, {'comment_count': comment_count,
                            'comment_good_rate': comment_good_rate})

    model_update(order_goods, {'comment_id': comment.comment_id}, commit=True)

    # 站内消息
    content = _(u'您已评价“%s”。' % order_goods.goods_name)
    mcs = MessageCreateService(
        1, uid, -1, content, ttype=2, tid=og_id, current_time=current_time)
    if not mcs.check():
        log_error('[ErrorViewApiOrderSaveComment][MessageCreateError]  og_id:%s msg:%s' % (
            og_id, mcs.msg))
    else:
        mcs.do()

    return resjson.print_json(0, u'ok')
Пример #7
0
 def __init__(self,
              message_type,
              tuid,
              fuid=0,
              content=u'',
              img=u'',
              ttype=0,
              tid=0,
              data={},
              current_time=0):
     """初始化函数
     @param message_type 消息类型 0.默认; 1.系统通知
     @param tuid 接收用户ID 0.所有用户
     @param fuid 来源用户ID -1.系统; 0.接收用户自己; >0:其它用户ID;
     @param ttype 第三方类型 0.默认; 1.订单; 2.订单商品;
     @param tid 第三方ID
     """
     self.msg = u''
     self.message_type = message_type
     self.tuid = tuid
     self.fuid = fuid
     self.content = content
     self.img = img
     self.ttype = toint(ttype)
     self.tid = toint(tid)
     self.data = json.dumps(data) if data else json.dumps('{}')
     self.message_type_list = [1]
     self.ttype_list = [1]
     self.current_time = current_time if current_time else current_timestamp(
     )
     self.today_timestamp = some_day_timestamp(current_time, 0)
     self.message = None
     self.tuser = None
     self.fuser = {'uid': self.fuid}
Пример #8
0
 def __init__(self,
              uid,
              order_id=0,
              og_id=0,
              quantity=0,
              aftersales_type=0,
              deliver_status=0,
              content='',
              img_data='[]'):
     self.msg = u''
     self.uid = uid  # 用户UID
     self.order_id = toint(order_id)  # 订单ID
     self.og_id = toint(og_id)  # 订单商品ID
     self.quantity = toint(quantity)  # 售后商品数量
     self.aftersales_type = toint(
         aftersales_type)  # 售后类型: 0.默认; 1.仅退款; 2.退货退款; 3.仅换货;
     self.deliver_status = toint(
         deliver_status)  # 订单收货状态: 0.默认; 1.未收货; 2.已收货;
     self.content = content  # 申请原因
     self.img_data = img_data  # 图片数据
     self.current_time = current_timestamp()  # 当前时间
     self.refunds_amount = Decimal('0.00')  # 退款金额
     self.goods_data = []  # 售后商品数据
     self.order = None  # 订单实例
     self.order_address = None  # 收货地址实例
     self.order_goods = None  # 订单商品实例
     self.order_goods_list = []  # 订单商品实例列表
     self.address_data = {}  # 售后地址数据
     self.aftersales = None  # 售后记录
Пример #9
0
    def add_log(aftersales_id,
                content,
                al_type=0,
                current_time=0,
                commit=True):
        """添加日志
            @param al_type 类型:
                        0_默认,
                        1_申请,
                        2_审核,
                        3_收货(商家),
                        4_退款,
                        5_寄货(商家)
                        6_寄货(用户),
        """

        current_time = current_time if current_time else current_timestamp()

        aftersales = Aftersales.query.get(aftersales_id)
        if aftersales:
            data = {
                'aftersales_id': aftersales_id,
                'content': content,
                'al_type': al_type,
                'add_time': current_time
            }
            model_create(AftersalesLogs, data)

            data = {'latest_log': content, 'update_time': current_time}
            model_update(aftersales, data, commit=commit)

        return True
Пример #10
0
def cancel():
    """取消订单"""
    resjson.action_code = 11

    form = request.form
    order_id = toint(form.get('order_id', 0))
    cancel_desc = form.get('cancel_desc', '').strip()
    # operation_note = form.get('operation_note', '').strip()
    current_time = current_timestamp()

    order = Order.query.get(order_id)
    if not order:
        return resjson.print_json(10, _(u'订单不存在'))

    if order.pay_status == 2:
        return resjson.print_json(11, _(u'不能取消已付款的订单'))

    if order.shipping_status == 2:
        return resjson.print_json(13, _(u'订单已经发货,不能取消'))

    if order.order_status == 2:
        return resjson.print_json(14, _(u'订单已经完成,不能取消'))

    order.order_status = 3
    order.cancel_status = 2
    order.cancel_desc = cancel_desc
    order.cancel_time = current_time
    order.update_time = current_time

    db.session.commit()
    return resjson.print_json(0, u'ok')
Пример #11
0
def index(page=1, page_size=20):
    """优惠券列表"""
    g.page_title = _(u'优惠券')

    args = request.args
    tab_status = toint(args.get('tab_status', '0'))
    cb_name = args.get('cb_name', '').strip()
    current_time = current_timestamp()

    q = CouponBatch.query

    if tab_status == 1:
        q = q.filter(CouponBatch.is_valid == 1).\
                filter(or_(CouponBatch.begin_time == 0, CouponBatch.begin_time <= current_time)).\
                filter(or_(CouponBatch.end_time == 0, CouponBatch.end_time >= current_time))
    elif tab_status == 2:
        q = q.filter(
            and_(CouponBatch.end_time > 0,
                 CouponBatch.end_time < current_time))

    if cb_name:
        q = q.filter(CouponBatch.cb_name.like('%%%s%%' % cb_name))

    batches = q.order_by(CouponBatch.cb_id.desc()).offset(
        (page - 1) * page_size).limit(page_size).all()
    pagination = Pagination(None, page, page_size, q.count(), None)

    return render_template('admin/coupon/index.html.j2',
                           pagination=pagination,
                           batches=batches)
Пример #12
0
    def coupons(uid):
        current_time = current_timestamp()

        q = Coupon.query.\
                filter(Coupon.uid == uid).\
                filter(Coupon.is_valid == 1).\
                filter(Coupon.begin_time <= current_time).\
                filter(Coupon.end_time >= current_time)
        valid_count = get_count(q)
        valid_coupons = q.order_by(Coupon.coupon_id.desc()).all()

        q = Coupon.query.\
                filter(Coupon.uid == uid).\
                filter(or_(and_(Coupon.is_valid == 0, Coupon.order_id == 0), Coupon.end_time < current_time))
        invalid_count = get_count(q)
        invalid_coupons = q.order_by(Coupon.coupon_id.desc()).all()

        q = Coupon.query.\
                filter(Coupon.uid == uid).\
                filter(Coupon.order_id > 0)
        used_count = get_count(q)
        used_coupons = q.order_by(Coupon.coupon_id.desc()).all()

        data = {
            'valid_coupons': valid_coupons,
            'invalid_coupons': invalid_coupons,
            'used_coupons': used_coupons,
            'valid_count': valid_count,
            'invalid_count': invalid_count,
            'used_count': used_count
        }

        return data
Пример #13
0
def shipping():
    """确认发货"""
    resjson.action_code = 10

    form = request.form
    order_id = toint(form.get('order_id', 0))
    shipping_sn = form.get('shipping_sn', '').strip()
    # operation_note = form.get('operation_note', '').strip()
    shipping_id = toint(form.get('shipping_id', 0))
    current_time = current_timestamp()

    order = Order.query.get(order_id)
    if not order:
        return resjson.print_json(10, _(u'订单不存在'))

    if order.shipping_status == 2:
        return resjson.print_json(11, _(u'请勿重复发货'))

    if order.pay_status != 2:
        return resjson.print_json(12, _(u'未付款订单'))

    if shipping_sn == '':
        return resjson.print_json(13, _(u'请填写快递单号'))

    shipping = Shipping.query.get(shipping_id)
    if not shipping:
        return resjson.print_json(14, _(u'物流公司不存在'))

    order.shipping_id = shipping.shipping_id
    order.shipping_name = shipping.shipping_name
    order.shipping_code = shipping.shipping_code
    order.shipping_sn = shipping_sn
    order.shipping_status = 2
    order.shipping_time = current_time
    order.deliver_status = 1
    order.update_time = current_time

    # 站内消息
    content = _(u'您的订单%s已发货,%s,快递单号%s,请注意查收。' %
                (order.order_sn, order.shipping_name, shipping_sn))
    mcs = MessageCreateService(1,
                               order.uid,
                               -1,
                               content,
                               ttype=1,
                               tid=order_id,
                               current_time=current_time)
    if not mcs.check():
        log_error(
            '[ErrorViewAdminOrderShipping][MessageCreateError]  order_id:%s msg:%s'
            % (order_id, mcs.msg))
    else:
        mcs.do()

    db.session.commit()

    # 微信消息
    WeixinMessageStaticMethodsService.shipping(order)

    return resjson.print_json(0, u'ok')
Пример #14
0
def notify():
    """微信支付回调"""
    resjson.action_code = 13

    xml = request.data
    jns = JsapiNotifyService(xml)
    if not jns.check():
        return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[CheckError]]></return_msg></xml>"

    if not jns.verify():
        return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[VerifyError]]></return_msg></xml>"

    pay_tran_id = jns.transaction_id
    paid_amount = (jns.total_fee / 100)
    tran_id = jns.out_trade_no
    current_time = current_timestamp()

    data = {
        'pay_tran_id': pay_tran_id,
        'pay_method': 'weixin_jsapi',
        'paid_time': current_time,
        'paid_amount': paid_amount
    }
    ps = PaidService(tran_id, **data)
    ps.paid()

    return "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"
Пример #15
0
 def __init__(self, form, us_id=0):
     self.errmsg = {}
     self.form = form
     self.us_id = us_id
     self.current_time = current_timestamp()
     self.is_new = False
     self.salon = None
     self.salon_img = ''
Пример #16
0
    def __init__(self, order_id, uid):
        """初始化函数"""

        self.order_id = order_id                 # 订单ID
        self.uid = uid                           # 用户ID
        self.current_time = current_timestamp()  # 当前时间
        self.order = None                        # 订单实例
        self.__is_check_order = False            # 是否检查订单
Пример #17
0
 def __init__(self, form, news_id=0):
     self.errmsg = {}
     self.form = form
     self.news_id = news_id
     self.current_time = current_timestamp()
     self.is_new = False
     self.news = None
     self.news_img = ''
Пример #18
0
def coupon_save():
    """优惠券派发保存"""

    admin_uid = session.get('admin_uid', None)
    if not admin_uid:
        return_url = request.args.get('return_url', '/admin/dashboard')
        return redirect(url_for('admin.auth.login', return_url=return_url))

    form = CouponForm(request.form)
    form.avatar.data = request.args.get('avatar')

    if not form.validate_on_submit():
        return render_template('admin/user/coupon.html.j2', form=form)

    coupon_batch = CouponBatch.query.filter(
        CouponBatch.cb_id == form.cb_id.data).first()

    if not coupon_batch:
        return render_template('admin/user/coupon.html.j2', form=form)

    #刷新优惠券数据
    give_num = coupon_batch.give_num + 1
    data = {'give_num': give_num}
    model_update(coupon_batch, data)

    coupon = model_create(Coupon, {'add_time': current_timestamp()})

    data = {
        'uid': form.uid.data,
        'cb_id': coupon_batch.cb_id,
        'coupon_name': coupon_batch.coupon_name,
        'begin_time': coupon_batch.begin_time,
        'end_time': coupon_batch.end_time,
        'is_valid': coupon_batch.is_valid,
        'limit_amount': coupon_batch.limit_amount,
        'coupon_amount': coupon_batch.coupon_amount,
        'limit_goods': coupon_batch.limit_goods,
        'limit_goods_name': coupon_batch.limit_goods_name,
        'coupon_from': coupon_batch.coupon_from,
        'update_timne': current_timestamp()
    }

    model_update(coupon, data, True)

    return redirect(url_for('admin.user.detail', uid=form.uid.data))
Пример #19
0
 def __init__(self, uid, wmt_id, data, url=''):
     self.uid = uid
     self.wmt_id = wmt_id
     self.data = data
     self.url = url
     self.current_time = current_timestamp()
     self.openid = ''
     self.access_token = ''
     self.template_id = ''
Пример #20
0
 def __init__(self, uid, order_id_list):
     self.msg = ''
     self.uid = uid
     self.order_id_list = order_id_list
     self.order_id_json = '[]'
     self.order_sn_list = []
     self.pay_order_list = []
     self.tran = None
     self.current_time = current_timestamp()
Пример #21
0
    def __init__(self, *args, **kwargs):
        super(CouponForm, self).__init__(*args, **kwargs)

        _coupons   = db.session.query(CouponBatch.cb_id, CouponBatch.coupon_name).\
                                    filter(current_timestamp() <= CouponBatch.end_time).\
                                    filter(CouponBatch.give_num < CouponBatch.publish_num).\
                                    filter(CouponBatch.is_valid == 1).all()
        
        self.cb_id.choices = _coupons
Пример #22
0
 def __init__(self, order_id, refunds_amount, current_time=0):
     self.msg = u''
     self.order_id = order_id
     self.refunds_amount = refunds_amount
     self.current_time = current_time if current_time else current_timestamp(
     )
     self.third_type = 0
     self.fs = None
     self.jwrs = None
     self.order = None
     self.refunds = None
Пример #23
0
 def __init__(self, form, goods_id=0):
     self.errmsg             = {}
     self.form               = form
     self.goods_id           = goods_id
     self.current_time       = current_timestamp()
     self.is_new             = False
     self.goods              = None
     self.goods_img          = ''
     self.goods_gallery_list = []
     self.goods_attr_list    = []
     self.goods_sku_list     = []
Пример #24
0
def address_save():
    """保存地址"""
    resjson.action_code = 12

    if not check_login():
        return resjson.print_json(resjson.NOT_LOGIN)
    uid = get_uid()

    wtf_form = AddressForm()
    current_time = current_timestamp()

    if not wtf_form.validate_on_submit():
        for key, value in wtf_form.errors.items():
            msg = value[0]
        return resjson.print_json(11, msg)

    is_default = toint(request.form.get('is_default', '-1'))
    if is_default not in [-1, 0, 1]:
        return resjson.print_json(resjson.PARAM_ERROR)

    ua_id = wtf_form.ua_id.data
    if ua_id:
        user_address = UserAddress.query.filter(
            UserAddress.ua_id == ua_id).filter(UserAddress.uid == uid).first()
        if not user_address:
            return resjson.print_json(12, _(u'收货地址不存在'))
    else:
        data = {'uid': uid, 'is_default': 1, 'add_time': current_time}
        user_address = model_create(UserAddress, data)

    if is_default == -1:
        is_default = user_address.is_default

    data = {
        'name': wtf_form.name.data,
        'mobile': wtf_form.mobile.data,
        'province': wtf_form.province.data,
        'city': wtf_form.city.data,
        'district': wtf_form.district.data,
        'address': wtf_form.address.data,
        'is_default': is_default,
        'update_time': current_time
    }

    if is_default == 1:
        default = UserAddress.query.filter(UserAddress.uid == uid).filter(
            UserAddress.is_default == 1).first()
        if default and default.ua_id != ua_id:
            default.is_default = 0

    user_address = model_update(user_address, data)
    db.session.commit()

    return resjson.print_json(0, u'ok', {'ua_id': user_address.ua_id})
Пример #25
0
    def __init__(self, order_id, uid, cancel_desc=u''):
        """初始化服务"""

        self.order_id = order_id                  # 订单ID
        self.uid = uid                            # 订单用户ID
        self.cancel_desc = cancel_desc            # 取消原因
        self.order = None                         # 订单信息
        self.current_time = current_timestamp()   # 当前时间
        self.cancel_status = 0                    # 取消状态

        self.__is_chceck_order = False            # 是否检查订单
Пример #26
0
    def reset_last_time(uid, last_type):
        """重置最新时间"""

        current_time = current_timestamp()

        ult = UserLastTime.query.\
                filter(UserLastTime.uid == uid).\
                filter(UserLastTime.last_type == last_type).first()

        model_update(ult, {'last_time': current_time}, commit=True)

        return True
Пример #27
0
 def __init__(self):
     self.msg = u''
     self.current_time = current_timestamp()
     self.order_id = 0
     self.order_type = 0
     self.code_url = ''
     self.redirect_url = ''
     self.appid = ''
     self.secret = ''
     self.code = ''
     self.openid = ''
     self.opentime = ''
Пример #28
0
    def __init__(self, user_data, current_time=0, request=None):
        self.msg = u''
        self.user = None
        self.user_data = {}
        self.current_time = current_time if current_time else current_timestamp(
        )

        _user_data_key = [
            'nickname', 'avatar', 'gender', 'country', 'province', 'city'
        ]
        for key in _user_data_key:
            self.user_data[key] = user_data.get(key, '')
Пример #29
0
def update():
    """更新购物车"""
    resjson.action_code = 12

    uid = get_uid()
    session_id = session.sid

    args = request.args
    cart_id = toint(args.get('cart_id', 0))
    quantity = toint(args.get('quantity', 0))
    current_time = current_timestamp()

    # 检查
    if cart_id <= 0 or quantity <= 0:
        return resjson.print_json(resjson.PARAM_ERROR)

    # 获取购物车商品
    q = Cart.query.filter(Cart.cart_id == cart_id).filter(
        Cart.checkout_type == 1)
    if uid:
        q = q.filter(Cart.uid == uid)
    else:
        q = q.filter(Cart.session_id == session_id)
    cart = q.first()
    if cart is None:
        return resjson.print_json(10, _(u'购物车里找不到商品'))

    # 更新购物车商品
    data = {'quantity': quantity, 'update_time': current_time}
    model_update(cart, data, commit=True)

    cs = CartService(uid, session_id)
    cs.check()
    session['cart_total'] = cs.cart_total

    for _cart in cs.carts:
        if _cart['cart'].cart_id == cart_id:
            _items_amount = _cart['items_amount']

    # 商品状态
    item = Goods.query.get(cart.goods_id)
    is_valid, valid_status = CartStaticMethodsService.check_item_statue(
        item, cart)

    data = {
        'cart_total': cs.cart_total,
        'items_quantity': cs.items_quantity,
        'items_amount': cs.items_amount,
        '_items_amount': _items_amount,
        'is_valid': is_valid,
        'valid_status': valid_status
    }
    return resjson.print_json(0, u'ok', data)
Пример #30
0
def fundspay_req():
    """ 余额支付请求 """
    resjson.action_code = 10

    if not check_login():
        return resjson.print_json(resjson.NOT_LOGIN)
    uid = get_uid()

    paid_time = current_timestamp()
    pay_amount = Decimal('0.00')

    args = request.args
    order_id_list = args.get('order_id_list', '[]').strip()
    try:
        order_id_list = json.loads(order_id_list)
    except Exception as e:
        return resjson.print_json(10, _(u'支付订单ID列表数据格式错误'))

    ps = PayService(uid, order_id_list)
    if not ps.check():
        return resjson.print_json(11, ps.msg)

    if not ps.tran:
        ps.create_tran()

    tran = ps.tran
    tran_id = tran.tran_id
    pay_amount -= Decimal(tran.pay_amount).quantize(Decimal('0.00'))

    # 更新资金 - 使用资金支付 - 检查
    remark_user = _(u'支付订单')
    remark_sys = _(u'支付订单,订单编号:%s,支付金额:%s' %
                   (','.join(ps.order_sn_list), pay_amount))
    fs = FundsService(uid, pay_amount, 2, 1, tran_id, remark_user, remark_sys,
                      paid_time)
    if not fs.check():
        return resjson.print_json(12, fs.msg)

    # 更新资金 - 使用资金支付 - 支付
    fs.update()

    data = {
        'pay_tran_id': fs.funds_detail.fd_id,
        'pay_method': 'funds',
        'paid_time': paid_time,
        'paid_amount': fs.funds_change
    }
    ps = PaidService(tran_id, **data)
    ps.paid()

    return resjson.print_json(0, u'ok', {'info': {}, 'tran': tran})