示例#1
0
    def check(self):
        """ 检查 """

        # 商品主图
        _goods_img = request.files.get('goods_img', None)

        # 商品相册
        _gallery_list = request.files.getlist('gallery')

        # 筛选属性
        _attr_id_list = request.form.getlist('attr_id')
        _attr_id_list = list(set(_attr_id_list))

        # SKU
        _sku_list          = request.form.getlist('sku')
        _sku_name_list     = request.form.getlist('sku_name')
        _sku_price_list    = request.form.getlist('sku_price')
        _sku_quantity_list = request.form.getlist('sku_quantity')

        # 是否创建商品
        self.is_new = True if self.goods_id == 0 else False

        # 检查 - 必填项
        required_arr = ['goods_name', 'is_sale', 'is_hot', 'is_pre', 'is_new', 'goods_price', 'is_free_shipping', 'is_return']
        for key in required_arr:
            value = self.form.get(key, '').strip()
            if not value:
                self.errmsg[key] = u'必填项'

        # 检查 - 新建商品是否上传商品主图
        if self.is_new and not _goods_img:
            self.errmsg['goods_img'] = u'必填项'

        gc_id = toint(self.form.get('gc_id', '0'))
        if gc_id <= 0:
            self.errmsg['gc_id'] = u'必填项'

        # 检查 - 商品是否存在
        if not self.is_new:
            self.goods = Goods.get(self.goods_id)
            if not self.goods:
                self.errmsg['submit'] = u'商品不存在'

        # 检查 - 商品主图是否合法
        if _goods_img:
            oss = AliyunOSS('goods', current_app.config['SAVE_TARGET_PATH'])
            try:
                oss.save(_goods_img)
                self.goods_img = oss.put_to_oss()
            except UploadNotAllowed, e:
                self.errmsg['goods_img'] = u'商品图片只允许是图片文件'
            except Exception, e:
                self.errmsg['goods_img'] = u'商品图片上传失败'
示例#2
0
def sort_modify():
    """修改排序"""

    goods_id = toint(request.args.get('goods_id', '0'))
    new_sort = toint(request.args.get('new_sort', '0'))
    new_sort = new_sort if new_sort > 0 else -1

    if new_sort < 0:
        return u'只能输入大于0的数字'

    if new_sort > 10000000:
        return u'数字不能过大'

    if goods_id <= 0:
        return u'参数出错'

    goods_info = Goods.get(goods_id)

    if goods_info:
        goods_info.sort_order = new_sort
        db.session.commit()

    return u'ok'
示例#3
0
def add_news_goods():
    """新增资讯商品"""
    """
    goods_id     = toint(request.args.get('goods_id', '0'))
    news_id      = toint(request.args.get('news_id', '0'))
    redirect_url = request.args.get('redirect_url', None)
    if goods_id <= 0 or news_id <=0:
        return u'参数出错'

    goods = Goods.query.get_or_404(goods_id)
    news  = News.query.get_or_404(news_id)
    if not goods:
        return u'新增资讯商品不存在'

    if not news:
        return u'找不到资讯'

    ng_info = NewsGoods.query.filter(NewsGoods.news_id == news_id).\
                filter(NewsGoods.goods_id == goods_id).first()

    if ng_info:
        return u'资讯商品已经存在,无需增加。'

    ng = NewsGoods()
    ng.goods_id = goods_id
    ng.news_id  = news_id
    ng.add_time = int(time.time())
    db.session.add(ng)
    db.session.commit()

    if redirect_url:
        return redirect(url_for('news.news_edit',news_id=news_id, redirect_url=redirect_url))
    return u'ok'
    """
    resjson.action_code = 10

    goods_id = toint(request.form.get('goods_id', 0))
    news_id = toint(request.form.get('news_id', 0))
    extend = request.form.get('extend', '')

    if goods_id <= 0 or news_id <= 0:
        return resjson.print_json(10, u'参数错误')

    goods = Goods.get(goods_id)
    if not goods:
        return resjson.print_json(11, u'找不到商品')

    news = News.get(news_id)
    if not news:
        return resjson.print_json(12, u'找不到资讯')

    news_goods = NewsGoods.query.filter(NewsGoods.news_id == news_id).filter(
        NewsGoods.goods_id == goods_id).first()
    if news_goods:
        return resjson.print_json(13, u'资讯的商品已经存在')

    NewsGoods.create(news_id=news_id,
                     goods_id=goods_id,
                     extend=extend,
                     add_time=current_timestamp(),
                     commit=True)

    return resjson.print_json(0, u'ok')
示例#4
0
        # 如果修改的达到开奖人次数量比之前的大就增加一元云购号码池表数据
        if diff_finish_quantity > 0:
            for diff in range(diff_finish_quantity):
                lottery_number += 1
                LotteryNumberPool.create(lottery_id=lottery_info.lottery_id,
                                         lottery_number=lottery_number)

    # 如果修改的达到开奖人次数量比之前的小就删除一元云购号码池表数据
    # if diff_finish_quantity < 0:
    #     for diff in range(abs(diff_finish_quantity)):
    #         max_lottery_number_list=db.session.query(func.max(LotteryNumberPool.lottery_number)).\
    #                                 filter(LotteryNumberPool.lottery_id == lottery_info.lottery_id).all()
    #         max_lottery_number = LotteryNumberPool.query.filter(LotteryNumberPool.lottery_number.in_([toint(lnp) for lnp in max_lottery_number_list])).first()
    #         if max_lottery_number:
    #             db.session.delete(max_lottery_number)
    goods = Goods.get(goods_id)
    lottery_info.update(
        section_number=section_number,
        goods_id=goods_id,
        lottery_img=lottery_img if lottery_img else lottery_info.lottery_img,
        lottery_price=lottery_price,
        max_quantity=max_quantity,
        finish_quantity=finish_quantity,
        lottery_name=lottery_name if lottery_name else goods.goods_name,
        commit=True)

    return redirect(url_for('lottery.index'))


@lottery.route('/number')
@lottery.route('/number/<int:page>')