Пример #1
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)
Пример #2
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 and apply_info.SUid != sup.SUid:
             raise ParamsError('只能删除自己提交的申请')
         if apply_info.MBAstatus not in [
                 ApplyStatus.cancle.value, ApplyStatus.reject.value,
                 ApplyStatus.shelves.value
         ]:
             raise StatusError('只能删除已下架、已拒绝、已撤销状态下的申请')
         apply_info.isdelete = True
         MagicBoxApplySku.query.filter_by_(MBAid=apply_info.MBAid).delete_()
         if is_admin():
             BASEADMIN().create_action(AdminActionS.delete.value,
                                       'MagicBoxApply', mbaid)
     return Success('删除成功', {'mbaid': mbaid})
Пример #3
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
         if is_admin():
             BASEADMIN().create_action(AdminActionS.update.value,
                                       'TrialCommodity', tcid)
     return Success('取消成功', {'tcid': tcid})
Пример #4
0
    def upload_delivery_file(self):
        """
        订单批量发货,文件上传入口
        :return:
        """
        if is_admin():
            Admin.query.filter_by(ADid=request.user.id,
                                  ADstatus=AdminStatus.normal.value,
                                  isdelete=False).first_('管理员账号错误')
        elif is_supplizer():
            Supplizer.query.filter_by(SUid=request.user.id,
                                      SUstatus=UserStatus.usual.value,
                                      isdelete=False).first_('供应商账号状态错误')
        else:
            raise TokenError('未登录')
        file = request.files.get('file')
        if not file:
            raise ParamsError('未上传文件')
        current_app.logger.info('Start Add Delivery Template {}'.format(
            datetime.now()))
        folder = 'xls'
        # 接收数据保存到服务器
        file_path = self._save_excel(file, folder)

        # 进行订单发货
        nrows = self._order_delivery(file_path)
        if is_admin():
            with db.auto_commit():
                BASEADMIN().create_action(AdminActionS.insert.value, 'file',
                                          file_path)

        current_app.logger.info('End Add Delivery Template {}'.format(
            datetime.now()))
        return Success('批量发货成功, 共发货 {} 个订单'.format(nrows - 1))
Пример #5
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_()
         if is_admin():
             BASEADMIN().create_action(AdminActionS.delete.value,
                                       'TrialCommodity', tcid)
     return Success('删除成功', {'tcid': tcid})
Пример #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
             if is_admin():
                 BASEADMIN().create_action(AdminActionS.update.value,
                                           'TrialCommodity', tcid)
     return Success('下架成功', {'tcid': tcid_list})
Пример #7
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})
    def shelf_award(self):
        """撤销申请"""
        if not is_supplizer() and not is_admin():
            raise AuthorityError()
        form = ShelfFreshManfirstOrder().valid_data()
        fmfaid = form.fmfaid.data
        with db.auto_commit():
            suid = request.user.id if is_supplizer() else None
            apply_query = FreshManFirstApply.query.filter(
                FreshManFirstApply.isdelete == False,
                FreshManFirstApply.FMFAid == fmfaid,
                FreshManFirstApply.FMFAstatus == ApplyStatus.wait_check.value
            )
            if suid:
                apply_query = apply_query.filter(
                    FreshManFirstApply.SUid == request.user.id,
                )
            apply = apply_query.first_('申请已处理')

            # 库存处理
            self._re_stock(apply)
            apply.FMFAstatus = ApplyStatus.cancle.value
            db.session.add(apply)
            # 相应的审批流
            Approval.query.filter(
                Approval.isdelete == False,
                Approval.AVcontent == fmfaid
            ).update({
                'AVstatus': ApplyStatus.cancle.value
            })
            if is_admin():
                BASEADMIN().create_action(AdminActionS.update.value, 'FreshManFirstApply', fmfaid)
        return Success('撤销成功')
Пример #9
0
    def shelf_award(self):
        """撤销申请"""
        if not (is_supplizer() or is_admin()):
            raise AuthorityError()
        data = parameter_required(('tlpid', ))
        tlpid = data.get('tlpid')
        if is_supplizer():
            tlp_from = ApplyFrom.supplizer.value
            suid = request.user.id

        else:
            tlp_from = ApplyFrom.platform.value

            suid = None
        with db.auto_commit():
            apply_info = TimeLimitedProduct.query.filter_by(
                TLPid=tlpid, isdelete=False).first_('无此申请记录')

            if apply_info.TLAstatus != ApplyStatus.wait_check.value:
                raise StatusError('只有在审核状态的申请可以撤销')
            if apply_info.SUid != suid:
                raise AuthorityError('仅可撤销自己提交的申请')
            apply_info.TLAstatus = ApplyStatus.cancle.value

            # 获取原商品属性
            # gnap_old = GuessNumAwardProduct.query.filter(GuessNumAwardProduct.GNAAid == apply_info.GNAAid,
            #                                                 GuessNumAwardProduct.isdelete == False).first()
            product = Products.query.filter_by(PRid=apply_info.PRid,
                                               PRfrom=tlp_from,
                                               isdelete=False).first_('商品信息出错')
            # 获取原sku属性
            tls_list = TimeLimitedSku.query.filter(
                TimeLimitedSku.isdelete == False,
                TimeLimitedSku.TLPid == apply_info.TLPid).all()

            # 遍历原sku 将库存退出去
            for sku in tls_list:
                sku_instance = ProductSku.query.filter_by(
                    isdelete=False, PRid=product.PRid,
                    SKUid=sku.SKUid).first_('商品sku信息不存在')
                self._update_stock(int(sku.TLSstock), product, sku_instance)

            # 同时将正在进行的审批流改为取消 todo
            approval_info = Approval.query.filter_by(
                AVcontent=tlpid,
                AVstartid=request.user.id,
                isdelete=False,
                AVstatus=ApplyStatus.wait_check.value).first()
            approval_info.AVstatus = ApplyStatus.cancle.value
            if is_admin():
                BASEADMIN().create_action(AdminActionS.update.value,
                                          'TimeLimitedProduct', tlpid)
        return Success('取消成功', {'tlpid': tlpid})
Пример #10
0
    def shelves(self):
        """下架申请"""
        if is_supplizer():
            usid = request.user.id
            sup = Supplizer.query.filter_by_(SUid=usid).first_('供应商信息错误')
            current_app.logger.info('Supplizer {} shelf 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 {} shelf magicbox apply'.format(
                admin.ADname))
            sup = None
        else:
            raise AuthorityError()
        data = parameter_required(('mbaid', ))
        mbaid = data.get('mbaid')
        pending_box = MagicBoxJoin.query.filter(
            MagicBoxJoin.isdelete == False,
            MagicBoxJoin.MBJstatus == MagicBoxJoinStatus.pending.value,
            MagicBoxJoin.MBSendtime >= datetime.now().date(),
            MagicBoxJoin.MBAid == mbaid).first()
        if pending_box:
            current_app.logger.info('仍存在未完成礼盒 MBJid: {}'.format(
                pending_box.MBJid))
            raise StatusError('该商品仍有正在分享中的礼盒未完成,暂不能下架')

        with db.auto_commit():
            apply_info = MagicBoxApply.query.filter_by_(
                MBAid=mbaid).first_('无此申请记录')
            if sup and apply_info.SUid != usid:
                raise StatusError('只能下架自己的申请')
            if apply_info.MBAstatus != ApplyStatus.agree.value:
                raise StatusError('只能下架已通过的申请')
            apply_info.MBAstatus = ApplyStatus.shelves.value
            if is_admin():
                BASEADMIN().create_action(AdminActionS.update.value,
                                          'MagicBoxApply', mbaid)
            # 返回库存
            product = Products.query.filter_by(PRid=apply_info.PRid,
                                               isdelete=False).first_('商品信息出错')
            mbs_old = MagicBoxApplySku.query.filter(
                MagicBoxApplySku.MBAid == apply_info.MBAid,
                MagicBoxApplySku.isdelete == False,
            ).all()
            for sku in mbs_old:
                sku_instance = ProductSku.query.filter_by(
                    isdelete=False, PRid=product.PRid,
                    SKUid=sku.SKUid).first_('商品sku信息不存在')
                super(CMagicBox, self)._update_stock(int(sku.MBSstock),
                                                     product, sku_instance)
        return Success('下架成功', {'mbaid': mbaid})
Пример #11
0
 def del_news(self):
     """删除资讯"""
     if is_tourist():
         raise TokenError()
     elif is_admin():
         usid = request.user.id
         admin = self._check_admin(usid)
         current_app.logger.info('Admin {0} deleted a news'.format(
             admin.ADname))
     elif is_supplizer():
         usid = request.user.id
         sup = self._check_supplizer(usid)
         current_app.logger.info('Supplizer {0} deleted a news'.format(
             sup.SUname))
     else:
         usid = request.user.id
         user = self.snews.get_user_by_id(usid)
         current_app.logger.info('User {0} deleted a news'.format(
             user.USname))
     data = parameter_required(('neid', ))
     neids = data.get('neid')
     with db.auto_commit():
         for neid in neids:
             news = News.query.filter_by_(NEid=neid).first_('未找到该资讯或已被删除')
             if is_admin():
                 if news.NEstatus != NewsStatus.refuse.value:
                     raise StatusError('只能删除已下架状态的资讯')
             else:
                 if news.USid != usid:
                     raise StatusError('只能删除自己发布的资讯')
             News.query.filter_by(NEid=neid, isdelete=False).delete_()
             NewsTag.query.filter_by(NEid=neid).delete_()  # 删除标签关联
             NewsComment.query.filter_by(NEid=neid).delete_()  # 删除评论
             NewsFavorite.query.filter_by(NEid=neid).delete_()  # 删除点赞
             NewsTrample.query.filter_by(NEid=neid).delete_()  # 删除点踩
             # 如果在审核中,同时取消在进行的审批流
             try:
                 if news.NEstatus == NewsStatus.auditing.value:
                     approval_info = Approval.query.filter_by_(
                         AVcontent=neid,
                         AVstartid=news.USid,
                         AVstatus=ApplyStatus.wait_check.value).first()
                     approval_info.update(
                         {'AVstatus': ApplyStatus.cancle.value})
                     db.session.add(approval_info)
             except Exception as e:
                 current_app.logger.error('删除圈子相关审批流时出错: {}'.format(e))
     return Success('删除成功', {'neid': neids})
Пример #12
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)
Пример #13
0
 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('更新成功')
Пример #14
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('删除完成')
Пример #15
0
 def list(self):
     """获取优惠券列表"""
     form = CouponListForm().valid_data()
     itid = form.itid.data
     coupons = Coupon.query.filter(Coupon.isdelete == False)
     usid = suid = adid = None
     if is_supplizer():
         suid = request.user.id
     elif is_admin():
         adid = request.user.id
     elif not is_tourist():
         usid = request.user.id
     if itid:
         coupons = coupons.join(CouponItem,
                                CouponItem.COid == Coupon.COid).filter(
                                    CouponItem.ITid == itid,
                                    CouponItem.isdelete == False)
     if suid:
         coupons = coupons.filter(Coupon.SUid == suid)
     coupons = coupons.order_by(Coupon.createtime.desc(),
                                Coupon.COid).all_with_page()
     for coupon in coupons:
         # 标签
         self._coupon(coupon, usid=usid)
     return Success(data=coupons)
 def del_award(self):
     """删除申请"""
     if not is_supplizer() and not is_admin():
         raise AuthorityError()
     form = ShelfFreshManfirstOrder().valid_data()
     fmfaid = form.fmfaid.data
     with db.auto_commit():
         apply_info = FreshManFirstApply.query.filter_by_(FMFAid=fmfaid).first_('申请未找到或已删除')
         if is_supplizer():
             assert apply_info.SUid == request.user.id, '供应商只能删除自己提交的申请'
         if apply_info.FMFAstatus not in [ApplyStatus.cancle.value, ApplyStatus.reject.value]:
             raise StatusError('只能删除已拒绝或已撤销状态下的申请')
         apply_info.isdelete = True
         if is_admin():
             BASEADMIN().create_action(AdminActionS.delete.value, 'FreshManFirstApply', fmfaid)
     return Success('删除成功', {'fmfaid': fmfaid})
Пример #17
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})
Пример #18
0
 def validate_usid(self, raw):
     """普通用户默认使用自己的id"""
     if not raw.data:
         if not is_admin():
             raw.data = request.user.id
             if request.user.id != raw.data:
                 raise AuthorityError()
Пример #19
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('删除完成')
Пример #20
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})
Пример #21
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})
Пример #22
0
 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)
Пример #23
0
 def change_password(self):
     if not is_supplizer() and not is_admin():
         raise AuthorityError()
     form = SupplizerChangePasswordForm().valid_data()
     old_password = form.oldpassword.data
     supassword = form.supassword.data
     suid = form.suid.data
     with db.auto_commit():
         supplizer = Supplizer.query.filter(
             Supplizer.isdelete == False,
             Supplizer.SUid == suid).first_('不存在的供应商')
         if not is_admin() and not check_password_hash(
                 supplizer.SUpassword, old_password):
             raise AuthorityError('原密码错误')
         supplizer.SUpassword = generate_password_hash(supassword)
         db.session.add(supplizer)
     return Success('修改成功')
Пример #24
0
    def cancel_apply(self):
        """取消申请"""
        if is_admin():
            Admin.query.filter_by_(ADid=request.user.id).first_("账号状态错误")
        # elif is_supplizer():
        #     Supplizer.query.filter_by_(SUid=request.user.id).first_("账号状态错误")
        else:
            raise AuthorityError()
        data = parameter_required(('ipid', ))
        with db.auto_commit():
            ip = IntegralProduct.query.filter(
                IntegralProduct.IPid == data.get('ipid'),
                IntegralProduct.isdelete == False, IntegralProduct.IPstatus ==
                ApplyStatus.wait_check.value).first_("只有在审核状态下的申请可以撤销")
            if is_supplizer() and ip.SUid != request.user.id:
                raise AuthorityError("只能撤销属于自己的申请")
            ip.update({'IPstatus': ApplyStatus.cancle.value})
            db.session.add(ip)
            if is_admin():
                BASEADMIN().create_action(AdminActionS.update.value,
                                          'IntegralProduct', data.get('ipid'))
            # 返回库存
            product = Products.query.filter_by(PRid=ip.PRid,
                                               isdelete=False).first_('商品信息出错')
            ips_old = IntegralProductSku.query.filter(
                IntegralProductSku.IPid == ip.IPid,
                IntegralProductSku.isdelete == False,
                IntegralProduct.isdelete == False,
            ).all()
            for sku in ips_old:
                sku_instance = ProductSku.query.filter_by(
                    isdelete=False, PRid=product.PRid,
                    SKUid=sku.SKUid).first_('商品sku信息不存在')
                super(CIntegralStore,
                      self)._update_stock(int(sku.IPSstock), product,
                                          sku_instance)

            # 同时取消正在进行的审批流
            Approval.query.filter_by(
                AVcontent=ip.IPid,
                AVstartid=request.user.id,
                isdelete=False,
                AVstatus=ApplyStatus.wait_check.value).update(
                    {'AVstatus': ApplyStatus.cancle.value})
        return Success('已取消申请', dict(ipid=ip.IPid))
Пример #25
0
 def delete(self):
     if not is_admin():
         raise AuthorityError()
     data = SignIndelete().valid_data()
     siaid = data.siaid.data
     check_sia = SignInAward.query.filter_by(SIAid=siaid,
                                             isdelete=False).delete_()
     if not check_sia:
         raise ParamsError('已删除')
     return Success('删除设置成功')
Пример #26
0
    def list(self):
        """拼团/商品列表"""
        args = request.args.to_dict()
        now = datetime.datetime.now()
        option = args.get('option')
        gpstatus = args.get('gpstatus')
        starttime, endtime = args.get('starttime', '2019-01-01') or '2019-01-01', args.get('endtime', '2100-01-01') or '2100-01-01'
        if is_admin() or is_supplizer():
            return self._back_group_product_list(gpstatus, starttime, endtime)

        if str(option) == 'my':
            my_group = []
            if common_user():
                my_group = self._filter_joined_group().all_with_page()
            list(map(lambda x: self._fill_single_group(x), my_group))
            return Success(data=my_group)

        elif str(option) == 'all':
            all_group = self._filter_not_joined_group().all_with_page()
            list(map(lambda x: self._fill_single_group(x), all_group))
            return Success(data=all_group)

        my_group = []
        if common_user():
            my_group = self._filter_joined_group().distinct().limit(2).all()

        list(map(lambda x: self._fill_single_group(x), my_group))

        all_group = self._filter_not_joined_group().distinct().limit(2).all()

        list(map(lambda x: self._fill_single_group(x), all_group))

        group_goods = GroupGoodsProduct.query.filter(GroupGoodsProduct.isdelete == False,
                                                     GroupGoodsProduct.GPstatus == ApplyStatus.agree.value,
                                                     GroupGoodsProduct.GPday == now.date()
                                                     ).order_by(GroupGoodsProduct.createtime.desc()).all_with_page()
        for gp in group_goods:
            gp.hide('SUid', 'PRid', 'GPfreight')
            product = Products.query.filter(Products.PRid == gp.PRid, Products.isdelete == False).first()
            if not product:
                continue
            gps_list = GroupGoodsSku.query.filter_by(GPid=gp.GPid, isdelete=False).all()
            gpsku_price = [gps.SKUPrice for gps in gps_list]
            gp.fill('gpstatus_en', ApplyStatus(gp.GPstatus).name)
            gp.fill('gpstatus_zh', ApplyStatus(gp.GPstatus).zh_value)
            gp.fill('prmainpic', product['PRmainpic'])
            gp.fill('prtitle', product.PRtitle)
            gp.fill('gpdeposit', max(gpsku_price))

        res = {'my_group': my_group,
               'all_group': all_group,
               'group_goods': group_goods
               }

        return Success(data=res)
Пример #27
0
 def list(self):
     form = BrandsListForm().valid_data()
     pbstatus = dict(form.pbstatus.choices).get(form.pbstatus.data)
     free = dict(form.free.choices).get(form.free.data)
     time_order = dict(form.time_order.choices).get(form.time_order.data)
     itid = form.itid.data
     itid = itid.split('|') if itid else []
     kw = form.kw.data
     brand_query = ProductBrand.query.filter_(
         ProductBrand.isdelete == False, ProductBrand.PBstatus == pbstatus)
     if itid:
         brand_query = brand_query.join(
             BrandWithItems,
             ProductBrand.PBid == BrandWithItems.PBid).filter(
                 BrandWithItems.isdelete == False,
                 BrandWithItems.ITid.in_(itid))
     if is_supplizer():
         current_app.logger.info('供应商查看品牌列表..')
         brand_query = brand_query.filter(
             ProductBrand.SUid == request.user.id)
     if free is True:
         brand_query = brand_query.filter(ProductBrand.SUid.is_(None))
     elif free is False:
         brand_query = brand_query.filter(ProductBrand.SUid.isnot(None))
     if kw:
         brand_query = brand_query.filter(ProductBrand.PBname.contains(kw))
     brands = brand_query.order_by(time_order).all_with_page()
     for brand in brands:
         brand.fill('PBstatus_en', ProductBrandStatus(brand.PBstatus).name)
         brand.fill('PBstatus_zh',
                    ProductBrandStatus(brand.PBstatus).zh_value)
         brand.add('createtime')
         # 标签
         print(brand.PBid)
         pb_items = Items.query.filter_by().join(
             BrandWithItems, Items.ITid == BrandWithItems.ITid).filter_(
                 BrandWithItems.PBid == brand.PBid,
                 BrandWithItems.isdelete == False,
             ).all()
         brand.fill('items', pb_items)
         if is_admin() or brand.SUid:
             supplizer = Supplizer.query.filter(
                 Supplizer.isdelete == False,
                 Supplizer.SUid == brand.SUid).first()
             if not supplizer:
                 with db.auto_commit():
                     brand.SUid = None
                     db.session.add(brand)
                 continue
             supplizer.fields = [
                 'SUloginPhone', 'SUlinkPhone', 'SUname', 'SUlinkman',
                 'SUheader'
             ]
             brand.fill('supplizer', supplizer)
     return Success(data=brands)
Пример #28
0
 def shelf(self):
     """下架"""
     # if is_supplizer():
     #     usid = request.user.id
     #     sup = Supplizer.query.filter_by_(SUid=usid).first_('供应商信息错误')
     #     current_app.logger.info('Supplizer {} shelf 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 {} shelf integral apply'.format(
             admin.ADname))
         sup = None
     else:
         raise AuthorityError()
     data = parameter_required(('ipid', ))
     ipid = data.get('ipid')
     with db.auto_commit():
         ip = IntegralProduct.query.filter_by_(IPid=ipid).first_('无此申请记录')
         if sup and ip.SUid != usid:
             raise StatusError('只能下架自己的商品')
         if ip.IPstatus != ApplyStatus.agree.value:
             raise StatusError('只能下架已上架的商品')
         ip.IPstatus = ApplyStatus.shelves.value
         if is_admin():
             BASEADMIN().create_action(AdminActionS.update.value,
                                       'IntegralProduct', ipid)
         # 返回库存
         product = Products.query.filter_by(PRid=ip.PRid,
                                            isdelete=False).first_('商品信息出错')
         ips_old = IntegralProductSku.query.filter(
             IntegralProductSku.IPid == ip.IPid,
             IntegralProductSku.isdelete == False,
             IntegralProduct.isdelete == False,
         ).all()
         for sku in ips_old:
             sku_instance = ProductSku.query.filter_by(
                 isdelete=False, PRid=product.PRid,
                 SKUid=sku.SKUid).first_('商品sku信息不存在')
             super(CIntegralStore,
                   self)._update_stock(int(sku.IPSstock), product,
                                       sku_instance)
     return Success('下架成功', {'ipid': ipid})
Пример #29
0
 def shelf(self):
     """下架"""
     if is_supplizer():
         usid = request.user.id
         sup = Supplizer.query.filter_by_(SUid=usid).first_('供应商信息错误')
         current_app.logger.info('Supplizer {} shelf guess group apply'.format(sup.SUname))
     elif is_admin():
         usid = request.user.id
         admin = Admin.query.filter_by_(ADid=usid).first_('管理员信息错误')
         current_app.logger.info('Admin {} shelf guess group apply'.format(admin.ADname))
         sup = None
     else:
         raise AuthorityError()
     data = parameter_required(('gpid',))
     gpid = data.get('gpid')
     pending_group = GuessGroup.query.filter(GuessGroup.isdelete == False,
                                             GuessGroup.GGstatus.in_((GuessGroupStatus.pending.value,
                                                                      GuessGroupStatus.waiting.value)),
                                             GuessGroup.GGendtime >= datetime.datetime.now(),
                                             GuessGroup.GPid == gpid).first()
     if pending_group:
         raise StatusError('该商品仍有拼团未完成,暂不能下架')
     with db.auto_commit():
         gp = GroupGoodsProduct.query.filter_by_(GPid=gpid).first_('无此申请记录')
         if sup and gp.SUid != usid:
             raise StatusError('只能下架自己的商品')
         if gp.GPstatus != ApplyStatus.agree.value:
             raise StatusError('只能下架已上架的商品')
         gp.GPstatus = ApplyStatus.shelves.value
         if is_admin():
             BASEADMIN().create_action(AdminActionS.update.value, 'GroupGoodsProduct', gpid)
         # 返回库存
         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)
     return Success('下架成功', {'gpid': gpid})
Пример #30
0
 def delete(self):
     if not is_admin():
         raise AuthorityError()
     data = SignIndelete().valid_data()
     siaid = data.siaid.data
     check_sia = SignInAward.query.filter_by(SIAid=siaid,
                                             isdelete=False).delete_()
     BASEADMIN().create_action(AdminActionS.delete.value, 'SignInAward',
                               siaid)
     if not check_sia:
         raise ParamsError('已删除')
     return Success('删除设置成功')