Exemple #1
0
 def get_product_relate_bigactivity(self):
     """商品池获取商品与专题的关联详情"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'请使用管理员账号重新登录')
     prid = request.args.to_dict().get('prid')
     parameter_required('prid')
     logger.debug("get product relate bigactivity PRID is %s", prid)
     prbaids = self.sproduct.get_product_baid_by_prid(prid)
     list_baid = []
     suid = ''
     suname = u'批量导入'
     updatetime = ''
     for prbaid in prbaids:
         record_info = self.sproduct.get_singel_record_by_filter({
             'PRid':
             prid,
             'PORtarget':
             prbaid.BAid
         })
         if record_info:
             suid = record_info.SUid
             suser_info = self.ssuperuser.get_one_super_by_suid(suid)
             suname = suser_info.SUname if suser_info else ''
             updatetime = get_web_time_str(record_info.PORcreatetime)
         dict_baid = {
             'pbid': prbaid.PBid,
             'baid': prbaid.BAid,
             'claimid': suid,
             'clainname': suname,
             'updatetime': updatetime
         }
         list_baid.append(dict_baid)
     response = import_status("messages_get_item_ok", "OK")
     response['data'] = list_baid
     return response
Exemple #2
0
 def add_one(self):
     """添加一个轮播图, 需要管理员的登录状态"""
     if not hasattr(request, 'user'):
         return TOKEN_ERROR  # 未登录, 或token错误
     if not is_admin():
         return AUTHORITY_ERROR  # 权限不足
     data = request.json
     now_time = datetime.strftime(datetime.now(), format_for_db)
     rbstarttime = data.get('rbstarttime', now_time)  # 轮播 开始时间
     rbstarttime_str_to_time = datetime.strptime(rbstarttime, format_for_db)
     one_days_later = datetime.strftime(
         rbstarttime_str_to_time + timedelta(days=1), format_for_db)
     rbentime = data.get('rbendtime', one_days_later)  # 轮播结束时间, 默认1天以后
     rbid = str(uuid.uuid1())
     rbimage = data.get('rbimage')
     rbsort = data.get('rbsort')
     prid = data.get('prid')
     if not rbimage or not prid:
         return PARAMS_MISS
     if not self.sproduct.get_product_by_prid(prid):
         return SYSTEM_ERROR("缺少对应的商品id")
     add_model(
         'RecommendBanner', **{
             'RBid': rbid,
             'RBimage': rbimage,
             'RRid': prid,
             'RBstarttime': rbstarttime,
             'RBendtime': rbentime,
             'RBsort': rbsort
         })
     response_make_banner = import_status('add_recommendbanner_success',
                                          'OK')
     response_make_banner['data'] = {'rbid': rbid}
     return response_make_banner
Exemple #3
0
    def get_all(self):
        """活动所有热文"""
        if is_tourist():
            raise TOKEN_ERROR(u'未登录')
        args = request.args.to_dict()
        logger.debug("get hotmessage args is %s", args)
        lasting = args.get('lasting', 'true')
        htfilter = 1 if is_partner() else 0
        if is_admin():
            htfilter = [0, 1]
        try:
            hot_list = self.s_hotmessage.get_hotmsg_list_by_filter(htfilter)
            if str(lasting) == 'true':
                hot_list = filter(
                    lambda hot: hot.HMstarttime < get_db_time_str() < hot.
                    HMendtime, hot_list)
            for hotmsg in hot_list:
                hotmsg.HMstarttime = get_web_time_str(hotmsg.HMstarttime)
                hotmsg.HMendtime = get_web_time_str(hotmsg.HMendtime)

            data = import_status("get_hotmessage_list_success", "OK")
            data['data'] = hot_list
            return data
        except:
            logger.exception("get hotmessage error")
            raise SYSTEM_ERROR(u'服务器繁忙')
Exemple #4
0
 def add_one(self):
     """添加一个轮播图, 需要管理员的登录状态"""
     if not hasattr(request, 'user'):
         return TOKEN_ERROR  # 未登录, 或token错误
     if not is_admin():
         return AUTHORITY_ERROR  # 权限不足
     data = request.json
     now_time = datetime.strftime(datetime.now(), format_for_db)
     bastarttime = data.get('bastarttime', now_time)  # 轮播 开始时间
     bastarttime_str_to_time = datetime.strptime(bastarttime, format_for_db)
     # 7天以后
     seven_days_later = datetime.strftime(bastarttime_str_to_time + timedelta(days=7), format_for_db)
     baentime = data.get('baendtime', seven_days_later)  # 轮播结束时间, 默认7天以后
     baid = str(uuid.uuid1())
     baimage = data.get('baimage')
     basort = data.get('basort')
     acid = data.get('acid')
     if not baimage or not acid:
         return PARAMS_MISS
     # if not self.sactivity.get_activity_by_acid(acid):
     #     return SYSTEM_ERROR
     add_model('Banner', **{
         'BAid': baid,
         'BAimage': baimage,
         'ACid': acid,
         'BAstarttime': bastarttime,
         'BAendtime': baentime,
         'BAsort': basort
     })
     response_make_banner = import_status('add_banner_success', 'OK')
     response_make_banner['data'] = {'baid': baid}
     return response_make_banner
Exemple #5
0
 def get_one_by_productid(self):
     logger.info(request.detail)
     args = request.args.to_dict()
     prid = args.get('productid')
     usid = request.user.id
     if not prid:
         raise PARAMS_MISS()
     product = self.sproduct.get_product_by_productid(prid)
     if not product:
         raise NOT_FOUND(u"无此商品")
     # 是管理员或客服则显示全部信息
     if is_admin() or is_customerservice():
         product.fields = product.all
         print '是管理员或客服'
     else:
         # 如果是游客, 或者是未购买开店大礼包的普通用户
         if is_tourist() or is_ordirnaryuser():
             print '是游客或者普通用户'
             product = self.trans_product_for_fans(product)
         else:  # 合伙人(即已购买开店大礼包的用户)
             print '合伙人'
             product = self.trans_product_for_shopkeeper(product)
         product = self.fill_product_nums(product)
     # 填充一些都需要的信息
     self.fill_product_alreadylike(product, usid)
     self.fill_images(product)
     self.fill_prtarget(product)
     self.fill_product_sku_key(product)
     self.fill_product_sku_value(product)
     self.sproduct.update_view_num(product.PRid)
     data = import_status('get_product_success', 'OK')
     data['data'] = product
     return data
Exemple #6
0
 def add_one(self):
     """添加一个首页上部导航, 需要管理员的登录状态"""
     if not hasattr(request, 'user'):
         return TOKEN_ERROR  # 未登录, 或token错误
     if not is_admin():
         return AUTHORITY_ERROR  # 权限不足
     data = request.json
     tnid = str(uuid.uuid1())
     tnname = data.get('tnname')
     tsort = data.get('tsort')
     tnurl = data.get('tnurl')
     tntype = data.get('tntype')
     tnparentid = data.get('tnparentid')
     if not tnid or not tnname:
         return PARAMS_MISS
     add_model(
         'TopNav', **{
             'TNid': tnid,
             'TNname': tnname,
             'TSort': tsort,
             'TNurl': tnurl,
             'TNtype': tntype,
             'TNparentid': tnparentid
         })
     response_make_topnav = import_status('add_topnav_success', 'OK')
     response_make_topnav['data'] = {'tnid': tnid}
     return response_make_topnav
Exemple #7
0
    def upload_task_img(self):
        if not is_admin():
            raise AUTHORITY_ERROR(u"权限不足")
        formdata = request.form
        logger.info("formdata is %s", formdata)
        files = request.files.get("file")

        if platform.system() == "Windows":
            rootdir = "D:/task"
        else:
            rootdir = "/opt/WeiDian/imgs/task/"
        if not os.path.isdir(rootdir):
            os.mkdir(rootdir)
        # if "FileType" not in formdata:
        #     return
        filessuffix = str(files.filename).split(".")[-1]
        # index = formdata.get("index", 1)
        filename = request.user.id + get_db_time_str() + "." + filessuffix
        filepath = os.path.join(rootdir, filename)
        print(filepath)
        files.save(filepath)
        response = import_status("save_photo_success", "OK")
        # url = Inforcode.ip + Inforcode.LinuxImgs + "/" + filename
        url = QRCODEHOSTNAME + "/imgs/task/" + filename
        # print(url)
        logger.info("this url is %s", url)
        response["data"] = url
        return response
Exemple #8
0
 def get_grant_record(self):
     """获取运营发放记录"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'非管理员权限')
     args = request.args.to_dict()
     logger.debug('get grant record args : %s', args)
     pagenum, pagesize = self.cuser.get_pagesize_pagenum(args)
     record_list, count = self.sraward.get_grant_record(pagenum, pagesize)
     for record in record_list:
         if record:
             user = self.suser.get_user_by_user_id(record.USid)
             usname = user.USname
             suser = self.ssuperuser.get_one_super_by_suid(record.SUid)
             susername = suser.SUname
             reward_info = self.sraward.get_raward_by_id(record.RAid)
             reward_info = self.fill_reward_detail(reward_info)
             record_str = '运营 {0} 发放给 {1} {2}优惠券 {3}张'.format(susername.encode('utf8'), usname.encode('utf8'), reward_info.rewardstr, record.RAnumber)
             record.fill(reward_info.rewardstr, 'rewardname')
             record.fill(usname, 'usname')
             record.fill(susername, 'susername')
             record.fill(record_str, 'record_str')
             record.RGRcreatetime = get_web_time_str(record.RGRcreatetime)
     response = import_status('messages_get_item_ok', 'OK')
     response['data'] = record_list
     response['count'] = count
     return response
Exemple #9
0
 def get_all_user_task(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'权限不足')
     user_task = self.stask.get_all_user_task()
     user_task = [self.fill_task_detail(_task) for _task in user_task]
     user_task = [_task for _task in user_task if _task]
     return user_task
Exemple #10
0
 def upload_file(self, rootdir, notimetag, filepath=None):
     logger.debug('get filetype %s', rootdir)
     from WeiDian.common.timeformat import get_db_time_str
     from WeiDian.config.setting import QRCODEHOSTNAME, LinuxRoot, LinuxImgs, LinuxStaticImgs
     files = request.files.get("file")
     if filepath:
         filepath = os.path.join(LinuxStaticImgs, filepath)
         url = QRCODEHOSTNAME + "/imgs/icon/" + filepath
     else:
         filename = files.filename
         if not isinstance(filename, basestring):
             filename = str(filename)
         filessuffix = filename.split(".")[-1]
         filedir = os.path.join(LinuxRoot, LinuxImgs, rootdir)
         logger.debug('get filedir is %s', filedir)
         if not os.path.isdir(filedir):
             os.mkdir(filedir)
         if not is_admin():
             filename_title = request.user.openid
         else:
             filename_title = request.user.id
         if str(notimetag) == 'true':
             filename = rootdir + filename_title + "." + filessuffix
         else:
             filename = rootdir + filename_title + get_db_time_str(
             ) + "." + filessuffix
         filepath = os.path.join(filedir, filename)
         url = QRCODEHOSTNAME + "/imgs/{0}/".format(rootdir) + filename
     print(filepath)
     files.save(filepath)
     return url
Exemple #11
0
    def set_schedual_show(self):
        """设置个人主页升级进度显示(vip数据统计), 素材圈显示, 待评价"""
        if not is_admin():
            raise TOKEN_ERROR(u'请使用管理员登录')
        # data = parameter_required(u'vip_match', u'material', u'wait_apply')
        data = request.json
        paras_list = ['vip_match', 'material', 'wait_apply']
        if not data or not filter(lambda x: x in paras_list, data):
            raise PARAMS_MISS()
        if 'vip_match' in data:  # vip进度, 写在model里
            vip_match_show = False if str(
                data.get('vip_match')) == '1' else True
            updated = self.spartnermatch.update_partner_match(
                1,
                {  # 更改: 这里的level没有用
                    'PSIMisclose': vip_match_show
                })
        if 'material' in data:  # 素材圈是否显示, 写在model里
            material_show = False if str(data.get('material')) == '1' else True
            updated = self.stopnav.update_topnav_by_tnidorname(
                data={'Tisdelete': material_show}, name='素材圈')

        if 'wait_apply' in data:  # 写在配置文件里
            wait_apply_show = data.get('wait_apply')
            wait_apply_show = '0' if str(wait_apply_show) == '0' else '1'
            Partner().set_item('show', 'wait_apply', wait_apply_show)
        msg = 'update_success'
        data = import_status(msg, "OK")
        return data
Exemple #12
0
    def set_commission(self):
        """佣金设置"""
        if not is_admin():
            raise AUTHORITY_ERROR(u'请使用管理员账号重新登录')
        # todo 设置周周奖 (开始时间/结束时间 分周)
        # todo 设置额外活动
        data = request.json
        logger.debug("SET commission data is %s", data)
        # 设置合伙人三级佣金比例
        divide_one = data.get('divide_one')
        if divide_one not in self.empty and divide_one.isdigit():
            divide_one = float(divide_one) / 100
            self.pn.one_level_divide = str(divide_one)
        divide_two = data.get('divide_two')
        if divide_two not in self.empty and divide_two.isdigit():
            divide_two = float(divide_two) / 100
            self.pn.two_level_divide = str(divide_two)
        divide_three = data.get('divide_three')
        if divide_three not in self.empty and divide_three.isdigit():
            divide_three = float(divide_three) / 100
            self.pn.three_level_divide = str(divide_three)
        # 设置专粉单数及佣金限制
        limit_time_one = data.get('time_one')  # [1,5]
        fans_price_one = data.get('fans_price_one')  # 30
        if fans_price_one not in self.empty:
            fans_price_one = float(fans_price_one) / 100
            self.pn.set_item("level_limit_1", "profit", fans_price_one)
        if limit_time_one not in self.empty:
            self.pn.set_item("level_limit_1", "min", limit_time_one[0])
            self.pn.set_item("level_limit_1", "max", limit_time_one[-1])

        limit_time_two = data.get('time_two')  # [6, 20]
        fans_price_two = data.get('fans_price_two')  # 30
        if fans_price_two not in self.empty:
            fans_price_two = float(fans_price_two) / 100
            self.pn.set_item("level_limit_1", "profit", fans_price_two)
        if limit_time_two not in self.empty:
            if limit_time_two[0] - limit_time_one[-1] != 1:
                raise PARAMS_ERROR(u'timeone 参数错误')
            self.pn.set_item("level_limit_2", "min", limit_time_two[0])
            self.pn.set_item("level_limit_2", "max", limit_time_two[-1])

        limit_time_three = data.get('time_three')  # 21
        fans_price_three = data.get('fans_price_three')  # 30
        if fans_price_three not in self.empty:
            fans_price_three = float(fans_price_three) / 100
            self.pn.set_item("level_limit_1", "profit", fans_price_three)
        if limit_time_three not in self.empty:
            if limit_time_three[0] - limit_time_two[-1] != 1:
                raise PARAMS_ERROR(u'timeone 参数错误')
            self.pn.set_item("level_limit_3", "min", limit_time_three)

        response = import_status("set_success", "OK")
        response['data'] = {
            "divide_one": self.pn.one_level_divide,
            "divide_two": self.pn.two_level_divide,
            "divide_three": self.pn.three_level_divide
        }
        return response
Exemple #13
0
    def update_recommend_by_reid(self):
        if not is_admin():
            raise AUTHORITY_ERROR(u'当前非管理员权限')  # 权限不足
        args = request.args.to_dict()
        logger.debug("update args is %s", args)
        data = request.json
        parameter_required(u'reid')
        logger.debug("update data is %s", data)
        reid = args.get('reid')
        recommend = {
            'REstarttime': get_db_time_str(data.get('restarttime')),
            'REendtime': get_db_time_str(data.get('reendtime')),
            'REfakeviewnum': data.get('reviewnum'),
            'RElikefakenum': data.get('relikenum'),
            'SUid': data.get('suid')
            # 'REisdelete': data.get('reisdelete')
        }
        recommend = {k: v for k, v in recommend.items() if v is not None}
        res = self.srecommend.update_recommend_by_reid(reid, recommend)
        if not res:
            raise SYSTEM_ERROR(u"信息修改错误")
        prid_list = data.get('prid_list')
        if prid_list:
            for item in prid_list:
                prid = item.get('prid')
                prisdelete = item.get('prisdelete')
                rpsort = item.get('rpsort')
                refilter = {'REid': reid, 'PRid': prid}
                already_exist_product = self.srecommend.get_exist_reproduct_by_filter(
                    refilter)
                if not already_exist_product:
                    add_model(
                        'RecommendProduct', **{
                            'REid': reid,
                            'PRid': prid,
                            'RPid': str(uuid.uuid4()),
                            'RPsort': rpsort
                        })
                else:
                    if prisdelete is True:
                        self.srecommend.del_reproduct_by_filter(refilter)
                    elif rpsort:
                        repr_changed = self.srecommend.get_exist_reproduct_by_filter(
                            {'RPsort': rpsort})
                        if repr_changed:
                            self.srecommend.update_exist_reproduct_by_filter(
                                {'RPid': repr_changed.RPid},
                                {'RPsort': already_exist_product.RPsort})
                    self.srecommend.update_exist_reproduct_by_filter(
                        refilter, {
                            'REid': reid,
                            'PRid': prid,
                            'RPsort': rpsort
                        })

        response_update_recommend = import_status('update_recommend_success',
                                                  'OK')
        response_update_recommend['data'] = {'reid': reid}
        return response_update_recommend
Exemple #14
0
 def get_show_type(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'请使用管理员登录')
     settings = Partner()
     skiptype = settings.get_item('skip', 'skip_type')
     response = import_status("messages_get_item_ok", "OK")
     response['data'] = {'skiptype': skiptype}
     return response
Exemple #15
0
 def get_rewardpacket(self):
     """获取优惠券集合"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'非管理员权限')
     rewardpackets = self.sraward.get_reward_packet_list()
     logger.info(('get reward packet list success'))
     data = import_status("messages_get_item_ok", "OK")
     data['data'] = rewardpackets
     return data
Exemple #16
0
 def upload_home_images(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'权限不足')
     filetype = request.args.to_dict().get("filetype", 'home')
     notimetag = request.args.to_dict().get("notimetag", '')
     url = BaseFile().upload_file(filetype, notimetag)
     res = import_status("save_photo_success", "OK")
     res['data'] = url
     return res
Exemple #17
0
    def update_hot(self):
        """修改热文"""
        if not is_admin():
            return AUTHORITY_ERROR  # 权限不足
        data = request.json
        if 'hmid' not in data.keys():
            return PARAMS_MISS
        logger.debug("update hotmessage data is %s", data)
        hmid = data.get('hmid')
        # HMSkipType = data.get('hmskiptype')
        # HMdisplaytype = data.get("hmdisplaytype")
        # if str(HMdisplaytype) not in self.hotmessage_display_type:
        #     raise SYSTEM_ERROR(u'HMdisplaytype参数错误')
        hot = {
            "HMid": data.get("hmid"),
            "HMtext": data.get("hmtext"),
            # "HMcontent": data.get("hmcontent"),
            "HMstarttime": get_db_time_str(data.get("hmstarttime")),
            "HMsort": data.get("hmsort"),
            # "HMSkipType": HMSkipType
            # "HMdisplaytype": HMdisplaytype
        }
        hot = {k: v for k, v in hot.items() if v not in self.empty}
        if data.get("hmendtime"):
            hot["HMendtime"] = get_db_time_str(data.get("hmendtime"))
        if data.get('HMisdelete'):
            hot['HMisdelete'] = True

        from WeiDian.models.model import HotMessage
        filter_change = {HotMessage.HMid == hmid}
        hostmessage_change = self.s_hotmessage.get_hotmessage_by_filter(
            filter_change)
        if not hostmessage_change:
            raise SYSTEM_ERROR(u'热文不存在')

        # for key in self.hostmessage_update_key:
        #     if data.get(str(key).lower()):
        #         hot[key] = data.get(str(key))

        if data.get("hmsort"):
            filter_changed = {HotMessage.HMsort == data.get("hmsort")}
            hostmessage_changeed = self.s_hotmessage.get_hotmessage_by_filter(
                filter_changed)
            if hostmessage_changeed:
                self.s_hotmessage.update_hot_by_hmid(
                    hostmessage_changeed.HMid,
                    {"HMsort": hostmessage_change.HMsort})

        update_info = self.s_hotmessage.update_hot_by_hmid(hmid, hot)
        if not update_info:
            return SYSTEM_ERROR(u'热文不存在')
        response_update_hotmessage = import_status('update_hotmessage_success',
                                                   'OK')
        response_update_hotmessage['data'] = {'hmid': hmid}
        return response_update_hotmessage
Exemple #18
0
    def create_reward(self):
        """创建优惠券"""
        if not is_admin():
            raise AUTHORITY_ERROR(u'当前账号权限不足')
        data = request.json
        logger.debug("create reward data is %s", data)
        raid = str(uuid.uuid1())
        ratype = data.get('ratype')
        rptid = data.get('rptid')
        if not re.match(r'^[0-4]$', str(ratype)):
            raise PARAMS_ERROR(u'ratype, 参数异常')
        now_time = get_db_time_str()
        nowtime_str_to_time = datetime.strptime(now_time, format_for_db)
        days_later = datetime.strftime(nowtime_str_to_time + timedelta(days=30), format_for_web_second)
        reendtime = get_db_time_str(data.get('raendtime', days_later))
        ratransfer = data.get('ratransfer', False)
        reward_dict = {
            'RAid': raid,
            'RAtype': ratype,
            'RAmaxusenum': data.get('ramaxusenum', 1),
            'RAmaxholdnum': data.get('ramaxholdnum', 1),
            'RAendtime': reendtime,
            'RAname': data.get('raname'),
            'RAtransfer': ratransfer,
            'SUid': request.user.id
        }
        if re.match(r'^[0-2]$', str(ratype)):
            if str(ratype) == '0':
                parameter_required('rafilter', 'raamount', 'ratype', 'raname')
                logger.info('This reward type 0 is created')
                reward_dict['RAfilter'] = data.get('rafilter')
                reward_dict['RAamount'] = data.get('raamount')
            elif str(ratype) == '1':
                parameter_required('raratio', 'ratype', 'raname')
                logger.info('This reward type 1 is created')
                reward_dict['RAratio'] = data.get('raratio')
            else:
                parameter_required('raamount', 'ratype', 'raname')
                logger.info('This reward type 2 is created')
                reward_dict['RAfilter'] = 0
                reward_dict['RAamount'] = data.get('raamount')
        if ratransfer == True:
            reward_dict['RAtransfereffectivetime'] = data.get('ratransfereffectivetime', 24)
        self.sraward.add_model('Raward', **reward_dict)

        if rptid:
            self.sraward.add_model('RewardPacketContact', **{
                'RPCid': str(uuid.uuid1()),
                'RAid': raid,
                'RPTid': rptid
            })

        data = import_status("create_reward_success", "OK")
        data['data'] = {'raid': raid}
        return data
Exemple #19
0
 def del_task(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'权限不足')
     data = request.json
     parameter_required("TAid")
     logger.debug('get del task data, %s', data)
     update_result = self.stask.update_task(data.get("TAid"),
                                            {"TAstatus": 4})
     if not update_result:
         raise SYSTEM_ERROR(u'数据库异常')
     return import_status("delete_success", "OK")
Exemple #20
0
 def del_exist_tags(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'非管理员权限')
     atid = request.json.get('atid')
     logger.debug("del exist tags data is %s", request.data)
     del_info = self.stags.del_exist_tags(atid)
     if not del_info:
         raise NOT_FOUND(u"无删除内容")
     response = import_status("delete_success", "OK")
     response['data'] = {'atid': atid}
     return response
Exemple #21
0
 def get_user_by_usphone_or_usname(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'非管理员权限')
     data = request.args.to_dict()
     keywords = data.get('keywords').encode('utf8')
     from WeiDian.models.model import User
     usfilter = (User.USname.like("%{0}%".format(keywords)),
                 User.USphone.like("%{0}%".format(keywords)))
     user_res = self.suser.get_user_by_phone_or_name(usfilter)
     response = import_status('messages_get_item_ok', 'OK')
     response['data'] = user_res
     return response
Exemple #22
0
 def get_all_task_level(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u"未登录")
     try:
         task_level_list = self.stask.get_task_level_all()
         map(self.fill_reward, task_level_list)
         response = import_status('get_task_success', 'OK')
         response['data'] = task_level_list
     except:
         logger.exception('get all task level error')
         raise SYSTEM_ERROR(u"服务器繁忙")
     return response
Exemple #23
0
    def get_all_task(self):
        if not is_admin():
            raise AUTHORITY_ERROR(u"权限不足")

        task_list = self.stask.get_task_all()
        map(self.fill_reward, task_list)
        # map(self.fill_task_params, task_list)
        task_list = [self.fill_task_params(_task) for _task in task_list]
        task_list = [_task for _task in task_list if _task]
        response = import_status("get_task_success", "OK")
        response['data'] = task_list
        return response
Exemple #24
0
 def upload_static_image(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'权限不足')
     logger.debug('get args is %s', request.args.to_dict())
     filetype = request.args.to_dict().get('filetype')
     from WeiDian.config.enums import staticimage
     if filetype not in staticimage:
         raise PARAMS_MISS('filetype is not right')
     url = BaseFile().upload_file("", "", staticimage.get(filetype))
     res = import_status("save_photo_success", "OK")
     res['data'] = url
     return res
Exemple #25
0
 def del_comment_admin(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'当前非管理员')
     data = request.json
     acoid = data.get('acoid')
     logger.debug('del comment data is %s', data)
     up_info = self.sactivitycomment.delete_comment_by_acoid(acoid)
     if not up_info:
         raise NOT_FOUND(u'要删除的数据不存在')
     data = import_status("delete_success", "OK")
     data['acoid'] = acoid
     return data
Exemple #26
0
 def add_one(self):
     """添加推荐"""
     # 此处无需添加图片, 关联商品id即可
     if not is_admin():
         return AUTHORITY_ERROR(u'当前非管理员权限')
     data = request.json
     logger.debug("data is %s", data)
     parameter_required('PRid_list')
     now_time = datetime.strftime(datetime.now(), format_for_web_second)
     restarttime = get_db_time_str(data.get('REstarttime',
                                            now_time))  # 上线时间, 默认当前时间
     restarttime_str_to_time = datetime.strptime(restarttime, format_for_db)
     days_later = datetime.strftime(
         restarttime_str_to_time + timedelta(days=7), format_for_web_second)
     reendtime = get_db_time_str(data.get('REendtime',
                                          days_later))  # 推荐下线时间, 默认7天以后
     relikefakenum = data.get('RElikenum', 0)  # 喜欢数
     refakeviewnum = data.get('REviewnum', 0)  # 浏览数
     prid_list = data.get('PRid_list')
     if not prid_list:
         raise PARAMS_MISS(u'缺失PRid_list')
     reid = str(uuid.uuid4())
     try:
         re_info = {
             # 'REid': reid,
             # 'SUid': request.user.id,
             'RElikefakenum': relikefakenum,
             'REfakeviewnum': refakeviewnum,
             'REstarttime': restarttime,
             'REendtime': reendtime,
         }
         update_info = self.srecommend.update_recommend_by_reid
     except Exception as e:
         logger.debug("add Recommend error")
         raise SYSTEM_ERROR(u'添加Recommend错误')
     try:
         for item in prid_list:
             add_model(
                 'RecommendProduct', **{
                     'REid': reid,
                     'PRid': item.get('PRid'),
                     'RPid': str(uuid.uuid4()),
                     'RPsort': item.get('RPsort')
                 })
     except Exception as e:
         logger.debug("add recommondproduct list error")
         raise SYSTEM_ERROR(u'添加每日推荐商品RecommendProduct内容出错')
     response_make_recommend = import_status('add_recommend_success', 'OK')
     response_make_recommend['data'] = {
         'reid': reid,
     }
     return response_make_recommend
Exemple #27
0
 def add_product_list(self):
     if not hasattr(request, 'user'):
         return TOKEN_ERROR  # 未登录, 或token错误
     if not is_admin():
         return AUTHORITY_ERROR  # 权限不足
     json_data = request.json
     product_list = json_data.get('products')
     logger.debug('get product list %s', product_list)
     product_list = self.fix_product_list(product_list)
     list_add_models('Product', product_list)
     data = import_status('add_product_list_success', 'OK')
     data['data'] = {'prid': self.prid_list}
     return data
Exemple #28
0
 def set_show_type(self):
     if not is_admin():
         raise TOKEN_ERROR(u'请使用管理员登录')
     data = parameter_required('skip_type')
     try:
         skip_type = str(data.get('skip_type'))
         if skip_type not in ['0', '1', '2']:
             raise TypeError()
     except TypeError as e:
         raise PARAMS_ERROR(u'参数skip_type错误')
     Partner().set_item('skip', 'skip_type', skip_type)
     response = import_status('set_success', 'OK')
     return response
Exemple #29
0
    def del_task_level(self):
        if not is_admin():
            raise AUTHORITY_ERROR(u'权限不足')
        data = request.json
        parameter_required("tlid")
        logger.debug('get del task level data, %s', data)
        tasklevel = self.stask.get_task_level_by_tlid(data.get("tlid"))
        if not tasklevel:
            return SYSTEM_ERROR(u'该任务等级不存在或已删除')
        self.stask.update_task_by_tlid(tasklevel.TLid, {"TAstatus": 4})
        self.stask.update_task_level(data.get("tlid"), {"TLisdelete": True})

        return import_status("delete_success", "OK")
Exemple #30
0
    def add_or_update_task_level(self):
        if not is_admin():
            raise AUTHORITY_ERROR(u"权限不足")
        parameter_required(*self.add_task_level)
        data = request.json
        logger.debug('get request data : %s', data)
        reward_list = data.get("reward")
        try:
            tasklevel = self.stask.get_tasklevel_by_level(
                int(data.get("TAlevel")))

            if not tasklevel:
                tlid = str(uuid.uuid1())
                self.stask.add_model(
                    "TaskLevel", **{
                        "TLid":
                        tlid,
                        "TAlevel":
                        data.get("TAlevel"),
                        "TArole":
                        data.get("TArole"),
                        "TAcomplateNotifications":
                        data.get("TAcomplateNotifications"),
                        "TLisdelete":
                        0
                    })

                for reward in reward_list:
                    self.add_task_raward(tlid, reward)

            else:
                update_result = self.stask.update_task_level(
                    tasklevel.TLid, {
                        "TAlevel":
                        data.get("TAlevel", 0),
                        "TArole":
                        data.get("TArole"),
                        "TAcomplateNotifications":
                        data.get("TAcomplateNotifications")
                    })
                if not update_result:
                    return import_status("update_data_error", "WEIDIAN_ERROR",
                                         "error_update_data")
                self.sraward.delte_task_raward_by_tlid(tasklevel.TLid)
                for reward in reward_list:
                    self.add_task_raward(tasklevel.TLid, reward)
            return import_status('add_task_success', 'OK')
        except:
            logger.exception('add or update task level error')
            return SYSTEM_ERROR(u"服务器繁忙")