Beispiel #1
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
Beispiel #2
0
 def get_accountinfo(self):
     if is_tourist():
         return AUTHORITY_ERROR(u"未登录")
     usid = request.user.id
     user = self.suser.get_user_by_user_id(usid)
     logger.debug("get info success, this user is %s", user.USname)
     default_address = self.suesraddress.get_default_address_by_usid(usid)
     if not default_address:
         first_address = self.suesraddress.get_first_no_default_address(
             usid)
     address = default_address or first_address
     if address:
         logger.info("get user address success")
         location = self.suesraddress.get_addressinfo_by_areaid(
             address.areaid)
         logger.info("get address detail success")
         for area, city, provice in location:
             locationname = getattr(provice, "name", '') + getattr(
                 city, "name", '') + getattr(area, "name", '')
     else:
         locationname = ''
     # print ''.join([x[1] for x in area])
     bankcard = self.sbankcard.get_bankcard_by_usid(usid)
     response = import_status("get_accountinfo_success", "OK")
     response['data'] = {
         "user": user.hide('USid'),
         # "address": '%s%s' %(locationname, address.UAtext),
         "address": '%s%s' % (locationname, getattr(address, "UAtext", '')),
         "bankcard": getattr(bankcard, "BCnumber", '')
     }
     return response
Beispiel #3
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
Beispiel #4
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
Beispiel #5
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
Beispiel #6
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
Beispiel #7
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
Beispiel #8
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
Beispiel #9
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
Beispiel #10
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
Beispiel #11
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
Beispiel #12
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
Beispiel #13
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")
Beispiel #14
0
 def get_one(self):
     """通过acid获取活动及活动下的评论
     """
     if is_tourist():
         return AUTHORITY_ERROR(u"未登录或token错误")
     args = request.args.to_dict()
     logger.info("get one act args is %s", args)
     parameter_required('acid')
     acid = args.get('acid')  # 活动id
     try:
         activity = self.sactivity.get_activity_by_acid(acid)
         logger.debug("get one act access")
         if not activity:
             raise SYSTEM_ERROR(u'数据错误,无此内容')
         self.sactivity.update_view_num(activity.ACid)
         self.fill_detail(activity)
         self.fill_like_num(activity)
         self.fill_type(activity)
         if activity.ACSkipType == 0:
             self.fill_comment_two(activity)
             activity.fill('none_skip', 'skip_type')
             activity.fill('无跳转类型', 'zh_skip_type')
         elif activity.ACSkipType == 1:
             baid = activity.AClinkvalue
             activity.fill('bigactivity', 'skip_type')
             activity.fill('专题', 'zh_skip_type')
             bigactivity = self.sbigactivity.get_one_big_act(baid)
             if not bigactivity:
                 # raise NOT_FOUND()
                 pass
             else:
                 bigactivity_type = bigactivity.BAtype
                 big_activity_content = {'type': bigactivity_type}
                 big_activity_content.setdefault('baid', bigactivity.BAid)
                 # 图片类型专题
                 if bigactivity_type == 0:
                     big_activity_content.setdefault(
                         'baimage', bigactivity.BAlongimg)  # 返回字段不修改
                     big_activity_content.setdefault(
                         'baid', bigactivity.BAid)
                 activity.fill(big_activity_content, 'bigactivity')
         elif activity.ACSkipType == 2:
             self.fill_soldnum(activity)
             self.fill_product(activity)
             activity.fill('product', 'skip_type')
             activity.fill('商品', 'zh_skip_type')
         activity.ACstarttime = get_web_time_str(activity.ACstarttime)
         activity.ACendtime = get_web_time_str(activity.ACendtime)
         data = import_status("get_activity_info_success", "OK")
         data["data"] = activity
         return data
     except:
         logger.exception("get one act error")
         return SYSTEM_ERROR(u"服务器繁忙")
Beispiel #15
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
Beispiel #16
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
Beispiel #17
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
Beispiel #18
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
Beispiel #19
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
Beispiel #20
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
Beispiel #21
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")
Beispiel #22
0
 def del_rewardpacket(self):
     """删除优惠券集合"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'非管理员权限')
     data = request.json
     logger.debug("del reward packet id is %s", data)
     rptid = data.get('rptid')
     del_info = self.sraward.update_reward_packet({'RPTid': rptid}, {'RPTisdelete': True})
     self.sraward.del_packet_contact({'RPTid': rptid})
     if not del_info:
         raise NOT_FOUND(u'删除失败')
     data = import_status("delete_success", "OK")
     data['data'] = {'rptid': rptid}
     return data
Beispiel #23
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"服务器繁忙")
Beispiel #24
0
 def get_exist_tags(self):
     if not is_admin():
         raise AUTHORITY_ERROR(u'非管理员权限')
     args = request.args.to_dict()
     logger.debug("get tags args is %s", args)
     try:
         tags_list = self.stags.get_exist_tags()
         logger.info("try to get tags")
         response = import_status("messages_get_item_ok", "OK")
         response['data'] = {"tags_list": tags_list}
         return response
     except Exception as e:
         logger.exception("get exist tags error")
         raise SYSTEM_ERROR(u"数据错误")
Beispiel #25
0
 def create_rewardpacket(self):
     """创建优惠券集合"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'非管理员权限')
     data = request.json
     logger.debug("create reward packet data is %s", data)
     rptid = str(uuid.uuid1())
     self.sraward.add_model('RewardPacket', **{
         'RPTid': rptid,
         'SUid': request.user.id,
         'RPTname': data.get('name')
     })
     data = import_status("create_reward_packet_success", "OK")
     data['data'] = {'rptid': rptid}
     return data
Beispiel #26
0
    def get_user_task(self):
        if is_tourist():
            raise AUTHORITY_ERROR(u"未登录")
        task_list = self.stask.get_user_task_by_userid(request.user.id)
        if not task_list:
            return SYSTEM_ERROR(u'当前没有任务')

        # task_list = self.fill_task_detail(task) for task in task_list
        task_detail_list, task_list = task_list, []
        for task in task_detail_list:
            task_detail = self.fill_task_detail(task)
            if task_detail:
                task_list.append(task_detail)
        if not task_list:
            return SYSTEM_ERROR(u'当前没有任务')

        task_level = self.stask.get_task_level_by_tlid(task_list[0].TLid)
        if not task_level:
            raise SYSTEM_ERROR(u'任务正在更新,请稍后查看')
        logger.debug('get task list %s', dict(task_level))
        # from WeiDian.common.divide import Partner
        # pa = Partner()
        # role = pa.cf.get(task_level, 'role')
        # cn = pa.cf.get(task_level, 'access')

        # map(self.fill_reward, task_list)
        is_complate = not bool(
            len([task.TUstatus for task in task_list if task.TUstatus == 0]))
        # logger.debug(len(is_complate))
        # logger.debug(request.user.id)
        # logger.debug(len(task_list))
        response = import_status("get_task_success", "OK")
        if is_complate:
            # 更新任务状态为已失效,发放奖励。并且添加新的任务内容
            self.stask.update_user_tasks(request.user.id, {"TUstatus": 4})
            self.add_user_task_raward(request.user.id, task_level.TLid)
            if task_level.TAlevel < 3:
                self.add_user_task(request.user.id, task_level.TAlevel)
        response['RAward'] = self.fill_reward(task_level)
        response['data'] = task_list
        response['TArole'] = task_level.TArole
        response[
            'TAcomplateNotifications'] = task_level.TAcomplateNotifications
        response['is_complate'] = is_complate

        return response
Beispiel #27
0
    def delete_product(self):
        if not is_admin():
            return AUTHORITY_ERROR(u'权限不足')
        data = parameter_required('productid')
        logger.debug('get delete_product data %s', data)
        product = self.sproduct.get_product_by_productid(data.get('productid'))
        if not product:
            return import_status('no_product', 'OK')

        update_result = self.sproduct.update_product_by_productid(
            data.get('productid'), {
                "PRisdelete": True,
                'PRmodifytime': get_db_time_str()
            })
        if not update_result:
            raise SYSTEM_ERROR(u'服务器繁忙')
        return import_status('delete_product_success', 'OK')
Beispiel #28
0
 def add_comment(self):
     """添加评论数据"""
     if is_tourist():
         return AUTHORITY_ERROR(u'未登录')
     data = parameter_required(u'ACtext')
     acid = data.get('acid')
     acoid = data.get('acoid')
     usid = request.user.id
     actext = data.get('ACtext')
     # 添加评论
     if acid:
         activity = self.sactivity.get_activity_by_acid(acid)
         if not activity:
             raise NOT_FOUND(u'推文不存在')
         model_data = {
             'ACOid': str(uuid.uuid4()),
             'ACid': acid,
             'USid': usid,
             'ACtext': actext,
             'ACOcreatetime': datetime.strftime(datetime.now(),
                                                format_for_db)
         }
     # 如果是添加回复
     elif acoid:
         if not is_admin():
             raise TOKEN_ERROR(u'请使用管理员回复')
         comment = self.sactivitycomment.get_comment_by_acoid(acoid)
         if not comment:
             raise NOT_FOUND(u'不存在的评论')
         acid = comment.ACid
         model_data = {
             'ACOid': str(uuid.uuid4()),
             'ACid': acid,
             'ACOparentid': acoid,
             'USid': request.user.id,
             'ACtext': actext,
             'ACOcreatetime': datetime.strftime(datetime.now(),
                                                format_for_db)
         }
     else:
         raise PARAMS_MISS(u'请指定回复类型')
     self.sactivity.add_model('ActivityComment', **model_data)
     data = import_status('add_activity_comment_success', 'OK')
     data['data'] = {'acoid': model_data['ACOid']}
     return data
Beispiel #29
0
    def add_image(self):
        if not is_admin():
            return AUTHORITY_ERROR(u"权限不足")
        # parameter_required(*self.add_image_params)
        data = request.json
        adimage_list_web = data.get("adimage", [])
        if not adimage_list_web:
            raise PARAMS_MISS('adimage')
        for adimage_web in adimage_list_web:
            aitype = int(adimage_web.get("aitype"))
            if not adimage_web.get("aiimage") or not (0 <= aitype < 15):
                continue
            adimage = {
                'AIimage': adimage_web.get("aiimage"),
                'AItype': adimage_web.get("aitype"),
                'AIsize': adimage_web.get("aisize"),
                'ACid': adimage_web.get("acid"),
            }

            adimage_list = self.sadimage.get_image_by_aitype(aitype)
            if aitype != 10:
                if adimage_list:
                    update_result = self.sadimage.update_image(
                        adimage_list[0].AIid, adimage)
                    if not update_result:
                        raise SYSTEM_ERROR(u"数据更新异常")
                else:
                    adimage['AIid'] = str(uuid.uuid1())
                    self.sadimage.add_model("AdImage", **adimage)

            else:
                if len(adimage_list) == 3:
                    adimage['AIcreatetime'] = get_db_time_str()
                    update_result = self.sadimage.update_image(
                        adimage_list[1].AIid, adimage)
                    if not update_result:
                        raise SYSTEM_ERROR(u"数据更新异常")
                else:
                    adimage['AIid'] = str(uuid.uuid1())
                    self.sadimage.add_model("AdImage", **adimage)

        return import_status('save_photo_success', 'OK')
Beispiel #30
0
    def get_image_by_aitype(self):
        if is_tourist():
            raise AUTHORITY_ERROR(u"未登录")
        aitype = request.args.to_dict().get("aitype", "")
        logger.debug('get aitype %s, and type of aitype %s', aitype,
                     type(aitype))

        if re.search(r'\[', aitype):
            aitype = json.loads(aitype)
            adimage_list = [
                self.get_image_list(aitype_item) for aitype_item in aitype
            ]
        else:
            adimage_list = self.get_image_list(aitype)
        res = import_status('get_adimage_success', 'OK')
        if adimage_list:
            res['data'] = adimage_list
            return res
        res['message'] = u'尚未添加图片'
        return res