コード例 #1
0
    def update(self):
        data = parameter_required(('paid', ))

        with db.auto_commit():
            productarea = ProductArea.query.filter(
                ProductArea.PAid == data.get('paid')).first_('专题已取消')
            if data.get('delete'):
                productarea.isdelete = True
                return Success('删除成功')
            if data.get('pastatus'):
                # if re.match(r'^-?\d+$', str(data.get('pastatus'))):
                if self._check_int(data.get('pastatus')):
                    # ProductAreaStatus.
                    try:
                        productarea.PAstatus = ProductAreaStatus(
                            int(data.get('pastatus'))).value
                    except Exception as e:
                        current_app.logger.info(
                            'pastatus {} 违法 error msg {}'.format(
                                data.get('pastatus'), e.args))
                        raise ParamsError('pastatus 参数违法')

            if data.get('pcid'):
                self._check_pcid(data.get('pcid'))
                productarea.PCid = data.get('pcid')
            if data.get('pasort'):
                productarea.PAsort = self._check_pasort(data.get('pasort'))
            if data.get('paimg'):
                productarea.PAimg = data.get('paimg')

        return Success('更新成功')
コード例 #2
0
 def create(self):
     data = parameter_required(('pcid', 'pasort', 'paimg'))
     self._check_pcid(data.get('pcid'))
     pasort = data.get('pasort')
     # assert isinstance(pasort, int), 'pasort 类型错误'
     if not isinstance(pasort, int):
         raise ParamsError('类型错误')
     pasort = self._check_pasort(pasort)
     productarea_instance = ProductArea.create({
         'PAid':
         str(uuid.uuid1()),
         'PCid':
         data.get('pcid'),
         'PAstatus':
         ProductAreaStatus.wait.value,
         'PAdesc':
         data.get('padesc'),
         'PAsort':
         pasort,
         'PAimg':
         data.get('paimg'),
     })
     with db.auto_commit():
         db.session.add(productarea_instance)
     return Success(data=productarea_instance.PAid)
コード例 #3
0
 def update_category(self):
     """更新/删除分类"""
     self._check_user(request.user.id)
     data = parameter_required(('mcid', 'mcname', 'mctype'))
     mcid, mctype, mcsort = data.get('mcid'), data.get(
         'mctype', 0), data.get('mcsort')
     mcisdelete = data.get('mcisdelete')
     category = MaterialCategory.query.filter_by_(
         MCid=mcid).frist_('要修改的分类不存在')
     if mctype == CategoryType.material.value:
         if mcid in [
                 'case_community', 'knowledge_classroom',
                 'disease_treatment', 'health_encyclopedia', 'hot_topic'
         ]:
             raise ParamsError('系统内置分类不允许更改')
         mcsort = self._check_sort(mctype, mcsort, category.MCparentid)
         if category.MClevel == 1:
             raise ParamsError('该层分类不允许修改')
     update_dict = {
         'MCname': data.get('mcname'),
         'MCsort': mcsort,
     }
     if category.MCparentid == 'hot_topic':
         update_dict['MCpicture'] = data.get('mcpicture')
         update_dict['MCdesc'] = data.get('mcdesc')
     with db.auto_commit():
         if mcisdelete:
             category.update({'isdelete': True})
         else:
             category.update(update_dict)
         db.session.add(category)
     return Success('修改成功', data=dict(MCid=mcid))
コード例 #4
0
 def approve_comment(self):
     """处理评论 置顶/删除/通过/驳回"""
     self._check_admin(request.user.id)
     data = parameter_required(('mcoid', 'operation'))
     mcoid = data.get('mcoid')
     operation = data.get('operation')
     if operation not in ['top', 'del', 'pass', 'reject']:
         raise ParamsError('operation参数错误')
     with db.auto_commit():
         mco = MaterialComment.query.filter_by_(
             MCOid=mcoid).first_('该评论不存在')
         if str(operation) == 'top':
             opt_dict = {'MCOistop': True}
             MaterialComment.query.filter(
                 MaterialComment.MTid == mco.MTid,
                 MaterialComment.MCOid != mco.MCOid,
                 MaterialComment.isdelete == False).update(
                     {'MCOistop': False})  # 只有一个置顶
         elif str(operation) == 'del':
             opt_dict = {'isdelete': True}
         elif str(operation) == 'pass':
             opt_dict = {'MCOstatus': MaterialCommentStatus.usual.value}
         else:
             opt_dict = {'MCOstatus': MaterialCommentStatus.reject.value}
         mco.update(opt_dict)
         db.session.add(mco)
     return Success('修改成功', data=dict(mcoid=mcoid))
コード例 #5
0
    def update(self):
        data = parameter_required(('gbid', ))
        gb = GroupBuying.query.filter(
            GroupBuying.isdelete == False,
            GroupBuying.GBid == data.get('gbid')).first_('该活动已删除')
        with db.auto_commit():
            starttime, endtime = self._check_time(
                data.get('starttime') or str(gb.GBstarttime),
                data.get('endtime') or str(gb.GBendtime))
            gb.GBendtime = endtime
            gb.GBstarttime = starttime
            gb.GBstatus = GroupBuyingStatus.wait_check.value
            if data.get('delete'):
                self._delete_gb(gb)

            if data.get('gbnum'):
                if not self._check_pint(data.get('gbnum')):
                    raise ParamsError('gbnum 格式错误')
                gb.GBnum = data.get('gbnum')
            if data.get('gbtimes'):
                if not self._check_pint(data.get('gbtimes')):
                    raise ParamsError('gbtimes 格式错误')
                gb.GBtimes = data.get('gbtimes')
            if data.get('prid') or data.get('gpfreight') or data.get(
                    'gpstocks') or data.get('skus'):
                self._update_groupbuying_product(data, gb)
        return Success('更新成功')
コード例 #6
0
ファイル: CCategory.py プロジェクト: shuaibinliu/bechiproject
 def update(self):
     """更新分类"""
     data = parameter_required(('pcid', 'pcdesc', 'pcname', 'pcpic'))
     pcdesc = data.get('pcdesc')
     pcname = data.get('pcname')
     pcpic = data.get('pcpic')
     parentpcid = data.get('parentpcid')
     pcsort = int(data.get('pcsort', 1))
     pctoppic = data.get('pctoppic')
     with db.auto_commit():
         current_category = ProductCategory.query.filter(
             ProductCategory.isdelete == False,
             ProductCategory.PCid == data.get('pcid')
         ).first_('分类不存在')
         pcsort = self._check_sort(current_category.PCtype, pcsort, parentpcid)
         if parentpcid:
             parent_cat = ProductCategory.query.filter(
                 ProductCategory.isdelete == False,
                 ProductCategory.PCid == parentpcid
             ).first_('指定上级目录不存在')
             current_category.PCtype = parent_cat.PCtype + 1
         else:
             current_category.PCtype = 1
         current_category.update({
             'PCname': pcname,
             'PCdesc': pcdesc,
             'ParentPCid': parentpcid,
             'PCsort': pcsort,
             'PCpic': pcpic,
             'PCtopPic': pctoppic
         }, null='not ignore')
         db.session.add(current_category)
     return Success('更新成功')
コード例 #7
0
ファイル: CCategory.py プロジェクト: shuaibinliu/bechiproject
    def create(self):
        data = parameter_required(('pcdesc', 'pcname', 'pcpic'))
        pcdesc = data.get('pcdesc')
        pcname = data.get('pcname')
        pcpic = data.get('pcpic')
        parentpcid = data.get('parentpcid')
        pcsort = data.get('pcsort', 1)
        if not isinstance(pcsort, int):
            raise ParamsError('pcsort 类型错误')

        if not parentpcid:
            pctype = 1
        else:
            # parent_catory = self._get_category_one(parentpcid, '指定父级目录不存在')
            parent_catory = ProductCategory.query.filter(
            ProductCategory.PCid == parentpcid, ProductCategory.isdelete == False).first_('指定父级目录不存在')
            pctype = parent_catory.PCtype + 1

        pcsort = self._check_sort(pctype, pcsort, parentpcid)

        with db.auto_commit() as s:

            category_instance = ProductCategory.create({
                'PCid': str(uuid.uuid4()),
                'PCtype': pctype,
                'PCname': pcname,
                'PCdesc': pcdesc,
                'ParentPCid': parentpcid,
                'PCpic': pcpic,
                'PCsort': pcsort,
                'PCtopPic': data.get('pctoppic')
            })
            s.add(category_instance)
        return Success('创建成功', {'pcid': category_instance.PCid})
コード例 #8
0
    def list_groupbuying(self):
        # 后台获取拼团商品
        data = parameter_required()
        gb_list = GroupBuying.query.filter(
            GroupBuying.isdelete == False).all_with_page()
        try:
            order, desc_asc = data.get('order_type',
                                       'time|desc').split('|')  # 排序方式
            order_enum = {
                'time': GroupBuying.GBstarttime,
                'sale_value': Products.PRsalesValue,
                'price': GroupbuyingProduct.GPprice,
            }
            assert order in order_enum and desc_asc in ['desc', 'asc'
                                                        ], 'order_type 参数错误'
        except Exception as e:
            raise e

        for gb in gb_list:
            gp = GroupbuyingProduct.query.filter(
                GroupbuyingProduct.GBid == gb.GBid,
                GroupbuyingProduct.isdelete == False).first()
            if not gp:
                current_app.logger.info('后台数据异常')
                raise SystemError
            product = Products.query.filter(
                Products.PRid == GroupbuyingProduct.PRid,
                Products.isdelete == False).first()
            self._fill_product(product, gp, gb)
            gb.fill('product', product)
            gb.fill('gbstatus_zh', GroupBuyingStatus(gb.GBstatus).zh_value)
            gb.fill('gbstatus_en', GroupBuyingStatus(gb.GBstatus).name)

        return Success(data=gb_list)
コード例 #9
0
 def send(self):
     """发货"""
     data = parameter_required(('omid', 'olcompany', 'olexpressno'))
     omid = data.get('omid')
     olcompany = data.get('olcompany')
     olexpressno = data.get('olexpressno')
     with self.strade.auto_commit() as s:
         s_list = []
         order_main_instance = s.query(OrderMain).filter_by_({
             'OMid': omid,
         }).first_('订单不存在')
         if order_main_instance.OMstatus != OrderMainStatus.wait_send.value:
             raise StatusError('订单状态不正确')
         if order_main_instance.OMinRefund is True:
             raise StatusError('商品在售后状态')
         s.query(LogisticsCompnay).filter_by_({
             'LCcode': olcompany
         }).first_('快递公司不存在')
         # 添加物流记录
         order_logistics_instance = OrderLogistics.create({
             'OLid':
             str(uuid.uuid4()),
             'OMid':
             omid,
             'OLcompany':
             olcompany,
             'OLexpressNo':
             olexpressno,
         })
         s_list.append(order_logistics_instance)
         # 更改主单状态
         order_main_instance.OMstatus = OrderMainStatus.wait_recv.value
         s_list.append(order_main_instance)
         s.add_all(s_list)
     return Success('发货成功')
コード例 #10
0
    def get_groupbuying_items(self):
        # now = datetime.datetime.now()
        data = parameter_required(('gbid', ))
        gb = GroupBuying.query.filter(
            GroupBuying.GBid == data.get('gbid'), GroupBuying.GBstatus ==
            GroupBuyingStatus.agree.value).first_('活动已结束')
        filter_args = {
            GroupbuyingItem.isdelete == False, GroupbuyingItem.GBid == gb.GBid
        }
        if not is_admin():
            filter_args.add(GroupbuyingItem.GIstatus ==
                            GroupbuyingItemStatus.underway.value)

        gi_list = GroupbuyingItem.query.filter(*filter_args).all()
        for gi in gi_list:
            gu_list = GroupbuyingUser.query.filter(
                GroupbuyingUser.isdelete == False,
                GroupbuyingUser.GIid == gi.GIid).all()
            gi.fill('gus', gu_list)
            gi.fill('gistatus_en', GroupbuyingItemStatus(gi.GIstatus).name)
            gi.fill('gistatus_zh', GroupbuyingItemStatus(gi.GIstatus).zh_value)
            end_time = gi.createtime + datetime.timedelta(days=1)
            gi.fill('countdown', self._get_timedelta(end_time))
            gi.fill('gbnum', gb.GBnum)
        return Success(data=gi_list)
コード例 #11
0
ファイル: CFile.py プロジェクト: shuaibinliu/bechiproject
 def upload_img(self):
     self.check_file_size()
     file = request.files.get('file')
     data = parameter_required()
     folder = self.allowed_folder(data.get('type'))
     if not file:
         raise ParamsError(u'上传有误')
     file_data = self._upload_file(file, folder)
     return Success('上传成功', data=file_data[0]).get_body(video_thum=file_data[1], video_dur=file_data[2], upload_type=file_data[3])
コード例 #12
0
    def resubmit_product(self):
        data = parameter_required(('prid', ))
        product = Products.query.filter(
            Products.isdelete == False,
            Products.PRid == data.get('prid')).first_('商品不存在')
        with db.auto_commit():
            product.PRstatus = ProductStatus.usual.value
            db.session.add(product)

        return Success('申请成功')
コード例 #13
0
 def confirm(self):
     """活动确认"""
     data = parameter_required(('gbid', ))
     gb = GroupBuying.query.filter(
         GroupBuying.GBid == data.get('gbid'),
         GroupBuying.isdelete == False, GroupBuying.GBstatus !=
         GroupBuyingStatus.agree.value).first_('已经确认')
     with db.auto_commit():
         gb.GBstatus = GroupBuyingStatus.agree.value
     return Success('确认活动成功')
コード例 #14
0
    def delete(self):
        data = parameter_required(('prids', ))
        prids = data.get('prids')
        if not isinstance(prids, list):
            raise ParamsError('prids 参数异常')

        with db.auto_commit():
            Products.query.filter(
                Products.isdelete == False,
                Products.PRid.in_(prids)).delete_(synchronize_session=False)
        return Success('删除成功')
コード例 #15
0
    def off_shelves(self):
        """下架"""
        data = parameter_required(('prids', ))
        if not isinstance(data.get('prids'), list):
            raise ParamsError('数据异常')

        with db.auto_commit():
            product = Products.query.filter(
                Products.PRid.in_(data.get('prids')),
                Products.isdelete == False).first_('商品不存在')
            product.PRstatus = ProductStatus.off_shelves.value
        return Success('下架成功')
コード例 #16
0
    def get_material(self):
        """获取素材"""
        args = parameter_required(('mtid', ))
        mtid = args.get('mtid')
        material = Material.query.filter_by_(MTid=mtid).first_('文章不存在或已删除')

        pictures = material.MTpicture
        pictures = json.loads(pictures) if pictures and isinstance(
            pictures, str) else None
        material.fill('mtpicture', pictures)

        videos = material.MTvideo
        videos = json.loads(videos) if videos and isinstance(videos,
                                                             str) else None
        material.fill('mtvideo', videos)

        comment_count = MaterialComment.query.filter_by_(
            MTid=mtid).count()  # todo 仅话题下有评论数 (参与)
        favorite_count = material.MTfakefavorite or MaterialFavorite.query.filter_by_(
            MTid=mtid).count()
        views_cout = material.MTfakeviews or material.MTviews

        material.fill('comment_count', comment_count)
        material.fill('favorite_count', favorite_count)
        material.fill('views_cout', views_cout)
        if common_user():
            user = self._check_user(request.user.id)
            is_favorite = bool(
                MaterialFavorite.query.filter_by_(MTid=mtid,
                                                  USid=user.USid).first())
            is_collection = bool(
                UserCollections.query.filter_by_(
                    UCScollectionid=mtid,
                    USid=user.USid,
                    UCStype=CollectionType.material.value).first())
        else:
            user = None
            is_favorite = False
            is_collection = False
        material.fill('is_favorite', is_favorite)
        material.fill('is_collection', is_collection)

        # 增加分类信息
        category = MaterialCategory.query.outerjoin(
            MaterialCategoryRelated,
            MaterialCategoryRelated.MCid == MaterialCategory.MCid).filter(
                MaterialCategoryRelated.isdelete == False,
                MaterialCategory.isdelete == False,
                MaterialCategoryRelated.MTid == material.MTid).all()
        material.fill('category', category)
        self.update_pageviews(mtid)  # 增加浏览量
        return Success('获取成功', data=dict(data=material))
コード例 #17
0
ファイル: CCategory.py プロジェクト: shuaibinliu/bechiproject
    def delete(self):
        data = parameter_required(('pcid', ))
        pcid = data.get('pcid')
        with db.auto_commit() as s:
            product_category_instance = s.query(ProductCategory).filter_by_({'PCid': pcid}).first_('该分类不存在')
            product_category_instance.isdelete = True
            s.add(product_category_instance)
            s.query(Products).filter_(Products.PCid == product_category_instance.PCid).update({
                'PRstatus': ProductStatus.off_shelves.value,
                'PCid': None
            }, synchronize_session=False)

        return Success('删除成功')
コード例 #18
0
    def list(self):
        """前台获取商品列表"""
        now = datetime.datetime.now()
        data = parameter_required()
        try:
            order, desc_asc = data.get('order_type',
                                       'time|desc').split('|')  # 排序方式
            order_enum = {
                'time': GroupBuying.GBstarttime,
                'sale_value': Products.PRsalesValue,
                'price': GroupbuyingProduct.GPprice,
            }
            assert order in order_enum and desc_asc in ['desc', 'asc'
                                                        ], 'order_type 参数错误'
        except Exception as e:
            raise e
        filter_set = {
            GroupBuying.isdelete == False,
        }
        if common_user():
            filter_set.add(
                GroupBuying.GBstatus == GroupBuyingStatus.agree.value)
            filter_set.add(GroupBuying.GBstarttime < now)
            filter_set.add(GroupBuying.GBendtime > now)

        product_order = order_enum.get(order)
        if desc_asc == 'desc':
            by_order = product_order.desc()
        else:
            by_order = product_order.asc()
        gblist = GroupBuying.query.join(
            GroupbuyingProduct,
            GroupbuyingProduct.GBid == GroupBuying.GBid).join(
                Products, Products.PRid == GroupbuyingProduct.PRid).filter(
                    *filter_set).order_by(by_order).all_with_page()
        product_list = []
        for gb in gblist:
            gp = GroupbuyingProduct.query.filter(
                GroupbuyingProduct.GBid == gb.GBid,
                GroupbuyingProduct.isdelete == False).first_('活动已结束')

            product = Products.query.filter(
                Products.PRid == gp.PRid,
                Products.isdelete == False,
                Products.PRstatus == ProductStatus.usual.value,
            ).first_('活动已结束')

            self._fill_product(product, gp, gb)
            product_list.append(product)

        return Success(data=product_list)
コード例 #19
0
ファイル: CFile.py プロジェクト: shuaibinliu/bechiproject
 def remove(self):
     data = parameter_required(('img_url', ))
     try:
         img_url = data.get('img_url')
         dirs = img_url.split('/')[-6:]
         name_shuffer = dirs[-1]
         name = name_shuffer.split('.')[0]
         if not 'anonymous' in name and request.user.id not in name:
             raise NotFound()
         path = os.path.join(current_app.config['BASEDIR'], '/'.join(dirs))
         os.remove(path)
     except Exception as e:
         raise NotFound()
     return Success(u'删除成功')
コード例 #20
0
 def list_dietitian(self):
     """营养师"""
     args = request.args.to_dict()
     mcid = args.get('mcid')
     if mcid:
         res = Dietitian.query.join(
             DietitianCategoryRelated,
             DietitianCategoryRelated.DTid == Dietitian.DTid).filter(
                 DietitianCategoryRelated.isdelete == False,
                 Dietitian.isdelete == False,
                 DietitianCategoryRelated.MCid == mcid).first()
     else:
         res = Dietitian.query.filter_by_(DTisrecommend=True).order_by(
             Dietitian.createtime.desc()).all()
     return Success('获取成功', dict(data=res))
コード例 #21
0
 def get_comment(self):
     args = parameter_required(('mtid', 'mcostatus'))
     mtid = args.get('mtid')
     mcostatus = args.get('mcostatus', )
     ms = MaterialComment.query.filter_(
         MaterialComment.MTid == mtid,
         MaterialComment.MCOstatus == getattr(MaterialCommentStatus,
                                              mcostatus).value,
         MaterialComment.isdelete == False).order_by(
             MaterialComment.MCOistop.desc(),
             MaterialComment.createtime.desc()).all()
     for mc in ms:
         mc.fill('mcostatus_zh',
                 getattr(MaterialCommentStatus, mc.MCOstatus).zh_value)
     return Success('获取成功', data=dict(data=ms))
コード例 #22
0
 def del_search_history(self):
     """清空当前搜索历史"""
     if not is_tourist():
         data = parameter_required(('shtype', ))
         shtype = data.get('shtype')
         if shtype not in ['product', 'news']:
             raise ParamsError('shtype, 参数错误')
         shtype = getattr(UserSearchHistoryType, shtype, 'product').value
         usid = request.user.id
         with db.auto_commit() as s:
             s.query(UserSearchHistory).filter_by({
                 'USid': usid,
                 'USHtype': shtype
             }).delete_()
     return Success('删除成功')
コード例 #23
0
 def guess_search(self):
     """推荐搜索"""
     data = parameter_required(('kw', 'shtype'))
     shtype = data.get('shtype')
     if shtype not in ['product', 'news']:
         raise ParamsError('shtype, 参数错误')
     shtype = getattr(UserSearchHistoryType, shtype, 'product').value
     kw = data.get('kw').strip()
     if not kw:
         raise ParamsError()
     search_words = UserSearchHistory.query.filter(
         UserSearchHistory.USHtype == shtype,
         UserSearchHistory.USHname.like(kw + '%'),
     ).order_by(UserSearchHistory.createtime.desc()).all_with_page()
     [sw.hide('USid', 'USHid') for sw in search_words]
     return Success(data=search_words)
コード例 #24
0
    def join(self):
        """用户加入拼团"""
        user = get_current_user()
        data = parameter_required(('giid', ))
        gu = GroupbuyingUser.query.join(
            GroupbuyingItem,
            GroupbuyingItem.GIid == GroupbuyingUser.GIid).filter(
                GroupbuyingItem.isdelete == False,
                GroupbuyingUser.isdelete == False, GroupbuyingItem.GIstatus ==
                GroupbuyingItemStatus.underway.value,
                GroupbuyingUser.USid == user.USid,
                GroupbuyingUser.GIid == data.get('giid')).first()
        if gu:
            raise ParamsError('账号已经在队伍里了')
        gi = GroupbuyingItem.query.filter(
            GroupbuyingItem.isdelete == False,
            GroupbuyingItem.GIid == data.get('giid')).first_('该拼团已结束')
        now = datetime.datetime.now()
        gb = GroupBuying.query.filter(
            GroupBuying.GBstarttime <= now, GroupBuying.GBendtime >= now,
            GroupBuying.GBid == gi.GBid,
            GroupBuying.isdelete == False).first_('活动已结束')
        gus = GroupbuyingUser.query.filter(
            GroupbuyingUser.GIid == gi.GIid,
            GroupbuyingUser.isdelete == False).all()

        if len(gus) >= int(gb.GBnum):
            raise ParamsError('队伍已经满了,选择另外一个队伍吧')
        # gu_times = GroupbuyingUser.query.join(GroupbuyingItem, GroupbuyingItem.GIid == GroupbuyingUser.GIid).join(
        #     GroupBuying, GroupBuying.GBid == GroupbuyingItem.GBid).filter(
        #     GroupbuyingUser.USid == user.USid, GroupBuying.GBid == data.get('gbid')).count()
        # if gu_times >= gb.GBtimes:
        #     raise ParamsError('超过限购次数')
        self._check_bgtimes(gb.GBid, user.USid, gb.GBtimes)
        with db.auto_commit():
            gu = GroupbuyingUser.create({
                'GUid': str(uuid.uuid1()),
                'GIid': data.get('giid'),
                'USid': user.USid,
                'UShead': user.USheader,
                'USname': user.USname
            })
            db.session.add(gu)
            if int(gb.GBnum) - len(gus) == 1:
                gi.GIstatus = GroupbuyingItemStatus.success.value

        return Success('加入成功')
コード例 #25
0
 def search_history(self):
     """"搜索历史"""
     if not is_tourist():
         args = parameter_required(('shtype', ))
         shtype = args.get('shtype')
         if shtype not in ['product', 'news']:
             raise ParamsError('shtype, 参数错误')
         shtype = getattr(UserSearchHistoryType, shtype, 'product').value
         usid = request.user.id
         search_history = UserSearchHistory.query.filter(
             UserSearchHistory.USid == usid,
             UserSearchHistory.USHtype == shtype,
             UserSearchHistory.isdelete == False,
         ).order_by(UserSearchHistory.createtime.desc()).all_with_page()
     else:
         search_history = []
     return Success(data=search_history)
コード例 #26
0
ファイル: CCategory.py プロジェクト: shuaibinliu/bechiproject
    def get(self):
        data = parameter_required()
        up = data.get('up') or None
        deep = data.get('deep', 0)  # 深度
        # pctype = 1 if not up else None
        # categorys = self.sproduct.get_categorys({'ParentPCid': up, 'PCtype': pctype})
        filter_args = {
            ProductCategory.isdelete == False
        }
        if up:
            filter_args.add(ProductCategory.ParentPCid == up)
        else:
            filter_args.add(ProductCategory.PCtype == 1)

        categorys = ProductCategory.query.filter(*filter_args).all()
        for category in categorys:
            self._sub_category(category, deep)
        return Success(data=categorys)
コード例 #27
0
 def create_category(self):
     """创建分类"""
     self._check_admin(request.user.id)
     data = parameter_required((
         'mcname',
         'mctype',
     ))
     mctype = data.get('mctype', 0)
     mcsort = data.get('mcsort')
     mcparentid = data.get('mcparentid')
     with db.auto_commit():
         if mctype == CategoryType.material.value:
             if not mcparentid:
                 raise ParamsError('mcparentid 不能为空')
             parent_category = MaterialCategory.query.filter_by_(
                 MCid=mcparentid).first_('上级分类不存在')
             if parent_category.MCid == 'knowledge_classroom':
                 raise ParamsError('不允许在该层下创建分类')  # 知识课堂下不允许创建二级分类
             mcsort = self._check_sort(mctype, mcsort, mcparentid)
             category_dict = {
                 'MCid': str(uuid.uuid1()),
                 'MCname': data.get('mcname'),
                 'MCparentid': mcparentid,
                 'MClevel': parent_category.MClevel + 1,
                 'MCsort': mcsort,
                 'MCtype': mctype
             }
             if category_dict['MClevel'] > 3:
                 raise ParamsError('超出分类最高层级')
             if mcparentid == 'hot_topic':  # 热门话题有简介 和 图片
                 category_dict['MCpicture'] = data.get('mcpicture')
                 category_dict['MCdesc'] = data.get('mcdesc')
         else:
             category_dict = {
                 'MCid': str(uuid.uuid1()),
                 'MCname': data.get('mcname'),
                 'MClevel': 1,
                 'MCsort': mcsort,
                 'MCtype': mctype
             }
         category_instance = MaterialCategory.create(category_dict)
         db.session.add(category_instance)
     return Success('创建成功', data=dict(MCid=category_dict['MCid']))
コード例 #28
0
 def list_category(self):
     """素材库分类"""
     args = request.args.to_dict()
     mctype = args.get('mctype', 0) or 0
     categorys = MaterialCategory.query.filter(
         MaterialCategory.isdelete == False,
         MaterialCategory.MCtype == mctype,
         MaterialCategory.MCparentid.is_(None)).order_by(
             MaterialCategory.MCsort.asc(),
             MaterialCategory.createtime.desc()).all()
     for category in categorys:
         subs = self._sub_category(category.MCid, mctype)
         if subs:
             category.fill('sub', subs)
             for sub in subs:
                 sb = self._sub_category(sub.MCid, mctype)
                 if sb:
                     sub.fill('sub', sb)
     return Success('获取成功', data=categorys)
コード例 #29
0
ファイル: CFile.py プロジェクト: shuaibinliu/bechiproject
 def batch_upload(self):
     self.check_file_size()
     files = request.files.to_dict()
     if len(files) > 9:
         raise ParamsError('最多可同时上传9张图片')
     # todo 视频数量限制
     data = parameter_required()
     folder = self.allowed_folder(data.get('type'))
     file_url_list = []
     for file in files.values():
         upload_file = self._upload_file(file, folder)
         file_dict = {
             'file_url': upload_file[0],
             'video_thum': upload_file[1],
             'video_dur': upload_file[2],
             'upload_type': upload_file[3]
         }
         file_url_list.append(file_dict)
     return Success('上传成功', file_url_list)
コード例 #30
0
    def start(self):
        """用户发起拼团"""
        # data = parameter_required(('prid', ))
        user = get_current_user()
        now = datetime.datetime.now()
        # now = datetime.datetime.now()
        data = parameter_required(('gbid', ))

        gb = GroupBuying.query.filter(
            GroupBuying.GBstarttime <= now, GroupBuying.GBendtime >= now,
            GroupBuying.GBid == data.get('gbid'),
            GroupBuying.isdelete == False).first_('活动已结束')
        self._check_bgtimes(data.get('gbid'), user.USid, gb.GBtimes)

        with db.auto_commit():
            gi = GroupbuyingItem.create({
                'GIid':
                str(uuid.uuid1()),
                'GBid':
                gb.GBid,
                'GIstatus':
                GroupbuyingItemStatus.underway.value
            })
            gu = GroupbuyingUser.create({
                'GUid':
                str(uuid.uuid1()),
                'GIid':
                gi.GIid,
                'USid':
                user.USid,
                'UShead':
                user.USheader,
                'USname':
                user.USname,
                'GUstatus':
                GroupbuyingUserStatus.waitpay.value
            })
            # TODO 异步任务,24h 修改超时状态
            db.session.add(gi)
            db.session.add(gu)

        return Success('发起拼团成功')