Example #1
0
 def like_or_cancel(self):
     if not is_partner():
         return AUTHORITY_ERROR
     print '是合伙人'
     json_data = parameter_required('reid')
     reid = json_data.get('reid')
     already_like = self.srecommendlike.get_recommend_like_by_usidreid(request.user.id, reid)
     # recommend = self.srecommend.get_recommend_by_reid(reid)
     if not already_like:
         rl_dict = dict(
             rlid=str(uuid.uuid4()),
             usid=request.user.id,
             reid=reid
         )
         dict_add_models('RecommendLike', rl_dict)
         rlid = already_like.RLid if already_like else rl_dict['rlid']
         self.srecommend.add_like_num(reid)  # 数量更改
         data = import_status('add_recommend_like_success', 'OK')
         data['data'] = {'rlid': rlid}
         return data
     else:
         # 删除点赞
         self.srecommendlike.del_like(request.user.id, reid)
         self.srecommend.del_like_num(reid)
         response_make_like = import_status('cancel_recommend_like_success', 'OK')
         response_make_like['data'] = {'reid': reid}
         return response_make_like
Example #2
0
 def get_today_total(self):
     """今日"""
     if not is_partner():
         raise TOKEN_ERROR(u'请使用vip登录')
     usid = request.user.id
     # 今日营业额
     today_orders = self.sorder.get_today_order_by_usid_status(
         usid, finished_pay_status)
     sold_mount_list = [x.OImount for x in today_orders] or [0]
     sold_mount = sum(sold_mount_list)
     # 今日赚
     today_earn = sold_mount * Partner().one_level_divide
     today_earn = round(today_earn, 2)
     # 额外赚
     # todo
     other_earn = 0
     # 新衣币
     new_cloth_bit = self.sraward.get_reward_by_usid(usid)
     bit_num_list = [x.RAnumber for x in new_cloth_bit] or [0]
     bit_num_mount = sum(bit_num_list)
     response = import_status('get_today_earn_success', 'OK')
     data = {
         'sold_mount': sold_mount,
         'today_earn': today_earn,
         'other_earn': other_earn,
         'bit_num_mount': bit_num_mount
     }
     response['data'] = data
     return response
Example #3
0
    def get_image_list(self, aitype):
        if re.match(r'^[0-9]+$', str(aitype)):
            # if re.match(r'^\d', str(aitype)):
            aitype = int(aitype)
            if not 0 <= aitype < 15:

                aitype = -1
        else:
            aitype = -1

        if aitype == -1:
            if is_partner():
                adimage_list = self.sadimage.get_image_by_aitype(5)
            else:
                adimage_list = self.sadimage.get_image_by_aitype(4)
        else:
            adimage_list = self.sadimage.get_image_by_aitype(aitype)
        if not adimage_list:
            return {'aiimage': "尚未添加改图片", 'aitype': aitype}

        if aitype == 10:
            return adimage_list
        # return adimage_list[0]

        if aitype < 15:
            return adimage_list[0]
        return adimage_list
Example #4
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'服务器繁忙')
Example #5
0
    def share_activity(self):
        if is_tourist():
            raise TOKEN_ERROR(u'未登录')
        data = request.json
        logger.debug("share qrcode data is %s", data)
        # data_url = data.get("dataurl")
        data_url = self.get_share_url(data.get("dataurl"))
        try:
            logger.info("get user info")
            user = self.suser.get_user_by_user_id(request.user.id)
            if not user:
                raise SYSTEM_ERROR(u'找不到该用户')
            save_path = LinuxRoot + LinuxImgs + "/qrcode/" + user.openid + '.png' if platform.system(
            ) == "Linux" else WindowsRoot + "qrcode/" + user.openid + '.png'
            make_qrcode(user.USheader, data_url, save_path)
            response = import_status("make_qrcode_success", "OK")
            response[
                "qrcodeurl"] = QRCODEHOSTNAME + '/' + LinuxImgs + '/qrcode/' + user.openid + '.png'
            response[
                "components"] = QRCODEHOSTNAME + '/' + LinuxImgs + '/components.png'
            logger.debug('response url is %s', response["qrcodeurl"])

            url = data_url.split('#')[-1]
            from WeiDian.common.get_url_params import GetUrlParams
            parse_dict = GetUrlParams.url_params_to_dict(url)
            if 'baid' in parse_dict or 'prid' in parse_dict:
                # 分享时更改转发数
                paramstype = bool(not 'baid' in parse_dict)
                filter_parameter = {
                    'AClinkvalue':
                    parse_dict['prid'] if paramstype else parse_dict['baid'],
                    'ACSkipType':
                    2 if paramstype else 1,
                    'ACisdelete':
                    False
                }
                act_list = self.sactivity.get_acid_by_filterid(
                    filter_parameter)
                for act in act_list:
                    if act.ACforwardFakenum != 0:
                        self.sactivity.update_forward_fakenum(act.ACid)
                    else:
                        self.sactivity.add_model(
                            'ActivityFoward', **{
                                'AFid': str(uuid.uuid1()),
                                'USid': request.user.id,
                                'ACid': act.ACid
                            })

                if is_partner():

                    self.do_shoppingtask_or_forwardtask(1)
            return response
        except:
            logger.exception("make qrcode error")
            return SYSTEM_ERROR(u'服务器繁忙')
Example #6
0
 def get_all(self):
     args = request.args.to_dict()
     if not is_partner():
         return AUTHORITY_ERROR
     print '是合伙人'
     lasting = args.get('lasting', 'true')  # 有效时间内的轮播
     if lasting == 'true':
         banner_list = self.srecommendbanner.get_all_lasting_banner()
     else:
         banner_list = self.srecommendbanner.get_all_banner()
     data = import_status("get_recommendbanner_success", "OK")
     data['data'] = banner_list
     return data
Example #7
0
 def get_one(self):
     args = request.args.to_dict()
     if not is_partner():
         return AUTHORITY_ERROR
     print '是合伙人'
     rbid = args.get('rbid')
     if rbid:
         banner = self.srecommendbanner.get_one_by_rbid(rbid)
         if banner:
             banner = self.fill_product(banner)
             data = import_status("get_recommendbanner_success", "OK")
             data['data'] = banner
             return data
         else:
             return SYSTEM_ERROR
Example #8
0
 def fill_sku(self, cart):
     """
     填充选择的sku信息
     """
     pskid = cart.PSKid
     if pskid:
         sku = self.sproductskukey.get_psk_by_pskid(pskid)
         if not sku:
             return cart
         sku.add('PSKproperkey')
         # 价格计算, 合伙人优惠
         cart.PRprice = float(sku.PSKprice) * \
             Partner().one_level_divide if is_partner() else float(sku.PSKprice)
         cart.subtotal = cart.PRprice * cart.SCnums
         cart.current_sku = sku
         cart.add('current_sku', 'subtotal')
     return cart
Example #9
0
 def get_user_sub(self):
     data = request.args.to_dict()
     sub = data.get('sub')
     usid = data.get('usid')
     if sub == None:
         if not is_admin():
             raise TOKEN_ERROR(u'权限不足')
     else:
         if not is_partner():
             raise TOKEN_ERROR(u'当前非合伙人')
     logger.debug('get user sub args: %s', data)
     # parameter_required('usid')
     pagenum, pagesize = self.get_pagesize_pagenum(data)
     if usid:
         user = self.suser.get_user_by_user_id(usid)
     else:
         user = self.suser.get_user_by_user_id(request.user.id)
     user_sub, count = self.suser.get_sub_user(user.openid, pagesize,
                                               pagenum)
     response = import_status('messages_get_item_ok', 'OK')
     response['data'] = user_sub
     response['count'] = count
     return response
Example #10
0
    def get_info_top(self):
        """个人中心需要的数据"""
        try:
            if is_tourist():
                return AUTHORITY_ERROR(u"未登录")
            data = dict()
            my_info = request.user
            level = my_info.level
            uslevel = userlevel.get(str(level), '普通用户')
            level = 'partner' if level > 0 else 'ordinary'

            my_info.fill(level, 'level')
            my_info.fill(uslevel, 'uslevel')
            data.setdefault('user', my_info)
            usid = my_info.id
            print(my_info.USname).encode('utf8')
            print(my_info.USid).encode('utf8')
            logger.debug("get my info by usid")
            show = 0
            # 正在进行中的指定等级的合伙人活动
            partner_match = self.spartnermatch.get_lasting_partner_match(
                level=my_info.USlevel)
            # 如果是合伙人, 且活动进行中
            if is_partner() and partner_match:
                show = 1
                data.setdefault('match_type', partner_match.PSIMtype)
                # 成功超过vip数量
                psimid = partner_match.PSIMid
                my_achev = self.spartnermatch.get_partner_match_mount_by_usidpsmid(
                    usid, psimid)
                my_achev_value = my_achev.sellorinvitemount if my_achev else 0  # 我的销售总额(人数)

                gt_my_sell_count = self.spartnermatch.get_partner_match_mount_gt_value(
                    psimid, my_achev_value)  # 营业额(人数)比我多的
                partner_num = self.suser.get_partner_count_in_current_level(
                    request.user.USlevel)  # 该等级vip总数
                lt_my_sell_count = partner_num - gt_my_sell_count  # 比我销售(人数)少的
                partner_num = partner_num or 1
                percents = int(float(lt_my_sell_count) / partner_num *
                               100)  # 超过的同等级的百分比
                my_info.fill(percents, 'overpercents')  # 超过%的vip
                data.setdefault('myranking', percents)
                # 未完成还需多少升级
                try:
                    partner_match.PSIMrule = match_rule = json.loads(
                        partner_match.PSIMrule)
                    achev_level_value = {
                        k: int(v) - my_achev_value
                        for k, v in match_rule.items()
                        if int(v) > my_achev_value
                    }
                    #
                    if achev_level_value:  # 是否有下一级
                        next_level = sorted(achev_level_value.keys())[0]
                        # 当前等级(未用到)
                        current_level = int(next_level) - 1
                        to_next = achev_level_value[next_level]
                        my_info.fill(to_next, 'next')
                        data.setdefault('next', to_next)
                    else:
                        my_info.fill(0, 'next')
                        current_level = sorted(achev_level_value.keys())[-1]

                except ValueError as e:
                    print('保级错误')
                    my_info.fill('0', 'next')
                #     pass
                # 保级差别
            response = import_status("get_my_info_success", "OK")
            data.setdefault('show', show)
            response["data"] = data
            return response
        except Exception as e:
            logger.exception("get myinfo error")
            raise SYSTEM_ERROR()