コード例 #1
0
    def cancel_apply(self):
        """取消申请"""
        if is_supplizer():
            sup = Supplizer.query.filter_by_(SUid=request.user.id).first_("账号状态错误")
        else:
            raise AuthorityError()
        data = parameter_required(('gpid',))
        with db.auto_commit():
            gp = GroupGoodsProduct.query.filter(GroupGoodsProduct.GPid == data.get('gpid'),
                                                GroupGoodsProduct.isdelete == False,
                                                GroupGoodsProduct.GPstatus == ApplyStatus.wait_check.value
                                                ).first_("只有待审核状态下的申请可以撤销")
            if gp.SUid != sup.SUid:
                raise AuthorityError("只能撤销属于自己的申请")
            gp.update({'GPstatus': ApplyStatus.cancle.value})
            db.session.add(gp)
            # 返回库存
            product = Products.query.filter_by(PRid=gp.PRid, isdelete=False).first_('商品信息出错')
            gps_old = GroupGoodsSku.query.filter(GroupGoodsSku.GPid == gp.GPid,
                                                 GroupGoodsSku.isdelete == False,
                                                 ).all()
            for sku in gps_old:
                sku_instance = ProductSku.query.filter_by(isdelete=False, PRid=product.PRid,
                                                          SKUid=sku.SKUid).first_('商品sku信息不存在')
                super(CGuessGroup, self)._update_stock(int(sku.GSstock), product, sku_instance)

            # 同时取消正在进行的审批流
            Approval.query.filter_by(AVcontent=gp.GPid, AVstartid=sup.SUid,
                                     isdelete=False, AVstatus=ApplyStatus.wait_check.value
                                     ).update({'AVstatus': ApplyStatus.cancle.value})
        return Success('已取消申请', {'gpid': gp.GPid})
コード例 #2
0
 def offshelves(self):
     current_app.logger.info('下架供应商')
     data = parameter_required(('suid', ))
     suid = data.get('suid')
     with db.auto_commit():
         supplizer = Supplizer.query.filter(
             Supplizer.isdelete == False,
             Supplizer.SUid == suid).first_('供应商不存在')
         supplizer.SUstatus = UserStatus.forbidden.value
         db.session.add(supplizer)
         BASEADMIN().create_action(AdminActionS.update.value, 'Supplizer',
                                   suid)
         # 供应商的品牌也下架
         brand_count = ProductBrand.query.filter(
             ProductBrand.isdelete == False,
             ProductBrand.PBstatus == ProductBrandStatus.upper.value,
             ProductBrand.SUid == suid).update(
                 {'PBstatus': ProductBrandStatus.off_shelves.value})
         current_app.logger.info('共下架了 {}个品牌'.format(brand_count))
         # 供应商的商品下架
         products_count = Products.query.filter(
             Products.isdelete == False,
             Products.PRstatus != ProductStatus.off_shelves.value,
             Products.CreaterId == suid).update({
                 'PRstatus':
                 ProductStatus.off_shelves.value,
             })
         current_app.logger.info('共下架了 {}个商品'.format(products_count))
     return Success('供应商下架成功')
コード例 #3
0
ファイル: CFile.py プロジェクト: shuaibinliu/python_planet
 def batch_upload(self):
     if is_tourist():
         current_app.logger.info(">>>  Tourist Bulk Uploading Files  <<<")
     else:
         current_app.logger.info(">>>  {} Bulk Uploading Files  <<<".format(
             request.user.model))
     self.check_file_size()
     files = request.files.to_dict()
     current_app.logger.info(">>> Uploading {} Files  <<<".format(
         len(files)))
     if len(files) > 30:
         raise ParamsError('最多可同时上传30张图片')
     # 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 = {
             'data': 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)
コード例 #4
0
ファイル: CTicket.py プロジェクト: haobin12358/python_planet
 def set_award(self):
     """设置中奖"""
     data = parameter_required('tsoid')
     tsoid = data.get('tsoid')
     ticket_order = TicketsOrder.query.filter(TicketsOrder.isdelete == false(),
                                              TicketsOrder.TSOid == tsoid,
                                              TicketsOrder.TSOstatus == TicketsOrderStatus.pending.value
                                              ).first_('状态错误')
     ticket = Ticket.query.filter(Ticket.isdelete == false(), Ticket.TIid == ticket_order.TIid).first()
     if not ticket or ticket.TIstatus != TicketStatus.over.value:
         raise ParamsError('抢票尚未结束')
     award_num = self._query_award_num(ticket.TIid)
     current_app.logger.info('已中奖数:{} / {}'.format(award_num, ticket.TInum))
     if award_num >= ticket.TInum:
         raise StatusError('已达最大发放票数')
     with db.auto_commit():
         update_dict = {'TSOqrcode': 'https://play.bigxingxing.com/img/qrcode/2019/9/3/QRCODE.png',
                        'TSOstatus': TicketsOrderStatus.has_won.value}
         if ticket.TIdeposit == ticket.TIprice:  # 第二次支付押金0元的情况
             update_dict['TSOstatus'] = TicketsOrderStatus.completed.value
         ticket_order.update(update_dict)
         db.session.add(ticket_order)
         db.session.flush()
         awarded_num = self._query_award_num(ticket.TIid)
         current_app.logger.info('设置后中奖数:{} / {}'.format(awarded_num, ticket.TInum))
         if awarded_num == ticket.TInum:  # 未中奖退钱
             other_to = self._query_not_won(ticket.TIid)
             total_row_count = 0
             for oto in other_to:
                 row_count = self._deposit_refund(oto)
                 total_row_count += row_count
             current_app.logger.info('共{}条未中奖'.format(total_row_count))
     return Success('设置成功', data=tsoid)
コード例 #5
0
 def update(self):
     """更新购物车"""
     data = parameter_required(('caid', ))
     caid = data.get('caid')
     usid = request.user.id
     card = self.scart.get_card_one({'CAid': caid, 'USid': usid}, error='购物车不存在')  # card就是cart.
     # 默认的sku和数量
     skuid = data.get('skuid') or card.SKUid
     try:
         num = int(data.get('canums', card.CAnums))
         if num < 0:
             raise TypeError()
     except TypeError as e:
         raise ParamsError('num类型错误')
     msg = '更新成功'
     with self.scart.auto_commit() as session:
         # 数量为0执行删除
         if num == 0:
             session.query(Carts).filter_by({'CAid': caid}).delete_()
             msg = '删除成功'
         else:
             session.query(ProductSku).filter_by_({'SKUid': skuid}).first_('商品sku不存在')
             session.query(Carts).filter_by({'CAid': caid}).update({
                 'SKUid': skuid,
                 'CAnums': num
             })
     return Success(msg)
コード例 #6
0
 def shelves(self):
     """批量下架试用商品"""
     if is_supplizer():
         usid = request.user.id
         sup = self._check_supplizer(usid)
         current_app.logger.info('Supplizer {} shelves commodity'.format(
             sup.SUname))
     elif is_admin():
         usid = request.user.id
         admin = self._check_admin(usid)
         current_app.logger.info('Admin {} shelves commodity'.format(
             admin.ADname))
         sup = None
     else:
         raise AuthorityError()
     data = parameter_required(("tcids", ))
     tcid_list = data.get('tcids')
     for tcid in tcid_list:
         commodity = TrialCommodity.query.filter_by_(
             TCid=tcid).first_('未找到商品信息, tcid参数异常')
         if sup:
             assert commodity.CreaterId == usid, '供应商只能下架自己上传的商品'
         if commodity.TCstatus != TrialCommodityStatus.upper.value:
             raise StatusError('只能下架正在上架状态的商品')
         with db.auto_commit():
             commodity.TCstatus = TrialCommodityStatus.reject.value
     return Success('下架成功', {'tcid': tcid_list})
コード例 #7
0
 def del_commodity(self):
     """删除试用商品"""
     if is_supplizer():
         usid = request.user.id
         sup = self._check_supplizer(usid)
         current_app.logger.info('Supplizer {} delete commodity'.format(
             sup.SUname))
     elif is_admin():
         usid = request.user.id
         admin = self._check_admin(usid)
         current_app.logger.info('Admin {} delete commodity'.format(
             admin.ADname))
         sup = None
     else:
         raise AuthorityError()
     data = parameter_required(("tcid", ))
     tcid = data.get('tcid')
     commodity = TrialCommodity.query.filter_by_(
         TCid=tcid).first_('未找到商品信息, tcid参数异常')
     if sup:
         assert commodity.CreaterId == usid, '供应商只能删除自己上传的商品'
     if commodity.TCstatus not in [
             TrialCommodityStatus.reject.value,
             TrialCommodityStatus.cancel.value
     ]:
         raise StatusError('只能删除已下架或已撤销的商品')
     with db.auto_commit():
         TrialCommodity.query.filter_by(TCid=tcid).delete_()
         TrialCommodityImage.query.filter_by(TCid=tcid).delete_()
         TrialCommoditySku.query.filter_by(TCid=tcid).delete_()
         TrialCommoditySkuValue.query.filter_by(TCid=tcid).delete_()
     return Success('删除成功', {'tcid': tcid})
コード例 #8
0
    def delete_questoutline(self):
        """后台管理员删除问题分类"""
        if not is_admin():
            raise AuthorityError('权限不足')
        admin = Admin.query.filter_by_(ADid=request.user.id).first_('权限已被回收')
        data = parameter_required(('qolist', ))
        qolist = data.get('qolist')
        for qoid in qolist:
            qomodel = QuestOutline.query.filter_by_(QOid=qoid).first()
            if not qomodel:
                continue
            qomodel.isdelete = True
            qulist = Quest.query.filter_by_(QOid=qoid).all()
            for qu in qulist:
                qu.isdelete = True
                qalist = Answer.query.filter_by_(QUid=qu.QUid).all()
                for qa in qalist:
                    qa.isdelete = True

            qan = QuestAnswerNote.create({
                'QANid': str(uuid.uuid1()),
                'QANcontent': '删除问题分类',
                'QANcreateid': admin.ADid,
                'QANtargetId': qoid
            })
            db.session.add(qan)
            BASEADMIN().create_action(AdminActionS.delete.value,
                                      'QuestAnswerNote', str(uuid.uuid1()))
        return Success('删除完成')
コード例 #9
0
ファイル: CSku.py プロジェクト: haobin12358/python_planet
 def update(self):
     data = parameter_required(('skuid', ))
     skuid = data.get('skuid')
     price = data.get('skuprice')
     stock = data.get('skustock')
     if price:
         if price < 0:
             raise ParamsError('价格小于0')
         price = round(price, 2)
     if stock and stock < 0:
         raise ParamsError('库存小于0')
     skuattritedetail = data.get('skuattritedetail')
     with self.sproduct.auto_commit() as s:
         sku = s.query(ProductSku).filter_by_({
             'SKUid': skuid
         }).first_('sku不存在')
         product = self.sproduct.get_product_by_prid(sku.PRid)
         prattribute = json.loads(product.PRattribute)
         if len(skuattritedetail) != len(prattribute) or not isinstance(
                 skuattritedetail, list):
             raise ParamsError('skuattritedetail 参数不准确')
         skuattritedetail = json.dumps(skuattritedetail)
         sku_dict = {
             'SKUpic': data.get('skupic'),
             'SKUprice': price,
             'SKUstock': stock,
             'SKUattriteDetail': skuattritedetail,
         }
         [setattr(sku, k, v) for k, v in sku_dict.items() if v is not None]
         s.add(sku)
         if is_admin():
             BASEADMIN().create_action(AdminActionS.update.value,
                                       'ProductSku', skuid)
     return Success('更新成功')
コード例 #10
0
ファイル: CIndex.py プロジェクト: haobin12358/python_planet
 def get_linkcontent(self):
     data = parameter_required('lcid')
     lcid = data.get('lcid')
     lc = LinkContent.query.filter_by(LCid=lcid, isdelete=False).first()
     if not lc:
         raise ParamsError('链接失效')
     return Success(data=lc)
コード例 #11
0
 def delete(self):
     """删除申请"""
     # if is_supplizer():
     #     usid = request.user.id
     #     sup = Supplizer.query.filter_by_(SUid=usid).first_('供应商信息错误')
     #     suid = sup.SUid
     #     current_app.logger.info('Supplizer {} delete integral apply'.format(sup.SUname))
     if is_admin():
         usid = request.user.id
         admin = Admin.query.filter_by_(ADid=usid).first_('管理员信息错误')
         current_app.logger.info('Admin {} delete integral apply'.format(
             admin.ADname))
         sup = None
         suid = None
     else:
         raise AuthorityError()
     data = parameter_required(('ipid', ))
     ipid = data.get('ipid')
     with db.auto_commit():
         apply_info = IntegralProduct.query.filter_by(
             IPid=ipid, isdelete=False).first_('没有该商品记录')
         if sup and apply_info.SUid != suid:
             raise ParamsError('只能删除自己提交的申请')
         if apply_info.IPstatus not in [
                 ApplyStatus.cancle.value, ApplyStatus.reject.value,
                 ApplyStatus.shelves.value
         ]:
             raise StatusError('只能删除已下架或已撤销状态下的申请')
         apply_info.isdelete = True
         IntegralProductSku.query.filter(
             IntegralProductSku.IPid == apply_info.IPid).delete_()
         if is_admin():
             BASEADMIN().create_action(AdminActionS.delete.value,
                                       'IntegralProduct', apply_info.IPid)
     return Success('删除成功', {'ipid': ipid})
コード例 #12
0
ファイル: CIndex.py プロジェクト: haobin12358/python_planet
 def set_mp_banner(self):
     """小程序轮播图"""
     data = parameter_required(('mpbpicture',))
     mpbid = data.get('mpbid')
     mpb_dict = {'MPBpicture': data.get('mpbpicture'),
                 'MPBsort': data.get('mpbsort'),
                 'MPBshow': data.get('mpbshow'),
                 'MPBposition': data.get('mpbposition'),
                 'contentlink': data.get('contentlink')}
     with db.auto_commit():
         if not mpbid:
             mpb_dict['MPBid'] = str(uuid.uuid1())
             mpb_dict['ADid'] = getattr(request, 'user').id
             mpb_instance = MiniProgramBanner.create(mpb_dict)
             BASEADMIN().create_action(AdminActionS.insert.value, 'MiniProgramBanner', mpb_instance.MPBid)
             msg = '添加成功'
         else:
             mpb_instance = MiniProgramBanner.query.filter_by_(MPBid=mpbid).first_('未找到该轮播图信息')
             if data.get('delete'):
                 mpb_instance.update({'isdelete': True})
                 BASEADMIN().create_action(AdminActionS.delete.value, 'MiniProgramBanner', mpb_instance.MPBid)
                 msg = '删除成功'
             else:
                 mpb_instance.update(mpb_dict, null='not')
                 BASEADMIN().create_action(AdminActionS.update.value, 'MiniProgramBanner', mpb_instance.MPBid)
                 msg = '编辑成功'
         db.session.add(mpb_instance)
     return Success(message=msg, data={'mpbid': mpb_instance.MPBid})
コード例 #13
0
 def off_shelves(self):
     """上下架"""
     data = parameter_required(('pbid', ))
     pbid = data.get('pbid')
     pbstatus = data.get('pbstatus', 'up')
     with self.sproduct.auto_commit() as s:
         product_brand_instance = s.query(ProductBrand).filter_by_({
             'PBid':
             pbid
         }).first_('品牌不存在')
         s_list = []
         if pbstatus == 'up':
             # 上架
             product_brand_instance.PBstatus = ProductBrandStatus.upper.value
             s_list.append(product_brand_instance)
             msg = '上架成功'
         else:
             # 下架品牌
             product_brand_instance.PBstatus = ProductBrandStatus.off_shelves.value
             s_list.append(product_brand_instance)
             # 下架商品
             s.query(Products).filter_by_({
                 'PBid': pbid
             }).update({'PRstatus': ProductStatus.off_shelves.value})
             msg = '下架成功'
         s.add_all(s_list)
     return Success(msg)
コード例 #14
0
    def collect(self):
        data = parameter_required(('uclcollection', 'uclcotype'))
        user = get_current_user()
        # crusid = user
        ctid = data.get('uclcollection')
        c = data.get('uclcotype', 0)
        try:
            c = CollectionType(c).value
        except:
            current_app.logger.info('get colletcion type {} error '.format(c))
            c = 0

        ctid = self._check_type_id(c, ctid)
        flag = UserCollectionLog.query.filter(
            UserCollectionLog.UCLcollector == user.USid,
            UserCollectionLog.UCLcoType == c,
            UserCollectionLog.UCLcollection == ctid,
            UserCollectionLog.isdelete == False).first()

        with db.auto_commit():
            if flag:
                flag.isdelete = True
                return Success('取消收藏成功')

            uin = UserCollectionLog.create({
                'UCLid': str(uuid.uuid1()),
                'UCLcollector': user.USid,
                'UCLcollection': ctid,
                'UCLcoType': c
            })
            db.session.add(uin)

            return Success('添加收藏成功')
コード例 #15
0
 def delete(self):
     data = parameter_required(('pcid', ))
     pcid = data.get('pcid')
     with self.sproduct.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)
         BASEADMIN().create_action(AdminActionS.delete.value,
                                   'ProductCategory', pcid)
         s.query(Products).filter_(
             Products.PCid == product_category_instance.PCid).update(
                 {
                     'PRstatus': ProductStatus.off_shelves.value,
                     'PCid': None
                 },
                 synchronize_session=False)
         # else:
         #     parent_catetgory_instance = s.query(ProductCategory).filter_by_({'PCid': parent_catetgory_id}).first_()
         #     if not parent_catetgory_instance:   # 父级目录已删除
         #         s.query(Products).filter_(Products.PCid.in_(sub_ids)).update({
         #             'PCid': 'null'
         #         }, synchronize_session=False)
         #     else:
         #         pass
         #         s.query(Products).filter_by_({
         #             'PCid': pcid
         #         }).update({
         #             'PCid': parent_catetgory_id
         #         }, synchronize_session=False)
     return Success('删除成功')
コード例 #16
0
ファイル: CExcel.py プロジェクト: haobin12358/python_planet
 def download(self):
     if not is_supplizer() and not is_admin():
         raise AuthorityError()
     args = parameter_required(('type', ))
     type = args.get('type')
     try:
         tp = getattr(ExcelTemplateType, type).value
     except Exception:
         raise ParamsError('type 参数错误')
     current_app.logger.info('start download template')
     template_path = os.path.join(current_app.config['BASEDIR'], 'img',
                                  'xls')
     current_app.logger.info('template path {}'.format(template_path))
     if tp:
         current_app.logger.info('is file {}'.format(
             os.path.isfile(
                 os.path.join(template_path, 'deliverytemplate.xlsx'))))
         return send_from_directory(template_path,
                                    'deliverytemplate.xlsx',
                                    as_attachment=True)
     current_app.logger.info('is file {}'.format(
         os.path.isfile(os.path.join(template_path, 'template.xlsx'))))
     return send_from_directory(template_path,
                                'template.xlsx',
                                as_attachment=True)
コード例 #17
0
 def cancel_commodity_apply(self):
     """撤销自己的申请"""
     if is_supplizer():
         usid = request.user.id
         sup = self._check_supplizer(usid)
         current_app.logger.info('Supplizer {} cancel commodity'.format(
             sup.SUname))
     elif is_admin():
         usid = request.user.id
         admin = self._check_admin(usid)
         current_app.logger.info('Admin {} cancel commodity'.format(
             admin.ADname))
     else:
         raise AuthorityError()
     data = parameter_required(('tcid', ))
     tcid = data.get('tcid')
     with db.auto_commit():
         commodity = TrialCommodity.query.filter_by_(
             TCid=tcid).first_('无此商品信息')
         if commodity.TCstatus != TrialCommodityStatus.auditing.value:
             raise StatusError('只有在审核状态的申请可以撤销')
         if commodity.CreaterId != request.user.id:
             raise AuthorityError('仅可撤销自己提交的申请')
         commodity.TCstatus = TrialCommodityStatus.cancel.value
         # 同时将正在进行的审批流改为取消
         approval_info = Approval.query.filter_by_(
             AVcontent=tcid,
             AVstartid=request.user.id,
             AVstatus=ApplyStatus.wait_check.value).first()
         approval_info.AVstatus = ApplyStatus.cancle.value
     return Success('取消成功', {'tcid': tcid})
コード例 #18
0
 def shelf_award(self):
     """撤销申请"""
     if not (is_supplizer() or is_admin()):
         raise AuthorityError()
     data = parameter_required(('mbaid', ))
     mbaid = data.get('mbaid')
     with db.auto_commit():
         apply_info = MagicBoxApply.query.filter_by_(
             MBAid=mbaid).first_('无此申请记录')
         other_apply_info = MagicBoxApply.query.filter(
             MagicBoxApply.isdelete == False,
             MagicBoxApply.MBAid != mbaid,
             MagicBoxApply.MBAstatus.notin_(
                 [ApplyStatus.cancle.value, ApplyStatus.reject.value]),
             MagicBoxApply.OSid == apply_info.OSid,
         ).first()
         current_app.logger.info("其他的同库存申请 --> {}".format(other_apply_info))
         if apply_info.MBAstatus != ApplyStatus.wait_check.value:
             raise StatusError('只有在审核状态的申请可以撤销')
         if apply_info.SUid != request.user.id:
             raise AuthorityError('仅可撤销自己提交的申请')
         apply_info.MBAstatus = ApplyStatus.cancle.value
         # 是否修改库存
         if not other_apply_info:
             out_stock = OutStock.query.filter(
                 OutStock.isdelete == False,
                 OutStock.OSid == apply_info.OSid).first()
             self._update_stock(out_stock.OSnum, skuid=apply_info.SKUid)
         # 同时将正在进行的审批流改为取消
         approval_info = Approval.query.filter_by_(
             AVcontent=mbaid,
             AVstartid=request.user.id,
             AVstatus=ApplyStatus.wait_check.value).first()
         approval_info.AVstatus = ApplyStatus.cancle.value
     return Success('取消成功', {'mbaid': mbaid})
コード例 #19
0
 def resubmit_apply(self):
     """重新提交申请"""
     if is_supplizer():
         usid = request.user.id
         sup = self._check_supplizer(usid)
         current_app.logger.info('Supplizer {} resubmit commodity'.format(
             sup.SUname))
         nefrom = ApplyFrom.supplizer.value
     elif is_admin():
         usid = request.user.id
         admin = self._check_admin(usid)
         current_app.logger.info('Admin {} resubmit commodity'.format(
             admin.ADname))
         nefrom = ApplyFrom.platform.value
         sup = None
     else:
         raise AuthorityError()
     data = parameter_required(('tcid', ))
     tcid = data.get('tcid')
     with db.auto_commit():
         commodity = TrialCommodity.query.filter_by_(
             TCid=tcid).first_('无此商品信息')
         if commodity.TCstatus not in [
                 TrialCommodityStatus.cancel.value,
                 TrialCommodityStatus.reject.value
         ]:
             raise StatusError('只有撤销或已下架状态的申请可以重新提交')
         if sup:
             if commodity.CreaterId != usid:
                 raise AuthorityError('仅可重新提交自己上传的商品')
         commodity.TCstatus = TrialCommodityStatus.auditing.value
         # 重新创建一个审批流
     super().create_approval('totrialcommodity', usid, tcid, nefrom)
     return Success('提交成功', {'tcid': tcid})
コード例 #20
0
 def delete_apply(self):
     """删除申请"""
     if is_supplizer():
         usid = request.user.id
         sup = Supplizer.query.filter_by_(SUid=usid).first_('供应商信息错误')
         current_app.logger.info(
             'Supplizer {} delete magicbox apply'.format(sup.SUname))
     elif is_admin():
         usid = request.user.id
         admin = Admin.query.filter_by_(ADid=usid).first_('管理员信息错误')
         current_app.logger.info('Admin {} magicbox apply'.format(
             admin.ADname))
         sup = None
     else:
         raise AuthorityError()
     data = parameter_required(('mbaid', ))
     mbaid = data.get('mbaid')
     with db.auto_commit():
         apply_info = MagicBoxApply.query.filter_by_(
             MBAid=mbaid).first_('无此申请记录')
         if sup:
             assert apply_info.SUid == usid, '供应商只能删除自己提交的申请'
         if apply_info.MBAstatus not in [
                 ApplyStatus.cancle.value, ApplyStatus.reject.value
         ]:
             raise StatusError('只能删除已拒绝或已撤销状态下的申请')
         apply_info.isdelete = True
     return Success('删除成功', {'mbaid': mbaid})
コード例 #21
0
    def add_update_notes(self):
        # 创建或更新通告
        from flask import request
        if not is_admin():
            raise AuthorityError
        data = parameter_required(('mncontent', 'mnstatus'))
        mnstatus = data.get('mnstatus')
        mnstatus = getattr(NotesStatus, mnstatus, None)
        if not mnstatus:
            mnstatus = 0
        else:
            mnstatus = mnstatus.value

        mncontent = data.get('mncontent')
        mnid = data.get('mnid')
        with db.auto_commit():
            if mnid:
                mn = ManagerSystemNotes.query.filter(
                    ManagerSystemNotes.MNid == mnid,
                    ManagerSystemNotes.isdelete == False).first()
                if mn:
                    mn.MNcontent = mncontent
                    mn.MNstatus = mnstatus
                    mn.MNupdateid = request.user.id
                    return Success('更新通告成功', data=mn.MNid)

            mn = ManagerSystemNotes.create({
                'MNid': str(uuid.uuid1()),
                'MNcontent': mncontent,
                'MNstatus': mnstatus,
                'MNcreateid': request.user.id
            })

            db.session.add(mn)
        return Success('创建通告成功', data=mn.MNid)
コード例 #22
0
 def shelves(self):
     """下架申请"""
     if is_supplizer():
         usid = request.user.id
         sup = Supplizer.query.filter_by_(SUid=usid).first_('供应商信息错误')
         current_app.logger.info(
             'Supplizer {} delete magicbox apply'.format(sup.SUname))
     elif is_admin():
         usid = request.user.id
         admin = Admin.query.filter_by_(ADid=usid).first_('管理员信息错误')
         current_app.logger.info('Admin {} magicbox apply'.format(
             admin.ADname))
         sup = None
     else:
         raise AuthorityError()
     data = parameter_required(('mbaid', ))
     mbaid = data.get('mbaid')
     with db.auto_commit():
         apply_info = MagicBoxApply.query.filter_by_(
             MBAid=mbaid).first_('无此申请记录')
         if sup:
             assert apply_info.SUid == usid, '供应商只能下架自己的申请'
         if apply_info.MBAstatus != ApplyStatus.agree.value:
             raise StatusError('只能下架已通过的申请')
         apply_info.MBAstatus = ApplyStatus.reject.value
     return Success('下架成功', {'mbaid': mbaid})
コード例 #23
0
ファイル: CTicket.py プロジェクト: haobin12358/python_planet
    def pay(self):
        """购买"""
        data = parameter_required()
        tiid, tsoid, numbers = data.get('tiid'), data.get('tsoid'), data.get('num')
        user = User.query.filter(User.isdelete == false(), User.USid == getattr(request, 'user').id).first_('请重新登录')
        opayno = super(CTicket, self)._opayno()
        instance_list, tscode_list = [], []
        with db.auto_commit():
            if tiid and numbers:  # 抢票
                ticket, mount_price, instance_list, tscode_list = self._grap_ticket_order(tiid, numbers, user, opayno,
                                                                                          instance_list, tscode_list)
            elif tsoid:  # 中奖后补押金
                ticket, mount_price, instance_list, tscode_list = self._patch_ticket_order(tsoid, user, opayno,
                                                                                           instance_list, tscode_list)
            else:
                raise ParamsError

            db.session.add_all(instance_list)
        body = ticket.TIname[:16] + '...'
        openid = user.USopenid1
        pay_args = super(CTicket, self)._add_pay_detail(opayno=opayno, body=body, PPpayMount=mount_price, openid=openid,
                                                        PPcontent=ticket.TIid,
                                                        PPpayType=PlayPayType.ticket.value)
        response = {
            'pay_type': PayType.wechat_pay.name,
            'opaytype': PayType.wechat_pay.value,
            'tscode': tscode_list,
            'args': pay_args
        }
        current_app.logger.info('response = {}'.format(response))
        return Success(data=response)
コード例 #24
0
 def award_detail(self):
     """查看申请详情"""
     data = parameter_required(('fmfaid', ))
     fmfaid = data.get('fmfaid')
     apply = FreshManFirstApply.query.filter(
         FreshManFirstApply.isdelete == False,
         FreshManFirstApply.FMFAid == fmfaid).first_('该申请不存在')
     apply.fill('FMFAstatus_zh', ApplyStatus(apply.FMFAstatus).zh_value)
     if apply.FMFAfrom == ApplyFrom.platform.value:
         admin = Admin.query.filter(Admin.ADid == apply.SUid).first()
         admin.hide('ADfirstpwd', 'ADpassword')
         apply.fill('from_admin', admin)
     else:
         supplizer = Supplizer.query.filter(
             Supplizer.SUid == apply.SUid).first()
         supplizer.hide('SUpassword')
         apply.fill('from_supplizer', supplizer)
     apply_product = FreshManFirstProduct.query.filter(
         FreshManFirstProduct.FMFAid == apply.FMFAid).first()
     apply_product.PRattribute = json.loads(apply_product.PRattribute)
     apply.fill('product', apply_product)
     apply_skus = FreshManFirstSku.query.filter(
         FreshManFirstSku.FMFPid == apply_product.FMFPid).all()
     for apply_sku in apply_skus:
         sku = ProductSku.query.filter(
             ProductSku.SKUid == apply_sku.SKUid).first()
         sku.SKUattriteDetail = json.loads(sku.SKUattriteDetail)
         apply_product.fill('apply_sku', apply_sku)
         apply_sku.fill('sku', sku)
     return Success('获取成功', apply)
コード例 #25
0
    def delete_question(self):
        """后台管理员删除问题"""
        if not is_admin():
            raise AuthorityError('权限不足')
        admin = Admin.query.filter_by_(ADid=request.user.id).first_('权限已被回收')

        data = parameter_required(('qulist',))
        qulist = data.get('qulist')
        for quid in qulist:
            qu = Quest.query.filter_by_(QUid=quid).first()
            if not qu:
                continue
            qu.isdelete = True
            qalist = Answer.query.filter_by_(QUid=qu.QUid).all()
            for qa in qalist:
                qa.isdelete = True
            qan = QuestAnswerNote.create({
                'QANid': str(uuid.uuid1()),
                'QANcontent': '删除问题',
                'QANcreateid': admin.ADid,
                'QANtargetId': quid,
                'QANtype': QuestAnswerNoteType.qu.value,
            })
            db.session.add(qan)

        return Success('删除完成')
コード例 #26
0
 def get_user_activationcode(self):
     """获取用户拥有的激活码"""
     if not is_admin():
         usid = request.user.id
         user_act_codes = UserActivationCode.query.filter(
             UserActivationCode.isdelete == False,
             UserActivationCode.USid == usid
         ).order_by(
             UserActivationCode.UACuseFor.asc(),
             UserActivationCode.createtime.desc()
         ).all_with_page()
     elif is_admin():
         data = parameter_required()
         usid = data.get('usid')
         user_act_codes = UserActivationCode.query.filter_(
             UserActivationCode.isdelete == False,
             UserActivationCode.USid == usid
         ).order_by(
             UserActivationCode.createtime.desc()
         ).all_with_page()
         # todo 管理员查看激活码
         pass
     for user_act_code in user_act_codes:
         user_act_code.fill('uacstatus_zh',
                            UserActivationCodeStatus(user_act_code.UACstatus).zh_value)
     return Success(data=user_act_codes)
コード例 #27
0
    def delete(self):
        """删除"""
        data = parameter_required(('suid', ))
        suid = data.get('suid')
        with db.auto_commit():
            supplizer = Supplizer.query.filter(
                Supplizer.isdelete == False,
                Supplizer.SUid == suid).first_('供应商不存在')
            if self._check_lasting_order(suid=suid):
                raise StatusError('供应商部分订单正在进行')

            supplizer.isdelete = True
            db.session.add(supplizer)
            BASEADMIN().create_action(AdminActionS.delete.value, 'Supplizer',
                                      suid)
            # 品牌删除
            productbrands = ProductBrand.query.filter(
                ProductBrand.isdelete == False,
                ProductBrand.SUid == suid).all()
            current_app.logger.info('删除供应商{}'.format(supplizer.SUname))
            for pb in productbrands:
                pb.isdelete = True
                db.session.add(pb)
                # 商品删除
                delete_product = Products.query.filter(
                    Products.isdelete == False,
                    Products.PBid == pb.PBid).update(
                        {'PRstatus': ProductStatus.off_shelves.value})
        return Success('删除成功')
コード例 #28
0
 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 = self._check_sort(data.get('pcid'), data.get('pcsort', 1))
     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('更新成功')
コード例 #29
0
 def create_apply(self):
     """提交购买申请"""
     data = parameter_required(
         ('acabankname', 'acabanksn', 'acaname', 'vouchers'))
     acabankname = data.get('acabankname')
     acabanksn = data.get('acabanksn')
     if len(acabanksn) < 10 or len(acabanksn) > 30:
         raise ParamsError('卡号错误')
     if re.findall('\D', acabanksn):
         raise ParamsError('卡号错误')
     acaname = data.get('acaname')
     vouchers = data.get('vouchers')
     if not vouchers or (not isinstance(vouchers,
                                        list)) or (len(vouchers) > 4):
         raise ParamsError('凭证有误')
     with db.auto_commit():
         apply = ActivationCodeApply.create({
             'ACAid': str(uuid.uuid1()),
             'USid': request.user.id,
             'ACAname': acaname,
             'ACAbankSn': acabanksn,
             'ACAbankname': acabankname,
             'ACAvouchers': vouchers
         })
         db.session.add(apply)
     self.create_approval('toactivationcode', request.user.id, apply.ACAid)
     return Success('提交成功')
コード例 #30
0
ファイル: CCoupon.py プロジェクト: haobin12358/python_planet
    def create_code(self):
        data = parameter_required(('coid', 'conum'))
        coid = data.get('coid')
        conum = data.get('conum')
        with db.auto_commit():
            coupon = Coupon.query.filter_by(COid=coid,
                                            isdelete=False,
                                            COcode=1).first_('该优惠券不能生成兑换码')
            # 校验剩余数量
            if coupon.COlimitNum:
                if int(coupon.COremainNum) < int(conum):
                    raise StatusError('兑换数量超过剩余数量')
                coupon.update(
                    {'COremainNum': int(coupon.COremainNum) - int(conum)})
            # isinstance_list = [coupon]
            db.session.add(coupon)
            for _ in range(int(data.get('conum'))):
                ccid = str(uuid.uuid1())
                cccode = self.coupen_code()
                coupon_code = CouponCode.create({
                    'CCid': ccid,
                    'COid': coid,
                    'CCcode': cccode
                })
                db.session.add(coupon_code)
                BASEADMIN().create_action(AdminActionS.insert.value,
                                          'CouponCode', coid)
                db.session.flush()

        return Success('生成激活码成功', data={'coid': coid, 'conum': conum})