Exemple #1
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)
Exemple #2
0
 def __init__(self, like_type, ttype, tid, current_time=0):
     self.msg          = u''
     self.like_type    = toint(like_type)    # LIKE类型: 0.默认; 1.点赞; 2.收藏; 3.关注;
     self.ttype        = toint(ttype)        # 第三方类型: 0.默认; 1.商品;
     self.tid          = toint(tid)          # 第三方ID
     self.tname        = u''                 # 第三方名称
     self.timg         = u''                 # 第三方封面图
     self.uid          = get_uid()           # 用户UID
     self.nickname     = get_nickname()      # 用户昵称
     self.avatar       = get_avatar()        # 用户头像
     self.action_code  = 0                   # 0.默认; 1.添加; 2.取消;
     self.ext_data     = '{}'                # 扩展数据, json
     self.like         = None                # Like实例
     self.third_obj    = None                # 第三方实例
     self.current_time = current_time if current_time else current_timestamp()
Exemple #3
0
    def advs(params, platform_type=1):
        """获取广告列表"""

        p = toint(params.get('p', '1'))
        ps = toint(params.get('ps', '10'))
        ac_id = toint(params.get('ac_id', '0'))

        advs = db.session.query(Adv.adv_id, Adv.ac_id, Adv.img, Adv.ttype, Adv.tid, Adv.url).\
                    filter(Adv.is_show == 1).\
                    filter(Adv.ac_id == ac_id).\
                    filter(Adv.platform_type == platform_type).\
                    order_by(Adv.sorting.desc()).\
                    order_by(Adv.adv_id.desc()).offset((p-1)*ps).limit(ps).all()

        return advs
Exemple #4
0
def checked():
    """选中"""
    resjson.action_code = 14

    uid = get_uid()
    session_id = session.sid

    carts = request.args.get('carts', '[]').strip()
    current_time = current_timestamp()

    try:
        carts = json.loads(carts)
    except Exception as e:
        return resjson.print_json(resjson.PARAM_ERROR)
    for cart in carts:
        cart_id = toint(cart.get('cart_id', 0))
        is_checked = toint(cart.get('is_checked', -1))

        # 检查
        if cart_id <= 0 or is_checked not in [0, 1]:
            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 = {'is_checked': is_checked, 'update_time': current_time}
        model_update(cart, data)

    db.session.commit()

    cs = CartService(uid, session_id)
    cs.check()

    data = {
        'cart_total': cs.cart_total,
        'items_quantity': cs.items_quantity,
        'items_amount': cs.items_amount
    }
    return resjson.print_json(0, u'ok', data)
Exemple #5
0
def index(page=1, page_size=20):
    """商品列表"""
    g.page_title = _(u'商品')

    args = request.args
    tab_status = toint(args.get('tab_status', '0'))
    cat_id = toint(args.get('cat_id', '0'))
    goods_name = args.get('goods_name', '').strip()

    q = db.session.query(Goods.goods_id, Goods.cat_id, Goods.goods_name, Goods.goods_img, Goods.goods_price,
                         Goods.is_sale, Goods.stock_quantity, Goods.is_hot, Goods.is_recommend, Goods.add_time,
                         GoodsCategories.cat_name).\
        filter(Goods.cat_id == GoodsCategories.cat_id).\
        filter(Goods.is_delete == 0)

    if cat_id > 0:
        q = q.filter(Goods.cat_id == cat_id)

    if tab_status == 1:
        q = q.filter(Goods.is_sale == 1)

    if tab_status == 2:
        q = q.filter(Goods.is_sale == 0)

    if tab_status == 3:
        q = q.filter(Goods.is_hot == 1)

    if tab_status == 4:
        q = q.filter(Goods.is_recommend == 1)

    if goods_name:
        q = q.filter(Goods.goods_name.like('%%%s%%' % goods_name))

    items = q.order_by(Goods.goods_id.desc()).offset(
        (page - 1) * page_size).limit(page_size).all()
    pagination = Pagination(None, page, page_size, q.count(), None)

    cats = [{'name': _(u'请选择……'), 'value': '-1'}]
    _cats = db.session.query(GoodsCategories.cat_id, GoodsCategories.cat_name).\
                order_by(GoodsCategories.cat_id.desc()).all()
    for _cat in _cats:
        cat = {'name': _cat.cat_name, 'value': _cat.cat_id}
        cats.append(cat)

    return render_template('admin/item/index.html.j2',
                           pagination=pagination,
                           items=items,
                           cats=cats)
Exemple #6
0
    def details(uid, params, is_pagination=False):
        """获取资金流水列表"""

        p  = toint(params.get('p', '1'))
        ps = toint(params.get('ps', '10'))

        q       = db.session.query(FundsDetail.fd_id, FundsDetail.funds_change,
                                    FundsDetail.event, FundsDetail.add_time).\
                        filter(FundsDetail.uid == uid)
        details = q.order_by(FundsDetail.fd_id.desc()).offset((p-1)*ps).limit(ps).all()

        pagination = None
        if is_pagination:
            pagination = Pagination(None, p, ps, q.count(), None)

        return {'details':details, 'pagination':pagination}
def index(page=1, page_size=20):
    """评论列表"""
    g.page_title = _(u'商品评价')

    args = request.args
    goods_id = toint(args.get('goods_id', '0'))
    add_time_daterange = args.get('add_time_daterange', '').strip()

    q = db.session.query(Comment.comment_id, Comment.uid, Comment.nickname, Comment.avatar,
                            Comment.rating, Comment.content, Comment.img_data, Comment.add_time,
                            Goods.goods_id, Goods.goods_name, Goods.goods_img).\
                        filter(Comment.tid == Goods.goods_id).\
                        filter(Comment.ttype == 1).\
                        filter(Comment.is_show == 1)

    if goods_id > 0:
        q = q.filter(Comment.tid == goods_id)

    if add_time_daterange:
        start, end = date_range(add_time_daterange)
        q = q.filter(Comment.add_time >= start).filter(Comment.add_time < end)

    comments = q.order_by(Comment.comment_id.desc()).offset(
        (page - 1) * page_size).limit(page_size).all()
    pagination = Pagination(None, page, page_size, q.count(), None)

    return render_template('admin/comment/index.html.j2',
                           pagination=pagination,
                           comments=comments)
    def aftersales(params, is_pagination=False):
        """获取售后列表"""

        p = toint(params.get('p', '1'))
        ps = toint(params.get('ps', '10'))
        uid = toint(params.get('uid', '0'))

        q = Aftersales.query.filter(Aftersales.uid == uid)
        aftersales = q.order_by(Aftersales.aftersales_id.desc()).offset(
            (p - 1) * ps).limit(ps).all()

        pagination = None
        if is_pagination:
            pagination = Pagination(None, p, ps, q.count(), None)

        return {'aftersales': aftersales, 'pagination': pagination}
Exemple #9
0
def remove():
    """ 删除订单 """
    resjson.action_code = 16

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

    order_id = toint(request.args.get('order_id', 0))

    if order_id <= 0:
        return resjson.print_json(resjson.PARAM_ERROR)

    order = Order.query.filter(Order.order_id == order_id).filter(
        Order.uid == uid).first()

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

    if order.order_status not in (2, 3):
        return resjson.print_json(11, _(u'当前订单状态不允许删除订单'))

    model_update(order, {'is_remove': 1}, commit=True)

    return resjson.print_json(0, u'ok')
Exemple #10
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)
Exemple #11
0
def deliver():
    """确认收货"""

    if not check_login():
        session['weixin_login_url'] = request.url
        return redirect(url_for('api.weixin.login'))
    uid = get_uid()

    args = request.args
    order_id = toint(args.get('order_id', 0))

    if order_id <= 0:
        return ''

    ods = OrderDeliverService(order_id, uid)
    try:
        ods.deliver()
    except OrderException as e:
        msg = u'%s' % e.msg
        log_error(msg)
        return ''

    text, code = OrderStaticMethodsService.order_status_text_and_action_code(
        ods.order)

    return render_template('mobile/order/order.html.j2',
                           order=ods.order,
                           text=text,
                           code=code)
Exemple #12
0
def cancel():
    """取消订单"""

    if not check_login():
        session['weixin_login_url'] = request.url
        return redirect(url_for('api.weixin.login'))
    uid = get_uid()

    args = request.args
    order_id = toint(args.get('order_id', 0))
    cancel_desc = args.get('cancel_desc', '').strip()

    if order_id <= 0:
        return ''

    ocs = OrderCancelService(order_id, uid, cancel_desc)
    try:
        ocs.cancel()
    except OrderException as e:
        msg = u'%s' % e.msg
        log_error(msg)
        return ''

    text, code = OrderStaticMethodsService.order_status_text_and_action_code(
        ocs.order)

    return render_template('mobile/order/order.html.j2',
                           order=ocs.order,
                           text=text,
                           code=code)
Exemple #13
0
def check():
    """售后审核"""
    resjson.action_code = 10

    form = request.form
    aftersales_id = toint(form.get('aftersales_id', 0))
    check_status = toint(form.get('check_status', 0))
    content = form.get('content', '').strip()

    ascs = AfterSaleCheckService(aftersales_id, check_status, content)
    if not ascs.check():
        return resjson.print_json(10, ascs.msg)

    ascs.do()

    return resjson.print_json(0, u'ok')
Exemple #14
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')
Exemple #15
0
    def messages(params, is_pagination=False):
        """获取消息列表"""

        p = toint(params.get('p', '1'))
        ps = toint(params.get('ps', '10'))
        uid = toint(params.get('uid', '0'))

        q = db.session.query(Message.message_id, Message.message_type, Message.content,
                             Message.ttype, Message.tid, Message.add_time).\
            filter(Message.tuid == uid)
        messages = q.order_by(Message.message_id.desc()).offset(
            (p - 1) * ps).limit(ps).all()

        pagination = None
        if is_pagination:
            pagination = Pagination(None, p, ps, q.count(), None)

        return {'messages': messages, 'pagination': pagination}
Exemple #16
0
def paging():
    """加载分页"""
    args = request.args
    p = toint(args.get('p', '1'))
    ps = toint(args.get('ps', '10'))
    cat_id = toint(args.get('cat_id', '0'))
    is_hot = toint(args.get('is_hot', '0'))
    is_recommend = toint(args.get('is_recommend', '0'))

    service = ItemListService(
        p,
        ps,
        cat_id=cat_id,
        is_hot=is_hot,
        is_recommend=is_recommend)
    items = service.items()

    return render_template('mobile/item/paging.html.j2',
                           items=items)
Exemple #17
0
    def likes(params, is_pagination=False):
        """获取赞列表"""

        p   = toint(params.get('p', '1'))
        ps  = toint(params.get('ps', '10'))
        uid = toint(params.get('uid', '0'))

        q     = db.session.query(Like.like_id, Like.like_type, Like.ttype, Like.tid, Like.tname, Like.timg,
                                    Like.ext_data, Like.add_time).\
                    filter(Like.uid == uid).\
                    filter(Like.like_type == 2).\
                    filter(Like.ttype == 1)
        likes = q.order_by(Like.like_id.desc()).offset((p-1)*ps).limit(ps).all()

        pagination = None
        if is_pagination:
            pagination = Pagination(None, p, ps, q.count(), None)

        return {'likes':likes, 'pagination':pagination}
Exemple #18
0
    def order_comments(uid, params, is_pagination=False):
        """ 订单评价中心 """

        p = toint(params.get('p', '1'))
        ps = toint(params.get('ps', '10'))
        is_pending = toint(params.get('is_pending', '0'))

        completed = db.session.query(Order.order_id).\
            filter(Order.uid == uid).\
            filter(Order.is_remove == 0).\
            filter(Order.order_status == 2).\
            filter(Order.pay_status == 2).\
            filter(Order.deliver_status == 2).all()
        completed = [order.order_id for order in completed]

        q = db.session.query(
            OrderGoods.og_id, OrderGoods.goods_id, OrderGoods.goods_name,
            OrderGoods.goods_img, OrderGoods.goods_desc,
            OrderGoods.goods_price, OrderGoods.comment_id).\
            filter(OrderGoods.order_id.in_(completed))
        pending_count = get_count(q.filter(OrderGoods.comment_id == 0))
        unpending_count = get_count(q.filter(OrderGoods.comment_id > 0))

        if is_pending == 1:
            q = q.filter(OrderGoods.comment_id == 0)
        else:
            q = q.filter(OrderGoods.comment_id > 0)

        comments = None
        pagination = None
        if is_pagination:
            comments = q.order_by(OrderGoods.og_id.desc()).offset(
                (p-1)*ps).limit(ps).all()
            pagination = Pagination(None, p, ps, q.count(), None)
        else:
            comments = q.order_by(OrderGoods.og_id.desc()).all()

        data = {'is_pending': is_pending, 'pending_count': pending_count,
                'unpending_count': unpending_count, 'comments': comments,
                'pagination': pagination}

        return data
Exemple #19
0
def galleries_remove():
    """删除商品相册"""
    resjson.action_code = 11

    id = toint(request.args.get('id'))
    gallery = GoodsGalleries.query.filter(GoodsGalleries.id == id).first()
    db.session.delete(gallery)
    db.session.commit()

    #return jsonify({'ret':0, 'msg':'ok'})
    return resjson.print_json(0, u'ok', {'gallery': gallery})
Exemple #20
0
def action():
    """ 点赞或取消点赞 """
    resjson.action_code = 10

    if not check_login():
        return resjson.print_json(resjson.NOT_LOGIN)

    args = request.args
    like_type = toint(args.get('like_type', 0))
    ttype = toint(args.get('ttype', 0))
    tid = toint(args.get('tid', 0))

    ls = LikeService(like_type, ttype, tid)
    if not ls.check():
        return resjson.print_json(11, ls.msg)

    ls.action()
    ls.commit()

    return resjson.print_json(0, u'ok', {'action_code': ls.action_code})
Exemple #21
0
    def __connect_xiao(self):
        """连接小程序"""

        false = (False, '', '', {}, {})
        jscode = self.request.args.get('jscode', '')
        nickname = self.request.args.get('nickname', '')
        avatar = self.request.args.get('avatar', '')
        gender = toint(self.request.args.get('gender', 0))
        country = self.request.args.get('country', '')
        province = self.request.args.get('province', '')
        city = self.request.args.get('city', '')

        if not jscode:
            self.msg = _(u'缺少jscode')
            return false

        if not nickname or not avatar:
            self.msg = _(u'缺少用户信息')
            return false

        user_data = {
            'nickname': nickname,
            'avatar': avatar,
            'gender': gender,
            'country': country,
            'province': province,
            'city': city
        }

        uri = 'https://api.weixin.qq.com/sns/jscode2session'
        params = OrderedDict()
        params['appid'] = self.appid
        params['secret'] = self.secret
        params['js_code'] = jscode
        params['grant_type'] = 'authorization_code'
        query_string = urlencode(params)
        url = u'%s?%s' % (uri, query_string)

        response = requests.get(url)
        if response.status_code != 200:
            self.msg = _(u'连接请求错误')
            return false

        data = response.json()
        errcode = data.get('errcode', 0)
        if errcode > 0:
            self.msg = _(u'登录请求错误')
            return false

        openid = data.get('openid')
        session_key = data.get('session_key')
        unionid = data.get('unionid')

        return (True, openid, unionid, data, user_data)
Exemple #22
0
def collect():
    """ 我的收藏列表 """

    resjson.action_code = 17

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

    args = request.args
    p = toint(args.get('p', '1'))
    ps = toint(args.get('ps', '10'))

    if p <= 0 or ps <= 0:
        return resjson.print_json(resjson.PARAM_ERROR)

    params = {'uid': uid, 'p': p, 'ps': ps}
    data = LikeStaticMethodsService.likes(params)

    return resjson.print_json(0, u'ok', {'likes': data['likes']})
Exemple #23
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})
Exemple #24
0
def h5_save():
    """保存文章H5"""
    g.page_title = _(u'保存文章')

    post_id = toint(request.form.get('post_id', '0'))
    post_detail   = request.form.get('detail', '').strip()

    item = Post.query.get_or_404(post_id)
    item.post_detail = post_detail
    db.session.commit()

    return redirect(url_for('admin.post.index'))
Exemple #25
0
def h5_save():
    """保存商品H5"""
    g.page_title = _(u'保存商品')

    goods_id = toint(request.form.get('goods_id', '0'))
    detail = request.form.get('detail', '').strip()

    item = Goods.query.get_or_404(goods_id)
    item.detail = detail
    db.session.commit()

    return redirect(url_for('admin.item.index'))
Exemple #26
0
def messages():
    """ 消息列表 """

    resjson.action_code = 16

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

    args = request.args
    p = toint(args.get('p', '1'))
    ps = toint(args.get('ps', '10'))

    if p <= 0 or ps <= 0:
        return resjson.print_json(resjson.PARAM_ERROR)

    params = {'uid': uid, 'p': p, 'ps': ps}
    data = MessageStaticMethodsService.messages(params)
    UserStaticMethodsService.reset_last_time(uid, 1)

    return resjson.print_json(0, u'ok', {'messages': data['messages']})
Exemple #27
0
def index():
    """ 评论列表 """
    resjson.action_code = 10

    params = request.args.to_dict()
    
    p      = toint(params.get('p', '1'))
    ps     = toint(params.get('ps', '10'))
    ttype  = toint(params.get('ttype', '0'))
    tid    = toint(params.get('tid', '0'))
    rating = toint(params.get('rating', '0'))
    is_img = toint(params.get('is_img', '0'))
    
    if p <=0 or ps <= 0:
        return resjson.print_json(resjson.PARAM_ERROR)

    if ttype not in [0, 1] or tid <= 0:
        return resjson.print_json(resjson.PARAM_ERROR)
    
    if rating not in [0, 1, 2, 3]:
        return resjson.print_json(resjson.PARAM_ERROR)
    
    if is_img not in [0 ,1]:
        return resjson.print_json(resjson.PARAM_ERROR)

    dataIndex = CommentStaticMethodsService.index_page(request.args)
    data = CommentStaticMethodsService.comments(params)

    data['rating_1_count'] = dataIndex['rating_1_count']
    data['rating_2_count'] = dataIndex['rating_2_count']
    data['rating_3_count'] = dataIndex['rating_3_count']
    data['img_count'] = dataIndex['img_count']

    return resjson.print_json(0, u'ok', data)
Exemple #28
0
    def check(self):
        """检查"""

        # 检查 - 支付订单ID列表数据
        self.order_id_list = [toint(order_id)
                              for order_id in self.order_id_list]
        if len(self.order_id_list) <= 0:
            self.msg = _(u'支付订单ID列表不能为空')
            return False

        # 格式化支付订单ID列表数据
        self.order_id_list.sort()
        self.order_id_json = json.dumps(self.order_id_list)

        # 支付订单列表
        q = db.session.query(Order.order_id,
                             Order.order_sn,
                             Order.pay_amount,
                             Order.order_type,
                             Order.uid).\
            filter(Order.uid == self.uid).\
            filter(Order.pay_status == 1).\
            filter(Order.order_id.in_(self.order_id_list))

        # 检查 - 支付订单列表是否有非法的订单
        if len(self.order_id_list) != get_count(q):
            self.msg = _(u'创建支付失败')
            return False

        # 支付订单列表
        self.pay_order_list = q.all()

        # 支付订单列表对应的交易
        self.tran = OrderTran.query.filter(OrderTran.uid == self.uid).\
            filter(OrderTran.order_id_list == self.order_id_json).first()
        if self.tran:
            # 检查交易是否已经支付
            if self.tran.pay_status == 2:
                self.msg = _(u'该订单已经支付过了')
                return False

            # 检查 - 支付订单列表
            if not self.check_order_list():
                return False

            return True

        # 检查 - 支付订单列表
        if not self.check_order_list():
            return False

        return True
Exemple #29
0
def apply():
    """申请售后"""
    resjson.action_code = 10

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

    wtf_form = AfterSalesForm()
    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 = toint(request.form.get('og_id', '0'))
    order_id = toint(request.form.get('order_id', '0'))
    quantity = toint(request.form.get('quantity', '0'))
    aftersales_type = toint(request.form.get('aftersales_type', '0'))
    deliver_status = toint(request.form.get('deliver_status', '0'))
    content = request.form.get('content', '').strip()
    img_data = request.form.get('img_data', '[]').strip()

    data = {
        'uid': uid,
        'order_id': order_id,
        'og_id': og_id,
        'quantity': quantity,
        'aftersales_type': aftersales_type,
        'deliver_status': deliver_status,
        'content': content,
        'img_data': img_data
    }
    ascs = AfterSalesCreateService(**data)
    if not ascs.check():
        return resjson.print_json(12, ascs.msg)

    aftersales_id = ascs.create()

    return resjson.print_json(0, u'ok', {'aftersales_id': aftersales_id})
Exemple #30
0
def index():
    """ 我的钱包 """

    resjson.action_code = 10

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

    args = request.args
    p = toint(args.get('p', '1'))
    ps = toint(args.get('ps', '10'))

    if p <= 0 or ps <= 0:
        return resjson.print_json(resjson.PARAM_ERROR)

    funds = Funds.query.filter(Funds.uid == uid).first()
    _data = FundsStaticMethodsService.details(uid, request.args.to_dict())

    data = {'funds': funds, 'details': _data['details']}
    log_info(data)
    return resjson.print_json(0, _(u'ok'), data)