浏览代码

Merge branch 'master' of http://git.huxiukeji.com/zhangxiaobin/ggyuyin

lizhen_gitee 1 年之前
父节点
当前提交
600fd69160

+ 24 - 13
application/api/controller/Guild.php

@@ -3,6 +3,7 @@
 namespace app\api\controller;
 
 use app\common\controller\Api;
+use app\common\service\UserService;
 use fast\Random;
 use think\Db;
 use think\Exception;
@@ -79,9 +80,9 @@ class Guild extends Api
     public function getGuildInfoNew() {
         $guild_id = $this->request->request("guild_id"); //公会ID
         $is_member = 0;
+        $user_id = $this->auth->id;
         if($guild_id <= 0) {
             $is_member = 1;
-            $user_id = $this->auth->id;
             // 获取当前用户是否是公会成员
             $idcardfind = \app\common\model\GuildJoinin::where(["user_id"=>$user_id,"status"=>0])->find();
             if($idcardfind) $this->error("您存在加入公会的申请,正在审核中,请耐心等待!");
@@ -109,32 +110,42 @@ class Guild extends Api
         // 获取公会成员总数
         $guildMemberCount = \app\common\model\GuildMember::where(["guild_id"=>$guild_id])->count("id");
         // 获取会长信息
-        //$guilderInfo = \app\common\model\User::field("avatar,nickname,u_id")->where(["id"=>$guildInfo->user_id])->find();
+        $guilderInfo = \app\common\model\User::field("avatar,nickname,u_id")->where(["id"=>$guildInfo->user_id])->find();
         // 获取房间信息
         $partyInfo = \app\common\model\Party::field("id,party_logo,party_type,is_online,party_name,party_notice_detail")->where(["id"=>$guildInfo->party_id])->find();
         $partyParams = ['party_id' => $guildInfo->party_id];
         $roomService = new RoomService();
         $partyOnlineRes = $roomService->getPartyUserList($partyParams);
         $onlineData = isset($partyOnlineRes['data']) ? $partyOnlineRes['data'] : [];
-        $partyInfo['user_list'] = isset($onlineData['user_list']) ? $onlineData['user_list'] : [];
-        $partyInfo['online_num'] = isset($onlineData['online_num']) ? $onlineData['online_num'] : 0;
-        // 派对类型
-        $partyTypeName = "普通房";
-        if(isset($partyInfo["party_type"])) {
-            $partyTypeName = \app\common\model\PartyType::where(["id"=>$partyInfo["party_type"]])->value("name");
+        if (!empty($partyInfo)) {
+            $partyInfo['user_list'] = isset($onlineData['user_list']) ? $onlineData['user_list'] : [];
+            $partyInfo['online_num'] = isset($onlineData['online_num']) ? $onlineData['online_num'] : 0;
+            // 派对类型
+            $partyTypeName = "普通房";
+            if(isset($partyInfo["party_type"])) {
+                $partyTypeName = \app\common\model\PartyType::where(["id"=>$partyInfo["party_type"]])->value("name");
+            }
+            $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1;
+            $partyInfo["party_type_color"] = $mod == 0?5:$mod;
+            $partyInfo["type_name"] = $partyTypeName;
         }
-        $mod = isset($partyInfo["party_type"])?intval($partyInfo["party_type"])%5:1;
-        $partyInfo["party_type_color"] = $mod == 0?5:$mod;
-        $partyInfo["type_name"] = $partyTypeName;
-
+        //获取家族角色
+        $userService =  new UserService();
+        $userParams = [
+            'user_id' => $user_id,
+            'guild_id' => $guild_id,
+        ];
+        $userRes = $userService->getGuildRole($userParams);
+        $guildStatus = isset($userRes['data']['guild_role']) ? $userRes['data']['guild_role'] : 4;
         // 返回参数拼接
         $res["guildInfo"] = $guildInfo; // 公会基本信息
         $res["partyInfo"] = $partyInfo; // 派对悉尼下
         $res["guildMemberInfo"] = $guildMemberInfo; // 成员列表
         $res["guildMemberCount"] = $guildMemberCount; // 成员总数
-        //$res["guilderInfo"] = $guilderInfo; // 会长
+        $res["guilderInfo"] = $guilderInfo; // 会长
         $res["is_member"] = $is_member; // 是否为派对成员
         $res['guild_status'] = $guildStatus; //家族状态
+        $res['guild_role'] = $guildStatus; //家族角色:1组长,2副族长,3成员,4非成员
         $this->success("获取成功!",$res);
     }
 

+ 1 - 1
application/api/controller/Notify.php

@@ -14,7 +14,7 @@ use addons\epay\library\Service;
  */
 class Notify extends Api
 {
-    protected $noNeedLogin = ['wechatnotify', 'wechatkjnotify'];
+    protected $noNeedLogin = ['wechatnotify', 'alipaynotify', 'wechatkjnotify'];
     protected $noNeedRight = ['*'];
 
     /**

+ 4 - 4
application/api/controller/Party.php

@@ -62,15 +62,15 @@ class Party extends Common
 
         if($room_type == 1) {
             // 2。开厅申请
-            $authInfo = \app\common\model\GuildApply::where(["user_id"=>$user_id])->find();
+            $authInfo = \app\common\model\Guild::where(["user_id"=>$user_id])->order('id desc')->find();
             if($authInfo) {
                 if($authInfo->status == 0) {
-                    $this->error("您的开厅申请还在这审核中...,请耐心等待!");
+                    $this->error("您的家族申请还在这审核中...,请耐心等待!");
                 } elseif($authInfo->status == -1) {
-                    $this->error("您的开厅申请审核未通过,请重新审核!");
+                    $this->error("您的家族申请已解散,请重新申请!");
                 }
             } else {
-                $this->error("请先申请开厅资质!");
+                $this->error("请先申请家族!");
             }
         }
 

+ 1 - 2
application/api/controller/User.php

@@ -968,9 +968,8 @@ class User extends Api
                 'idcard' => $idCard,
                 'certify_id' => '',
                 'out_trade_no' => '',
-                'status' => 0,
+                'status' => 1,
                 'createtime' => time(),
-                'updatetime' => time()
             ];
             //开启事务
             Db::startTrans();

+ 80 - 0
application/api/controller/Usercenter.php

@@ -10,6 +10,7 @@ use think\Db;
 use app\common\controller\RedisLeaderboard;
 use Redis;
 use GatewayClient\Gateway;
+use think\Exception;
 
 /**
  * 会员中心接口
@@ -1015,4 +1016,83 @@ class UserCenter extends Common
             $this->error($e->getMessage());
         }
     }
+    
+    /**
+     * 邀请详情
+     * @return void
+     */
+    public function inviteInfo()
+    {
+        try {
+            $userId = $this->auth->id;
+            $field = 'id,invite_no';
+            $where['id'] = $userId;
+            $user = model('User')->field($field)->where($where)->find();
+            $inviteNo = isset($user['invite_no']) ? $user['invite_no'] : '';
+            $todayNow = day_now();
+            $todayStart = $todayNow[0];
+            $todayEnd = $todayNow[1]+1;
+            $userMoneyLogWhere['user_id'] = $userId;
+            $userMoneyLogWhere['type'] = 15;
+            $appendWhere['createtime'] = [['egt', $todayStart],['lt', $todayEnd],'and'];
+            $todayMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->where($appendWhere)->sum('value');
+            $totalMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->sum('value');
+            //本周
+            $weekNow = week_now();
+            $userInviteWhere['user_id'] = $userId;
+            $userInviteAppendWhere['createtime'] = [['egt', $weekNow[0]],['lt', $weekNow[1]+1],'and'];
+            $userInviteModel = model('UserInvite');
+            $weekNowNum = $userInviteModel->where($userInviteWhere)->where($userInviteAppendWhere)->count();
+            //上周
+            $lastWeek = last_week();
+            $appendLastWhere['createtime'] = [['egt', $lastWeek[0]],['lt', $lastWeek[1]+1],'and'];
+            $lastWeekNum = $userInviteModel->where($userInviteWhere)->where($appendLastWhere)->count();
+            //全部
+            $totalNum = $userInviteModel->where($userInviteWhere)->count();
+            $result = [
+                'invite_no' => $inviteNo,//邀请码
+                'today_money' => $todayMoney,//今日收益
+                'total_money' => $totalMoney,//总收益
+                'week_now_num' => $weekNowNum,//本周邀请数
+                'last_week_num' => $lastWeekNum,//上周邀请数
+                'total_num' => $totalNum,//总邀请数
+            ];
+            $this->success('获取成功',$result);
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
+
+    /**
+     * 邀请列表
+     * @return void
+     */
+    public function inviteList()
+    {
+        try {
+            $userId = $this->auth->id;
+            $where['user_id'] = $userId;
+            $userInvite = model('UserInvite')->where($where)->with(['user'=>function($uQuery){
+                $uQuery->field('id,avatar,u_id,nickname');
+            }])->autopage()->order('createtime desc')->select();
+            $result = [];
+            if (!empty($userInvite)) {
+                foreach ($userInvite as $key => $value) {
+                    $user = isset($value['user']) ? $value['user'] : [];
+                    $temp = [
+                        'user_id'          => isset($user['id']) ? $user['id'] : 0,
+                        'u_id'             => isset($user['u_id']) ? $user['u_id'] : 0,
+                        'avatar'           => isset($user['avatar']) ? $user['avatar'] : 0,
+                        'nickname'         => isset($user['nickname']) ? $user['nickname'] : 0,
+                        'create_time_text' => !empty($value['createtime']) ? date('Y-m-d', $value['createtime']) : '',
+                    ];
+                    $result[] = $temp;
+                }
+            }
+
+            $this->success('获取成功',$result);
+        } catch (Exception $e) {
+            $this->error($e->getMessage());
+        }
+    }
 }

+ 46 - 0
application/common.php

@@ -704,3 +704,49 @@ if (!function_exists('curl_get')) {
         }
     }
 }
+if (!function_exists('day_now')) {
+    //返回今天的开始时间和结束时间
+    function day_now()
+    {
+        $arr = [
+            mktime(0, 0, 0, date('m'), date('d'), date('Y')),
+            mktime(23, 59, 59, date('m'), date('d'), date('Y')),
+        ];
+        return $arr;
+    }
+}
+if (!function_exists('day_yesterday')) {
+    //返回昨天开始结束时间 改造上边的方法
+    function day_yesterday()
+    {
+        $yesterday = date('d') - 1;
+        $arr       = [
+            mktime(0, 0, 0, date('m'), $yesterday, date('Y')),
+            mktime(23, 59, 59, date('m'), $yesterday, date('Y')),
+        ];
+        return $arr;
+    }
+}
+if (!function_exists('week_now')) {
+    //获取当前时间的本周开始结束时间
+    function week_now()
+    {
+        $arr = [
+            strtotime(date('Y-m-d', strtotime("-1 week Monday", time()))),
+            strtotime(date('Y-m-d', strtotime("+0 week Sunday", time()))) - 1
+        ];
+
+        return $arr;
+    }
+}
+if (!function_exists('last_week')) {
+    //返回上周开始和结束的时间戳
+    function last_week()
+    {
+        $arr = [
+            strtotime('last week Monday', time()),
+            strtotime('last week Sunday +1 days -1 seconds', time())
+        ];
+        return $arr;
+    }
+}

+ 5 - 0
application/common/model/UserInvite.php

@@ -11,4 +11,9 @@ class UserInvite extends Model
     // 定义时间戳字段名
     protected $createTime = 'createtime';
     protected $updateTime = 'updatetime';
+
+    public function user()
+    {
+        return $this->hasOne('User', 'id', 'invite_user_id',[],'LEFT');
+    }
 }

+ 4 - 2
application/common/model/Wallet.php

@@ -67,7 +67,7 @@ class Wallet extends Model
      * @return array[log_table]
      * @return array[log_id]
      */
-    public function lockChangeAccountRemain($user_id,$money,$mode,$before,$remark='',$logtype='',$accountType='money')
+    public function lockChangeAccountRemain($user_id,$money,$mode,$before,$remark='',$logtype='',$accountType='money',$inviteId=0)
     {
         //初始化
         $result = array(
@@ -134,7 +134,9 @@ class Wallet extends Model
             $data['detail'] = $remark;
             $data['createtime'] = time();
             $data['type'] = $logtype;
-
+            if ($accountType == 'money') {//用户邀请充值赠送上级金额,绑定赠送的用户ID
+                $data['invite_user_id'] = $inviteId;
+            }
             //新的方式
             $rs1 = Db::name('user')->where(['id'=>$user_id])->update([$accountType => $data['balance']]);
 

+ 51 - 5
application/common/service/UserService.php

@@ -154,22 +154,22 @@ class UserService
         try {
             $userId = isset($params['user_id']) ? $params['user_id'] : 0;
             if (!empty($userId)) {
-                $field = 'id,pre_user_id,money';
+                $field = 'id,pre_userid,money';
                 $where['id'] = $userId;
                 $user = model('User')->field($field)->where($where)->find();
                 if (!empty($user)) {
-                    if (!empty($user['pre_user_id'])) {
-                        $preWhere['id'] = $user['pre_user_id'];
+                    if (!empty($user['pre_userid'])) {
+                        $preWhere['id'] = $user['pre_userid'];
                         $preUser = model('User')->field($field)->where($preWhere)->find();
                         if (!empty($preUser)) {
                             //查看是否赠送过金额
                             $moneyLogWhere['invite_user_id'] = $userId;
                             $moneyLogWhere['type'] = 15;
                             $moneyLog = model('UserMoneyLog')->where($moneyLogWhere)->find();
-                            if (empty($moneyLogWhere)) {
+                            if (empty($moneyLog)) {
                                 $money = config('site.invite_money');
                                 $remark = '邀请用户充值赠送金额';
-                                $res = model('Wallet')->lockChangeAccountRemain($preUser['id'],$money,'+',$preUser['money'],$remark,15);
+                                $res = model('Wallet')->lockChangeAccountRemain($preUser['id'],$money,'+',$preUser['money'],$remark,15,'money',$userId);
                                 if (!$res['status']) {
                                     throw new Exception($res['msg']);
                                 }
@@ -184,4 +184,50 @@ class UserService
         }
         return $result;
     }
+
+    /**
+     * 获取用户家族角色
+     * @return void
+     */
+    public function getGuildRole($params=[])
+    {
+        $result = [
+            'status' => 1,
+            'msg' => '操作成功',
+            'data' => [],
+        ];
+        try {
+            $userId = isset($params['user_id']) ? $params['user_id'] : 0;
+            $guildId = isset($params['guild_id']) ? $params['guild_id'] : 0;
+            if (empty($userId) || empty($guildId)) {
+                throw new Exception('参数错误');
+            }
+            $guildWhere['id'] = $guildId;
+            $guild = model('Guild')->where($guildWhere)->find();
+            if (empty($guild)) {
+                throw new Exception('未找到家族信息');
+            }
+            $guildRole = 4;//家族角色:1组长,2副族长,3成员,4非成员
+            if ($userId == $guild['user_id']) {
+                $guildRole = 1;
+            }
+            $guildMemberWhere['guild_id'] = $guildId;
+            $guildMemberWhere['user_id'] = $userId;
+            $guildMember = model('GuildMember')->field('id,role')->where($guildMemberWhere)->find();
+            if (!empty($guildMember)) {
+                if ($guildMember['role'] == 0) {
+                    $guildRole = 3;
+                } elseif ($guildMember['role'] == 1) {
+                    $guildRole = 2;
+                }
+            }
+            $result['data'] = [
+                'guild_role' => $guildRole,
+            ];
+        } catch (Exception $e) {
+            $result['status'] = 0;
+            $result['msg'] = $e->getMessage();
+        }
+        return $result;
+    }
 }