浏览代码

意见反馈

zhangxiaobin 1 年之前
父节点
当前提交
67625c61bb

+ 58 - 0
application/api/controller/Feedback.php

@@ -0,0 +1,58 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+use think\Exception;
+
+class Feedback extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = '*';
+    protected $model;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\common\model\Feedback();
+    }
+
+    /**
+     * 意见反馈添加
+     * @return void
+     */
+    public function add()
+    {
+        try {
+            $content = $this->request->param('content','');
+            $images = $this->request->param('images','');
+            //验证参数
+            $validate = validate('Feedback');
+            if(!$validate->check($this->request->param(),[],'add')){
+                throw new Exception($validate->getError());
+            }
+            $userId  = isset($this->auth->id) ? $this->auth->id : 0;
+            $content = $content;
+            $images  = $images;
+            $limitNum = 100;//限制每月反馈数量
+            $feedbackNum = $this->model->getMonthNum($userId);
+            if ($feedbackNum >= $limitNum) {
+                throw new Exception('您反馈的意见过多,请在次月再反馈');
+            }
+            $data = [
+                'user_id' => $userId,
+                'content' => $content,
+                'images'  => $images,
+                'createtime' => time(),
+            ];
+            $addRes = $this->model->insertGetId($data);
+            if (!$addRes) {
+                throw new Exception('操作失败');
+            }
+            $this->success('操作成功');
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
+}

+ 33 - 34
application/api/controller/Party.php

@@ -12,6 +12,7 @@ use think\Exception;
 use think\exception\PDOException;
 use think\exception\ValidateException;
 use think\Request;
+use app\common\service\RoomService;
 
 /**
  * 派对信息接口
@@ -328,7 +329,6 @@ class Party extends Common
             $thispage = $this->request->request('thispage',1,"intval"); // 当前页数
             $pagenum = $this->request->request('pagenum',10,"intval"); // 每页显示条数0=不做分页
             $type_id = $this->request->request('type_id'); // 派对类型
-            $room_type = $this->request->request('room_type',1); // 房间类型:1=派对,2=直播
             $is_recommend = $this->request->request('is_recommend'); // 推荐0=否1=是
             $all = $this->request->request('all'); // 全部分类0=否1=是
             $index = $this->request->request('index',0); // 全部分类0=否1=是
@@ -345,41 +345,40 @@ class Party extends Common
             if($redisconfig['redis_selectdb'] > 0){
                 $redis->select($redisconfig['redis_selectdb']);
             }
-            $redisPartyRankList = $redis->zRevRange($this->roomTypeArr[$room_type]."Rank",0,-1,true);
-
-            $partyModel = new \app\common\model\Party();
-            if(!$redisPartyRankList) {
-                $userModel = new \app\common\model\User();
-                // 直接从数据库获取所有数据
-                $where = [];
-                $where["a.status"] = 1;
-                $where["a.is_online"] = 1;
-                $where["a.room_type"] = $room_type;
-                $sqlPartyList = $partyModel->alias("a")->field("a.*,b.name as type_name")
-                    ->join("hx_party_type b","a.party_type = b.id","left")->where($where)->select();
-                $userList = $userModel->field("id,nickname,avatar")->where(["status"=>"normal"])->select();
-                $userInfoArr = [];
-                if($userList) foreach($userList as $k => $v) $userInfoArr[$v["id"]] = $v;
-                if($sqlPartyList) {
-                    foreach($sqlPartyList as $k => $v) {
-                        // 加入缓存排序
-                        $redis->zAdd($this->roomTypeArr[$room_type]."Rank", $v['party_hot'], $v["id"]);
-                        // 设置冠名
-                        $sqlPartyList[$k]["naming"] = isset($userInfoArr[$v["naming"]])?$userInfoArr[$v["naming"]]:[];
-                        // 设置房主头像
-                        $sqlPartyList[$k]["avatar"] = isset($userInfoArr[$v["user_id"]])?$userInfoArr[$v["user_id"]]["avatar"]:[];
-                        // 加入缓存
-                        $redis->set($this->roomTypeArr[$room_type]."_".$v["id"],json_encode($v));
-                    }
-                    $redisPartyRankList = $redis->zRevRange($this->roomTypeArr[$room_type]."Rank",0,-1,true);
-                }
+            $redisPartyRankList = $redis->zRevRange("partyRank",0,-1,true);
+            $redisLiveRankList = $redis->zRevRange("liveRank",0,-1,true);
+
+            $roomService = new RoomService();
+            if(!$redisPartyRankList) {//party
+                $roomParams = ['room_type' => 1];
+                $roomPartyRes = $roomService->roomRedis($roomParams);
+                $redisPartyRankList = $roomPartyRes['data'];
+            }
+            if(!$redisLiveRankList) {//live
+                $roomParams = ['room_type' => 2];
+                $roomLiveRes = $roomService->roomRedis($roomParams);
+                $redisLiveRankList = $roomLiveRes['data'];
             }
-            if($redisPartyRankList) {
-                $resultInfo = $partyModel->getPatyInfoByPartyId($redisPartyRankList,$this->roomTypeArr[$room_type],$type_id,$is_recommend,$all,$start,$end,$index);
-                $this->success("获取成功!",$resultInfo);
-            }else{
-                $this->success("获取成功!",[]);
+            $redisRoomListIds = [];
+            $partyIds = !empty($redisPartyRankList) ? array_keys($redisPartyRankList) : [];
+            $liveIds = !empty($redisLiveRankList) ? array_keys($redisLiveRankList) : [];
+            $redisRoomListIds = array_merge($redisRoomListIds,$partyIds,$liveIds);
+            if(!empty($redisRoomListIds)) {
+                $roomListParams = [
+                    'ids' => $redisRoomListIds,
+                    'type_id' => $type_id,
+                    'is_recommend' => $is_recommend,
+                    'all' => $all,
+                    'start' => $start,
+                    'end' => $end,
+                    'index' => $index,
+                ];
+                $resultInfo = $roomService->getRoomList($roomListParams);
+                if (!$resultInfo['status']) {
+                    throw new Exception($resultInfo['msg']);
+                }
             }
+            $this->success("获取成功!",$resultInfo['data']);
         } catch (Exception $e) {;
             $this->error($e->getMessage());
         }

+ 163 - 0
application/api/controller/Usersign.php

@@ -0,0 +1,163 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+
+/**
+ * 签到
+ */
+class Usersign extends Api
+{
+    protected $noNeedLogin = [];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 配置
+     */
+    public function config()
+    {
+        $list = Db::name('signin')->order('id asc')->select();
+        //连续签到次数
+        $user_sign = Db::name('user_sign')->where(['uid' => $this->auth->id])->order('id desc')->find();
+        $yesterday_time = strtotime('yesterday'); //昨天0点时间戳
+        $today_time = $yesterday_time + 86400; //今日0点时间戳
+        if ($user_sign) {
+            if ($user_sign['createtime'] >= $yesterday_time) {
+                $data['sign_times'] = $user_sign['times']; //连续签到天数
+            } else {
+                $data['sign_times'] = 0;
+            }
+            if ($user_sign['createtime'] >= $today_time) {
+                $data['is_sign'] = 1; //今日是否签到: 1已签到 0未签到
+            } else {
+                $data['is_sign'] = 0; //今日是否签到: 1已签到 0未签到
+            }
+
+        } else {
+            $data['sign_times'] = 0; //连续签到天数
+            $data['is_sign'] = 0; //今日是否签到: 1已签到 0未签到
+        }
+
+        $data['sign_round_times'] = $data['sign_times'] % 7;
+
+        $data['list'] = $list;
+
+        $this->success('success',$data);
+    }
+
+    //签到
+    public function signin(){
+        $uid = $this->auth->id;
+
+        //记录日志
+        $data = [
+            'uid' => $uid,
+            'times' => 1,
+            'goldnum' => 0,
+            'createtime' => time(),
+        ];
+
+        $yesterday_time = strtotime('yesterday'); //昨天0点时间戳
+        $today_time = $yesterday_time + 86400; //今日0点时间戳
+        //修正当前次数
+        $check = Db::name('user_sign')->where('uid',$uid)->order('id desc')->find();
+        if($check){
+            //今天只能签一次
+            if($check['createtime'] >= $today_time){
+                $this->error('今天已经签过了');
+            }
+            if ($check['createtime'] >= $yesterday_time) {
+                $data['times'] = $check['times'] + 1; //连续签到次数
+            }
+        }
+
+        $signin_id = $data['times'] % 7;
+        if ($signin_id == 0) {
+            $signin_id = 7;
+        }
+
+        //匹配对应金币数
+        $list = Db::name('signin')->order('id asc')->column('id,goldnum');
+        $data['goldnum'] = isset($list[$signin_id]) ? $list[$signin_id] : 0 ;
+        Db::startTrans();
+        //记录日志
+        $log_id = Db::name('user_sign')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('签到失败');
+        }
+
+        //加经验
+        $userWhere['id'] = $uid;
+        $user = model('User')->where($userWhere)->lock(true)->find();
+        $userNewEmpirical = $user['empirical'] + $data['goldnum'];
+        $userUpdate['empirical'] = $userNewEmpirical;
+        // 获取用户当前经验值对应等级
+        $userconfigModel = new \app\common\model\UserLevelConfig();
+        $where = [];
+        $where["empirical"] = ["elt",$userNewEmpirical];
+        $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
+        if (!empty($userexplainstart)) {
+            if ($userexplainstart['level'] != $user['level']) {
+                $userUpdate['level'] = $userexplainstart['level'];
+            }
+        }
+        $res = model('User')->where($userWhere)->lock(true)->update();
+        if($res === false){
+            Db::rollback();
+            $this->error('经验更新失败');
+        }
+
+        /*//第七天赠送vip
+        $vip_rs = false;
+        $user_sign_gift_vipdays = intval(config('site.user_sign_gift_vipdays'));
+        if($data['times'] == 7 && $user_sign_gift_vipdays > 0){
+
+            $vip_rs = $this->gift_vip($user_sign_gift_vipdays);
+        }*/
+
+        //系统消息
+        $msg_id = \app\common\model\Message::addMessage($this->auth->id,'签到奖励','签到成功,获得金币奖励');
+
+        Db::commit();
+//        $remark = '获得金币'.$data['goldnum'];
+        /*if($vip_rs){
+            $remark .= ',vip'.$user_sign_gift_vipdays.'天';
+        }*/
+        $this->success('签到成功', $data['goldnum']);
+    }
+
+    //第七天赠送vip
+    //找出最近七天的次数
+    private function gift_vip($user_sign_gift_vipdays){
+        $start = strtotime(date('Y-m-d')) - 518400;
+        $map = [
+            'uid' => $this->auth->id,
+            'createtime' => ['gt',$start],
+        ];
+        $count = Db::name('user_sign')->where($map)->count();
+
+        if($count >= 7){
+            //赠送vip三天
+            $add_time = 86400 * $user_sign_gift_vipdays;
+
+            //有vip的续费,没有的从现在开始
+            $vip_endtime = model('wallet')->getWallet($this->auth->id,'vip_endtime');
+            if($vip_endtime <= time()){
+                $new_vip_endtime = time() + $add_time;
+            }else{
+                $new_vip_endtime = $vip_endtime + $add_time;
+            }
+            $rs = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['vip_endtime'=>$new_vip_endtime]);
+
+            if($rs === false){
+                Db::rollback();
+                $this->error('连续签到赠送vip失败');
+            }
+            return true;
+        }
+        return false;
+    }
+}

+ 14 - 0
application/common.php

@@ -549,3 +549,17 @@ function get_last_time($time = NULL) {
 
 return $text;
 }
+
+if (!function_exists('validate')) {
+    /**
+     * 实例化验证器
+     * @param string    $name 验证器名称
+     * @param string    $layer 业务层名称
+     * @param bool      $appendSuffix 是否添加类名后缀
+     * @return \think\Validate
+     */
+    function validate($name = '', $layer = 'validate', $appendSuffix = false)
+    {
+        return \think\Loader::validate($name, $layer, $appendSuffix);
+    }
+}

+ 29 - 0
application/common/model/Feedback.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace app\common\model;
+
+use think\Model;
+
+class Feedback extends Model
+{
+
+    protected $autoWriteTimestamp = 'int';
+    // 创建时间字段
+    protected $createTime = 'createtime';
+    protected $updateTime = 'updatetime';
+
+    /**
+     * 获取本月数据
+     */
+    public function getMonthNum($userId=0)
+    {
+        $dateStart = date('Y-m-01');
+        $monthStart = strtotime($dateStart);
+        $monthEnd = strtotime($dateStart . '+1 month');//月末时间戳
+        $where['user_id'] = $userId;
+        $where['createtime'] = ['egt',$monthStart];
+        $where['createtime'] = ['lt', $monthEnd];
+        $count = $this->where($where)->count();
+        return $count;
+    }
+}

+ 182 - 0
application/common/service/RoomService.php

@@ -0,0 +1,182 @@
+<?php
+
+namespace app\common\service;
+use think\Exception;
+use Redis;
+use app\common\service\TenimService;
+
+class RoomService
+{
+    private $model =  '';
+    private $redis =  '';
+    private $roomTypeArr = [];
+
+    /**
+     * 初始化方法
+     */
+    public function __construct()
+    {
+        $this->model = new \app\common\model\Party();
+        $redis = new Redis();
+        $redisconfig = config("redis");
+        $redis->connect($redisconfig["host"], $redisconfig["port"]);
+        if ($redisconfig['redis_pwd']) {
+            $redis->auth($redisconfig['redis_pwd']);
+        }
+        if($redisconfig['redis_selectdb'] > 0){
+            $redis->select($redisconfig['redis_selectdb']);
+        }
+        $this->redis = $redis;
+        $this->roomTypeArr = [1=>"party",2=>"live"];
+    }
+
+    /**
+     * 房间设置缓存
+     * @return void
+     */
+    public function roomRedis($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '',
+            'data' => [],
+        ];
+        try {
+            $room_type = isset($params['room_type']) ? $params['room_type'] : 0;
+            if (!empty($room_type)) {
+                $userModel = new \app\common\model\User();
+                // 直接从数据库获取所有数据
+                $where = [];
+                $where["a.status"] = 1;
+                $where["a.is_online"] = 1;
+                $where["a.room_type"] = $room_type;
+                $sqlPartyList = $this->model->alias("a")->field("a.*,b.name as type_name")
+                    ->join("hx_party_type b","a.party_type = b.id","left")->where($where)->select();
+                $userList = $userModel->field("id,nickname,avatar")->where(["status"=>"normal"])->select();
+                $userInfoArr = [];
+                if($userList) foreach($userList as $k => $v) $userInfoArr[$v["id"]] = $v;
+                if($sqlPartyList) {
+                    foreach($sqlPartyList as $k => $v) {
+                        // 加入缓存排序
+                        $this->redis->zAdd($this->roomTypeArr[$room_type]."Rank", $v['party_hot'], $v["id"]);
+                        // 设置冠名
+                        $sqlPartyList[$k]["naming"] = isset($userInfoArr[$v["naming"]])?$userInfoArr[$v["naming"]]:[];
+                        // 设置房主头像
+                        $sqlPartyList[$k]["avatar"] = isset($userInfoArr[$v["user_id"]])?$userInfoArr[$v["user_id"]]["avatar"]:[];
+                        // 加入缓存
+                        $this->redis->set($this->roomTypeArr[$room_type]."_".$v["id"],json_encode($v));
+                    }
+                    $redisPartyRankList = $this->redis->zRevRange($this->roomTypeArr[$room_type]."Rank",0,-1,true);
+                    $result['data'] = $redisPartyRankList;
+                }
+            }
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
+
+    /**
+     * 获取房间信息
+     */
+    public function getRoomList($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '',
+            'data' => [],
+        ];
+        try {
+            $partyIds    = isset($params['ids']) ? $params['ids'] : [];
+            $typeId      = isset($params['type_id']) ? $params['type_id'] : 0;
+            $isRecommend = isset($params['is_recommend']) ? $params['is_recommend'] : 0;
+            $all         = isset($params['is_recommend']) ? $params['all'] : 0;
+            $start       = isset($params['start']) ? $params['start'] : 1;
+            $end         = isset($params['end']) ? $params['end'] : 1;
+            $index       = isset($params['index']) ? $params['index'] : 0;
+            if(!$partyIds) throw new Exception('未获取到房间ID');;
+
+            $redisPartyInfo = $resdata = [];
+            $where['status'] = 1;
+            //$where['is_online'] = 1;
+            $where['is_close'] = 0;
+            $where['id'] = ['in',$partyIds];
+            $field = 'id,room_type,party_hot';
+            $partyData = $this->model->field($field)->where($where)->select();
+            if (!empty($partyData)) {
+                //获取房间用户信息
+                /*$tenimService = new TenimService();
+                $userParams = ['party_ids' => $partyIds];
+                $userImRes = $tenimService->getRoomUser($userParams);*/
+                foreach($partyData as $k => $v) {
+                    $roomType = $v['room_type'];
+                    $roomTypeStr = isset($this->roomTypeArr[$roomType]) ? $this->roomTypeArr[$roomType] : '';
+                    $getredisPartyInfo = $this->redis->get($roomTypeStr.'_'.$v['id']);
+                    $foreachData = json_decode($getredisPartyInfo,true);
+                    if(!$foreachData || $foreachData["is_close"] == 1) continue;
+                    if(!$foreachData || $foreachData["party_pass"] != '') continue;
+                    $mod = isset($foreachData["party_type"])?intval($foreachData["party_type"])%5:1;
+                    if(isset($foreachData["type_name"]) && $foreachData["type_name"]) {
+                        $type_name = $foreachData["type_name"];
+                    } else {
+                        $type_name = "普通房";
+                    }
+
+                    $hasdata = false;
+                    if($all == 1) {
+                        if($isRecommend == 1) {
+                            if($foreachData["is_recommend"] == 1) $hasdata = true;
+                        } else {
+                            $hasdata = true;
+                        }
+                    } elseif($typeId > 0) {
+                        if($typeId == $foreachData["party_type"]) $hasdata = true;
+                    }
+                    if($foreachData["status"] != 1) $hasdata = false;
+                    $foreachData = info_domain_image($foreachData,['party_logo']);
+                    $hasdata && $redisPartyInfo[] = [
+                        "id" => $foreachData["id"],
+                        "party_id" => $foreachData["party_id"],
+                        "r_id" => $foreachData["party_id"],
+                        "party_name" => $foreachData["party_name"],
+                        "party_pass" => $foreachData["party_pass"] ? $foreachData["party_pass"]:"",
+                        "party_hot" => $v['party_hot'],
+                        "party_logo" => $foreachData["party_logo"],
+                        "party_type" => $type_name,
+                        "avatar" => $roomType == 2 ? $foreachData["avatar"]:"",
+                        "party_type_color" => $mod == 0?5:$mod,
+                        "party_user" => isset($foreachData["party_user"]) ? array_values($foreachData["party_user"]) : [] // 当前麦位人头像
+                    ];
+                }
+
+                if($index == 1) {
+                    $num = $end - $start + 1;
+                    $countData = count($redisPartyInfo);
+                    if($num > $countData) $num = $countData;
+                    if($redisPartyInfo) {
+                        $dataRand = array_rand($redisPartyInfo,$num);
+                        $dataRand = is_array($dataRand)?$dataRand:[$dataRand];
+                        if($redisPartyInfo) {
+                            foreach($redisPartyInfo as $k => $v) {
+                                if(in_array($k,$dataRand)) $resdata[] = $v;
+                            }
+                        }
+                    }
+                } else {
+                    if($redisPartyInfo) {
+                        foreach($redisPartyInfo as $k => $v){
+                            if($k >= $start && $k <= $end) $resdata[] = $v;
+                        }
+                    }
+                }
+            }
+
+            $result['data'] = $resdata;
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
+}

+ 2 - 3
application/common/service/TenimService.php

@@ -48,15 +48,14 @@ class TenimService
             'data' => [],
         ];
         try {
-            $partyIds = isset($params['party_ids']) ? $params['party_ids'] : [];
+            $partyArr = isset($params['party_ids']) ? $params['party_ids'] : [];
             $url = "https://console.tim.qq.com/v4/group_open_avchatroom_http_svc/get_members".$this->url;
             $tencentObj = new tencentim($url);
             //获取用户 ["57","62","63","105","106","107","108","109","116","119"]
-            $partyArr = $partyIds;
             $memberList = [];
             if(!empty($partyArr)) {
                 foreach ($partyArr as $key => $value) {
-                    $data["GroupId"] = $value;
+                    $data["GroupId"] = (string)$value;
                     $tencentRes = $tencentObj->toSend($data);
                     if (isset($tencentRes['ActionStatus']) && $tencentRes['ActionStatus'] == 'OK') {
                         if (isset($tencentRes['MemberList']) && !empty($tencentRes['MemberList'])) {

+ 35 - 0
application/common/validate/Feedback.php

@@ -0,0 +1,35 @@
+<?php
+
+namespace app\common\validate;
+
+use think\Validate;
+
+class Feedback extends Validate
+{
+// 验证规则
+    protected $rule = [
+        'id'      => 'require|number',
+        'user_id' => 'require|number',
+        'content' => 'require|max:3072',
+        'images'  => 'max:3072',
+        'status'  => 'in:0,1',
+    ];
+
+    // 验证提示
+    protected $message = [
+        'id.require' => '请输入意见ID',
+        'id.number' => '您输入的意见ID,必须是数字类型',
+        'user_id.require' => '请输入用户ID',
+        'user_id.number' => '您输入的用户ID,必须是数字类型',
+        'content.require' => '请输入反馈意见',
+        'content.max' => '您输入的反馈意见,必须小于30721个字符限制',
+        'images.max' => '您输入的图片,必须小于30721个字符限制',
+        'status.in' => '状态,必须是0或1',
+    ];
+
+    // 应用场景
+    protected $scene = [
+        'add' => ['content', 'images'],
+        'edit' => ['id', 'content', 'images'],
+    ];
+}