示例#1
0
 def get_comment_list(self):
     """获取评论列表"""
     try:
         args = request.args.to_dict()
         acid = args.get('acid')
         if not acid:
             raise PARAMS_MISS(u'必要的参数缺失: acid;')
         reply = True if args.get('reply') else False
         page = int(args.get('page', 1))  # 页码
         # start = int(args.get('start', 0))  # 起始位置
         count = int(args.get('count', 15))  # 取出条数
         # if not start:
         #     start = (page -1) * count
         comment_list = self.sactivitycomment.get_comment_by_activity_id(
             acid, page, count, reply)
         # end = start + count
         # len_comment_list = len(comment_list)
         # if end > len_comment_list:
         #     end = len_comment_list
         # comment_list = comment_list[start: end]
         map(self.fill_user, comment_list)
         map(self.fill_comment_apply_for, comment_list)
         data = import_status('get_acvity_comment_list_success', 'OK')
         data['data'] = comment_list
         return data
     except Exception as e:
         generic_log(e)
         raise e
示例#2
0
 def __init__(self):
     try:
         self.session = DBSession.db_session()
     except Exception as e:
         # raise e
         from WeiDian.common.loggers import generic_log
         generic_log(e)
         print(e.message)
示例#3
0
 def auto_commit(self, func=None, args=[]):
     try:
         yield self.session
         self.session.commit()
     except Exception as e:
         if func is not None:
             func(*args)
         self.session.rollback()
         generic_log(e)
         raise e
     finally:
         self.session.close()
示例#4
0
    def get_comment_with_apply(self):
        """获取推文的评论列表(评论回复嵌套)"""
        try:
            args = request.args.to_dict()
            acid = args.get('acid')
            if not acid:
                raise PARAMS_MISS(u'必要的参数缺失: acid;')
            page = int(args.get('page', 1))  # 页码
            count = int(args.get('count', 15))  # 取出条数
            comment_list = self.sactivitycomment.get_comment_by_activity_id(
                acid, page, count)
            for comment in comment_list:
                self.fill_user(comment)
                comment.ACOcreatetime = get_web_time_str(comment.ACOcreatetime)
                replys = self.sactivitycomment.get_apply_by_acoid(
                    comment.ACOid)
                if replys:
                    for reply in replys:
                        comment.fill(replys, 'reply')
                        reply.hide('USid')
                        # 改: 所有的回复都是管理员回复
                        admin_user = self.ssuperuser.get_one_super_by_suid(
                            reply.USid)
                        if admin_user:
                            user = admin_user
                            admin_user.fill(0, 'robot')
                            user.hide('SUid')
                        else:
                            user = {'name': u'运营人员', 'robot': 1}
                        reply.ACOcreatetime = get_web_time_str(
                            reply.ACOcreatetime)
                        reply.fill(user, 'user')

            data = import_status('get_acvity_comment_list_success', 'OK')
            data['data'] = comment_list
            data["count"] = request.all_count
            data["page_count"] = request.page_count
            return data
        except Exception as e:
            generic_log(e)
            raise e
示例#5
0
 def get_commsion_list(self):
     """后台获取佣金统计表格"""
     if not is_admin():
         raise AUTHORITY_ERROR(u'请使用管理员账号重新登录')
     args = request.args.to_dict()
     logger.debug("Get commsion list args is %s", args)
     kw = args.get('kw')
     kw = kw.encode('utf8') if kw not in self.empty else None
     time_start = args.get('time_start')
     time_start = get_db_time_str(time_start) if time_start not in self.empty else None
     time_end = args.get('time_end')
     time_end = get_db_time_str(time_end) if time_end not in self.empty else None
     pagenum, pagesize = self.cuser.get_pagesize_pagenum(args)
     user_list, count = self.suser.get_all_partner_by_filter(pagenum, pagesize, kw)
     commision_list = []
     try:
         for user in user_list:
             usid = user.USid
             data = {
                 'usname': user.USname,
                 'usphone': user.USphone,
                 'total': self._total_commision(usid),                                     # 总额
                 'sold_income': self._user_commision(usid, 0, time_start, time_end),       # !销售佣金
                 'invite_open': self._user_commision(usid, 10, time_start, time_end),      # !邀请开店佣金
                 'fans_outincome': self._user_commision(usid, 20, time_start, time_end),   # !专粉佣金
                 'group_income': self._team_commision(usid),                               # 团队佣金
                 'remain': self._remain_commision(usid),                                   # 余额
                 'reward_income': self._user_commision(usid, 40, time_start, time_end),    # 周周奖佣金
                 'novice_reward': self._user_commision(usid, 45, time_start, time_end),    # !新手任务佣金
                 'priview': self._privew_commision(usid),                                  # 预估到帐
                 'extracting': self._extract_commision(usid)                               # 正在提现的佣金
             }
             commision_list.append(data)
     except Exception as e:
         generic_log(e)
         raise e
     response = import_status('get_success', 'OK')
     response['data'] = commision_list
     response['count'] = count
     return response
示例#6
0
    def get_all(self):
        """获取条件下的所有活动
        """
        if is_tourist():
            return AUTHORITY_ERROR(u"未登录")
        args = request.args.to_dict()
        logger.info("this is get all activity args %s", args)
        parameter_required(u'tnid')
        tnid = args.get('tnid')  # 导航id
        suid = args.get('suid')  # 管理员id
        lasting = args.get('lasting', 'true')  # 是否正在进行的活动
        acid = args.get("acid")
        if not acid:
            acid = None
        start = int(args.get('start', 0))  # 起始位置
        count = int(args.get('count', 5))  # 取出条数
        page = (args.get('page'))
        # 过滤跳转类型
        skiptype = args.get('skiptype')
        if skiptype is None:
            settings = Partner()
            skiptype = settings.get_item('skip', 'skip_type')  # 配置文件中的过滤条件(默认)
        if skiptype == 'all':
            skiptype = None
        # 分页
        if not page:
            page = int(math.floor(start / count) + 1)
        if not (tnid or suid):
            raise PARAMS_MISS(u"参数缺失")
        try:
            topnav = self.stopnav.get_topnav_by_tnid(tnid)
            if not topnav:
                raise NOT_FOUND(u'无此tnid')
            if topnav.TNtype == 2 and str(tnid) != '1':  # '1'为每日十荐页tnid
                skiptype = 0
            print(skiptype)

            now_time = None

            if str(lasting) == 'true':
                now_time = datetime.strftime(datetime.now(), format_for_db)
            activity_list = self.sactivity.get_activity_by_topnavid(
                tnid, page, count, skiptype, acid, suid, now_time)
            logger.info("get activity_list success")

            # if suid:
            #     activity_list = self.sactivity.get_activity_by_suid(suid, page, count)
            # if not activity_list:
            #     raise SYSTEM_ERROR(u'数据库错误')

            for activity in activity_list:
                self.sactivity.update_view_num(activity.ACid)
                self.fill_detail(activity)
                self.fill_like_num(activity)
                self.fill_type(activity)
                activity.fill(activity.AClinkvalue, 'aclinkvalue')
                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_list_success", "OK")
            data["count"] = request.all_count
            data["page_count"] = request.page_count
            data["data"] = activity_list
            return data
        except Exception as e:
            logger.exception("get activity error")
            generic_log(e)
            return e
示例#7
0
    def weixin_callback(self):
        """回调, 通过code, 获取用户信息"""
        try:
            args = request.args.to_dict()
            code = args.get('code')
            state = args.get('url')
            # state = state.replace('$', '#').replace('~', '?').replace('+', '=')

            wxlogin = WeixinLogin(APP_ID, APP_SECRET_KEY)
            data = wxlogin.access_token(code)
            # 这是本人的openid
            openid = data.openid
            access_token = data.access_token
            user = self.suser.get_user_by_openid(openid)
            # 是否关注 todo
            wx_subscribe = self.get_wx_response(
                get_subscribe.format(access_token, openid), "get subscribe")
            generic_log(wx_subscribe)
            # if "subscribe" not in wx_subscribe:
            #     logger.error("get subscribe error %s", wx_subscribe)
            #     raise WeixinError(u'get subscribe error')
            # wx_subscribe = dict()
            subscribe = wx_subscribe.get("subscribe", 0)
            data = wxlogin.user_info(data.access_token, data.openid)
            head = self.get_local_head(data.get('headimgurl'), openid)
            if not user:
                # 新用户
                # 这是上级openid, 而非本人openid, 根据openid获取上级身份
                upper_list = re.findall(r'openid=(.*?)&?', state)
                upper = upper_list[0] if upper_list else None
                upperd = self.suser.get_user_by_openid(upper)
                if upperd:
                    # todo 记录邀请成功时间(如果活动进行中的话
                    upperd_id = upperd.USid

                else:
                    upperd_id = None
                # 添加用户
                usid = str(uuid.uuid1())
                self.suser.add_model(
                    "User", **{
                        "USid":
                        usid,
                        "openid":
                        openid,
                        "USlastlogin":
                        datetime.datetime.now().strftime(format_for_db),
                        "USheader":
                        head,
                        "USlevel":
                        0,
                        "USgender":
                        data.get('sex'),
                        "USname":
                        data.get('nickname'),
                        "UPPerd":
                        upperd_id,
                        "unionid":
                        data.get('openid'),
                        "subscribe":
                        subscribe,
                    })
            else:
                # 老用户
                usid = user.USid
                print(usid)
                update_dict = {
                    "USlastlogin":
                    datetime.datetime.now().strftime(format_for_db),
                    "USheader": head,
                    "USgender": data.get("sex"),
                    "USname": data.get("nickname"),
                    "unionid": data.get("unionid"),
                    "subscribe": subscribe,
                }
                update_result = self.suser.update_user(usid, update_dict)
                if not update_result:
                    raise SYSTEM_ERROR()
            # 生成token
            token = usid_to_token(usid)
            userlogintime = self.suser.get_user_login_time(usid)
            now = datetime.datetime.now().strftime(format_for_db)

            is_today_first = True
            if userlogintime:
                is_today_first = bool(
                    userlogintime.USTcreatetime[:-6] < now[:-6])
            self.suser.add_model(
                "UserLoginTime", **{
                    "ULTid": str(uuid.uuid1()),
                    "USid": usid,
                    "USTip": request.remote_addr,
                    "USTcreatetime": now,
                })
            params_data = {
                "is_first": int(bool(user)),
                "subscribe": subscribe,
                "newtoken": token,
                "openid": openid,
                "access_token": access_token,
                "wximg": wximg,
                'user_level': 0 if bool(user) else user.USlevel,
                "is_today_first": int(is_today_first),
                "token": usid_to_token(usid),
                "icon": icon
            }
            # params_str = urllib.urlencode(params_data, doseq=True)

            # redirect_url = state + "?"+params_str
            # logger.debug("get loggin redirect_url %s", redirect_url)
            # return redirect(redirect_url)
            return params_data
        except WeixinError as e:
            generic_log(e)
            return SYSTEM_ERROR(u'code error')