Usercenter.php 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425
  1. <?php
  2. namespace app\api\controller;
  3. use addons\epay\library\Service;
  4. use app\api\controller\Common;
  5. use app\api\validate\user\Report;
  6. use app\common\model\UserPower;
  7. use app\common\service\TenimService;
  8. use outh\outh;
  9. use think\Db;
  10. use app\common\controller\RedisLeaderboard;
  11. use Redis;
  12. use GatewayClient\Gateway;
  13. use think\Exception;
  14. /**
  15. * 会员中心接口
  16. */
  17. class UserCenter extends Common
  18. {
  19. protected $noNeedLogin = ['shujuhuifu','getAnchorType','getRecharConfig','getExchangeConfig','getLevelExplain'];
  20. protected $noNeedRight = '*';
  21. public function _initialize()
  22. {
  23. parent::_initialize();
  24. $this->userModel = new \app\common\model\User();
  25. }
  26. /**
  27. * 获取当前用户信息
  28. */
  29. public function getMyUserInfo() {
  30. $this->success("获取成功!",$this->auth->getUserinfo());
  31. }
  32. /**
  33. * 获取个人信息
  34. */
  35. public function getUserInfo() {
  36. $user_id = $this->request->param("user_id");
  37. if (!$user_id) {
  38. $this->error(__('Invalid parameters'));
  39. }
  40. // 获取基本信息
  41. $where = [];
  42. $where["id"] = $user_id;
  43. $userInfo = $this->userModel->field("id,nickname,pre_nickname,image,mobile,avatar,pre_avatar,gender,age,u_id,level,
  44. age_id,constellation_id,province_id,city_id,desc,ipaddress,is_cool,is_manager,is_stealth,charm_level,wealth_level")->where($where)->find();
  45. //用户钱包
  46. $userwallet = Db::name('user_wallet')->where('user_id',$user_id)->find();
  47. $userInfo['money'] = $userwallet['money'];
  48. $userInfo['jewel'] = $userwallet['jewel'];
  49. $userInfo['nickname_status'] = $userInfo['avatar_status'] = 0;
  50. if (!empty($userInfo['pre_nickname']) && $userInfo['pre_nickname'] != $userInfo['nickname']) {
  51. $userInfo['nickname_status'] = 1;
  52. }
  53. if (!empty($userInfo['pre_avatar']) && $userInfo['pre_avatar'] != $userInfo['avatar']) {
  54. $userInfo['avatar_status'] = 1;
  55. }
  56. $userInfoA = $this->userModel->getAppendData($userInfo);
  57. $userInfo['age_text'] = $userInfoA['age_text'];
  58. $userInfo['constellation_text'] = $userInfoA['constellation_text'];
  59. $userInfo['province_text'] = $userInfoA['province_text'];
  60. $userInfo['city_text'] = $userInfoA['city_text'];
  61. $userInfo['friends_num'] = $userInfoA['friends_num'];
  62. $userInfo['look_num'] = $userInfoA['look_num'];
  63. // 获取技能信息
  64. $skillList = Model("ViewUserSkill")->getSkillInfo($user_id);
  65. $userInfo["skill"] = implode("/",$skillList);
  66. // 获取关注粉丝信息
  67. $followModel = new \app\common\model\ViewFollows();
  68. $fansModel = new \app\common\model\ViewFans();
  69. // 获取关注信息
  70. $where = [];
  71. $where["user_id"] = $user_id;
  72. $userCount = $followModel->where($where)->value("follows"); //该用户关注了几个人
  73. $userInfo["follows_count"] = $userCount?$userCount:0;
  74. $userInfo["follows"] = $userInfo["follows_count"];//前端字段使用不一致添加
  75. // 获取粉丝数
  76. $where = [];
  77. $where["user_id"] = $user_id;
  78. $fansCount = $fansModel->where($where)->value("fans"); //该用户的粉丝数
  79. $userInfo["fans_count"] = $fansCount?$fansCount:0;
  80. $userInfo["fans"] = $userInfo["fans_count"];//前端字段使用不一致添加
  81. // 获取贵族信息
  82. $nobleInfo = $this->userModel->getUserNobleInfo($user_id);
  83. // 查看者是否已关注
  84. $followid = \app\common\model\UserFansFollow::where(["fans_id"=>$this->auth->id,"user_id"=>$user_id])->value("id");
  85. $userInfo["is_follow"] = $followid>0?1:0;
  86. $userInfo = json_decode(json_encode($userInfo),true);
  87. $userInfo = array_merge($userInfo,$nobleInfo);
  88. // 获取用户在派对直播间情况信息
  89. $redis = new Redis();
  90. $redisconfig = config("redis");
  91. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  92. if ($redisconfig['redis_pwd']) {
  93. $redis->auth($redisconfig['redis_pwd']);
  94. }
  95. if($redisconfig['redis_selectdb'] > 0){
  96. $redis->select($redisconfig['redis_selectdb']);
  97. }
  98. $livingUserPartyId = $redis->hGet("livingUser", $user_id);
  99. $userInfo['party_info'] = json([]);
  100. if ($livingUserPartyId) {
  101. $party = \app\common\model\Party::where('id',$livingUserPartyId)->field('id,room_type')->find();
  102. $userInfo['party_info'] = ['party_id' => $party['id'], 'room_type' => $party['room_type']];
  103. }
  104. $blackWhere['user_id'] = $this->auth->id;
  105. $blackList = model('UserBlacklist')->where($blackWhere)->select();
  106. $blackIds = !empty($blackList) ? array_column($blackList,'black_user_id') : [];
  107. $userInfo['is_black'] = in_array($user_id,$blackIds) ? 1 : 0;
  108. $memberinfo = Db::name('guild_member')->alias('m')->field('m.id as `member_id`,m.user_id,guild.name,guild.image,guild.member,guild.desc')->join('guild','m.guild_id = guild.id','LEFT')->where(['m.user_id'=>$user_id,'m.status'=>1])->find();
  109. if ($memberinfo) {
  110. $userInfo['memberinfo'] = $memberinfo;
  111. }
  112. //家族信息
  113. $guildField = 'g.id,g.g_id,g.user_id,g.party_id,g.name,g.image,g.desc,g.member,g.status';
  114. $guildWhere['gm.user_id'] = $user_id;
  115. $guildWhere['g.status'] = 1;
  116. $guildInfo = model('Guild')->alias('g')->field($guildField)
  117. ->join('guild_member gm','gm.guild_id = g.id','LEFT')
  118. ->where($guildWhere)->order('id desc')->find();
  119. $userInfo['guild_info'] = !empty($guildInfo) ? $guildInfo : [];
  120. $guildStatus = -2;
  121. if (!empty($guildInfo)) {
  122. $guildStatus = (int)$guildInfo['status'];
  123. }
  124. $userInfo['guild_status'] = $guildStatus;//家族状态:公会状态:0=待审核,1=正常,-1=已解散,-2无公会
  125. //动态
  126. //技能
  127. //礼物
  128. if (empty($this->auth->power)) {
  129. $power = UserPower::where(['user_id'=>$user_id])->find();
  130. } else {
  131. $power = $this->auth->power;
  132. }
  133. $userInfo['user_power'] = $power;
  134. //访客记录
  135. if ($this->auth->id != $user_id) {
  136. $visit_data = [
  137. 'user_id' => $this->auth->id,
  138. 'visit_user_id' => $user_id,
  139. ];
  140. $visit_check = Db::name('user_visitlist')->where($visit_data)->find();
  141. if(empty($visit_check)){
  142. $visit_data['updatetime'] = time();
  143. Db::name('user_visitlist')->insertGetId($visit_data);
  144. }else{
  145. Db::name('user_visitlist')->where('id',$visit_check['id'])->update(['updatetime'=>time()]);
  146. }
  147. }
  148. //贡献等级
  149. $charm_info = Db::name('user_config_charm')->where('level',$userInfo['charm_level'])->find();
  150. $userInfo['charm_image'] = localpath_to_netpath($charm_info['image']);
  151. $userInfo['charm_color'] = $charm_info['color'];
  152. //财富等级
  153. $wealth_info = Db::name('user_config_wealth')->where('level',$userInfo['wealth_level'])->find();
  154. $userInfo['wealth_image'] = localpath_to_netpath($wealth_info['image']);
  155. $userInfo['wealth_color'] = $wealth_info['color'];
  156. $this->success("获取成功!",$userInfo);
  157. }
  158. /**
  159. * 添加关注
  160. */
  161. public function addFollows() {
  162. $user_id = $this->request->request("user_id",0,"intval");// 被关注者ID
  163. $type = $this->request->request("type",1);// 类型:1=关注,2=取消关注
  164. if (!$user_id || $user_id<=0) {
  165. $this->error(__('Invalid parameters'));
  166. }
  167. if($type == 1) {
  168. if($user_id == $this->auth->id) {
  169. $this->error("不需要关注自己哦!");
  170. }
  171. $fansfollowModel = new \app\common\model\UserFansFollow();
  172. $data = [];
  173. $data["user_id"] = $user_id;
  174. $data["fans_id"] = $this->auth->id;
  175. if($fansfollowModel->where($data)->find()) {
  176. $this->error("你已经关注过ta啦!");
  177. }
  178. $data["createtime"] = time();
  179. $id = $fansfollowModel->insertGetId($data);
  180. //关注通知
  181. $msgdata = [
  182. 'user_id'=>$user_id,
  183. 'title' => '有人刚刚关注了你',
  184. 'content'=> '打开[消息][最新关注]即可查看',
  185. 'createtime' => time(),
  186. ];
  187. Db::name('message')->insertGetId($msgdata);
  188. if($id > 0) {
  189. // 增加任务进度 +exp
  190. \app\common\model\TaskLog::tofinish($this->auth->id,"ebxLwnXj3L",1);
  191. // 增加任务进度 +exp
  192. \app\common\model\TaskLog::tofinish($this->auth->id,"iA1QgRhL",1);
  193. // 增加任务进度 +exp
  194. \app\common\model\TaskLog::tofinish($this->auth->id,"ghopE4Ou",1);
  195. // 增加任务进度 +exp
  196. \app\common\model\TaskLog::tofinish($this->auth->id,"TryNGc1x",1);
  197. $this->success("关注成功!");
  198. } else {
  199. $this->error("网络错误,请稍后重试!");
  200. }
  201. } else {
  202. $fansfollowModel = new \app\common\model\UserFansFollow();
  203. $where = [];
  204. $where["user_id"] = $user_id;
  205. $where["fans_id"] = $this->auth->id;
  206. $fansfollowInfo = $fansfollowModel->where($where)->find();
  207. if(!$fansfollowInfo) {
  208. $this->error("关注信息获取失败!");
  209. }
  210. $res = $fansfollowModel->where($where)->delete();
  211. if($res > 0) {
  212. $this->success("取消成功!");
  213. } else {
  214. $this->error("网络错误,请稍后重试!");
  215. }
  216. }
  217. }
  218. /**
  219. * 是否关注
  220. */
  221. public function isFollows() {
  222. $user_id = $this->request->request("user_id",0,"intval");// 关注者ID
  223. if (!$user_id || $user_id<=0) {
  224. $this->error(__('Invalid parameters'));
  225. }
  226. $fansfollowModel = new \app\common\model\UserFansFollow();
  227. $where = [];
  228. $where["user_id"] = $user_id;
  229. $where["fans_id"] = $this->auth->id;
  230. $fansfollowInfo = $fansfollowModel->where($where)->find();
  231. $data = [];
  232. if($fansfollowInfo) {
  233. $data["is_show_follow"] = 0;
  234. } else {
  235. $data["is_show_follow"] = 1;
  236. }
  237. $this->success("获取成功!",$data);
  238. }
  239. /**
  240. * 获取关注人列表.派对信息
  241. */
  242. public function getFollowsLive() {
  243. $is_online = $this->request->request("is_online");// 是否在线:1=直播中,0=未开播
  244. $page = $this->request->request('page',1); // 分页
  245. $pageNum = $this->request->request('pageNum',10); // 分页
  246. // 分页搜索构建
  247. $pageStart = ($page-1)*$pageNum;
  248. $is_online == 1 || $is_online = 0;
  249. $fanfollowModel = new \app\common\model\UserFansFollow();
  250. $where = [];
  251. $where["a.fans_id"] = $this->auth->id;
  252. $where["p.room_type"] = 2;
  253. $where["p.is_online"] = $is_online;
  254. if($is_online == 1) {
  255. $field = "p.id as party_id,u.u_id,u.nickname,p.party_name,p.party_hot,p.party_logo,u.avatar,t.id as party_type";
  256. } else {
  257. $field = "p.id as party_id,a.user_id,u.avatar,u.gender,u.level,u.nickname,p.party_name,p.party_logo,t.id as party_type";
  258. }
  259. $list = $fanfollowModel->alias("a")
  260. ->field($field)
  261. ->join("hx_user u","u.id = a.user_id")
  262. ->join("hx_party p","p.user_id = a.user_id")
  263. ->join("hx_party_type t","t.id = p.party_type","left")
  264. ->limit($pageStart,$pageNum)
  265. ->where($where)->select();
  266. if($list) {
  267. foreach($list as $k => $v) {
  268. $mod = isset($v["party_type"])?intval($v["party_type"])%5:1;
  269. if(isset($v["type_name"]) && $v["type_name"]) {
  270. $type_name = $v["type_name"];
  271. } else {
  272. $type_name = "普通房";
  273. }
  274. $list[$k]["party_type"] = $type_name;
  275. $list[$k]["party_type_color"] = $mod == 0?5:$mod;
  276. }
  277. $this->success("获取成功!",$list);
  278. } else {
  279. $this->success("数据为空!",[]);
  280. }
  281. }
  282. /**
  283. * 获取关注列表
  284. * (个人中心模块)(消息-最新关注)
  285. */
  286. public function getFollowsUser() {
  287. $type = $this->request->request('type',1); // 1=关注,2=粉丝,3=好友
  288. $page = $this->request->request('page',1); // 分页
  289. $pageNum = $this->request->request('pageNum',10); // 分页
  290. // 分页搜索构建
  291. $pageStart = ($page-1)*$pageNum;
  292. $pageEnd = $pageStart + $pageNum;
  293. $fanfollowModel = new \app\common\model\UserFansFollow();
  294. // 获取关注列表
  295. $where = [];
  296. $where["a.fans_id"] = $this->auth->id;
  297. $followlist = $fanfollowModel->alias("a")
  298. ->field("a.id,a.user_id,a.createtime,u.avatar,u.nickname,u.level,u.gender,u.desc")
  299. ->join("hx_user u","u.id = a.user_id")
  300. // ->limit($pageStart,$pageNum)
  301. ->where($where)->order('a.id desc')->select();
  302. $followlist = list_domain_image($followlist,['avatar']);
  303. // 获取粉丝列表
  304. $where = [];
  305. $where["a.user_id"] = $this->auth->id;
  306. $fanslist = $fanfollowModel->alias("a")
  307. ->field("a.id,a.fans_id,a.createtime,u.avatar,u.nickname,u.level,u.gender,u.desc")
  308. ->join("hx_user u","u.id = a.fans_id")
  309. // ->limit($pageStart,$pageNum)
  310. ->where($where)->order('a.id desc')->select();
  311. $fanslist = list_domain_image($fanslist,['avatar']);
  312. // print_r(json_encode($followlist));exit;
  313. if($type == 1) {
  314. $ids = [];
  315. if($fanslist) {
  316. foreach($fanslist as $k => $v) {
  317. $ids[] = $v["fans_id"];
  318. }
  319. }
  320. if($followlist) {
  321. foreach($followlist as $k => $v) {
  322. $followlist[$k]['createtime_text'] = get_last_time($v['createtime']);
  323. $followlist[$k]["is_follow"] = 1;
  324. if(in_array($v["user_id"],$ids)) {
  325. $followlist[$k]["is_hu"] = 1;
  326. } else {
  327. $followlist[$k]["is_hu"] = 0;
  328. }
  329. }
  330. }
  331. $fansfollow = $followlist;
  332. } elseif($type == 2) {
  333. $ids = [];
  334. if($followlist) {
  335. foreach($followlist as $k => $v) {
  336. $ids[] = $v["user_id"];
  337. }
  338. }
  339. if($fanslist) {
  340. foreach($fanslist as $k => $v) {
  341. $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
  342. if(in_array($v["fans_id"],$ids)) {
  343. $fanslist[$k]["is_hu"] = 1;
  344. $fanslist[$k]["is_follow"] = 1;
  345. } else {
  346. $fanslist[$k]["is_hu"] = 0;
  347. }
  348. }
  349. }
  350. $fansfollow = $fanslist;
  351. }else {
  352. $ids = [];
  353. if($followlist) {
  354. foreach($followlist as $k => $v) {
  355. $ids[] = $v["user_id"];
  356. }
  357. }
  358. if($fanslist) {
  359. foreach($fanslist as $k => $v) {
  360. $fanslist[$k]['createtime_text'] = get_last_time($v['createtime']);
  361. $fanslist[$k]["is_follow"] = 1;
  362. if(in_array($v["fans_id"],$ids)) {
  363. $fanslist[$k]["is_hu"] = 1;
  364. } else {
  365. unset($fanslist[$k]); //不是好友的 直接unset掉
  366. }
  367. }
  368. }
  369. $fansfollow = $fanslist;
  370. }
  371. if($fansfollow) {
  372. $data = [];
  373. foreach($fansfollow as $k => $v) {
  374. if($k >= $pageStart && $k < $pageEnd) {
  375. $data[] = $v;
  376. }
  377. }
  378. $this->success("获取成功!",$data);
  379. } else {
  380. $this->success("数据为空!",[]);
  381. }
  382. }
  383. /**
  384. * 获取最近访客
  385. * (消息)
  386. */
  387. public function getMyVisitList(){
  388. $list = Db::name('user_visitlist')->alias('uv')
  389. ->field('uv.user_id,uv.updatetime,user.id,user.nickname,user.avatar,user.gender,user.desc')
  390. ->join('user','uv.user_id = user.id','LEFT')
  391. ->where('uv.visit_user_id',$this->auth->id) //被访问者
  392. ->order('uv.id desc')->autopage()->select();
  393. $list = list_domain_image($list,['avatar']);
  394. if(!empty($list)){
  395. foreach($list as $key => &$val){
  396. //关注
  397. $val['is_follow'] = $this->is_follow($val['user_id'],$this->auth->id);
  398. }
  399. }
  400. $this->success(1,$list);
  401. }
  402. /**
  403. * 获取附近的人
  404. * (消息-同城)
  405. */
  406. public function getSamecityList(){
  407. if(!$this->auth->city_id){
  408. $this->success(1,[]);
  409. }
  410. $where = [
  411. 'status' => 'normal',
  412. 'city_id'=> $this->auth->city_id,
  413. ];
  414. //排除黑名单的
  415. $black_ids = Db::name('user_blacklist')->where('user_id',$this->auth->id)->column('black_user_id');
  416. if(!empty($black_ids)){
  417. $where['id'] = ['NOTIN',$black_ids];
  418. }
  419. $list = Db::name('user')->where($where)->where('id','neq',$this->auth->id)->field('id,nickname,avatar,gender,desc')->order('id desc')->autopage()->select();
  420. $list = list_domain_image($list,['avatar']);
  421. if(!empty($list)){
  422. foreach($list as $key => &$val){
  423. //关注
  424. $val['is_follow'] = $this->is_follow($val['id'],$this->auth->id);
  425. }
  426. }
  427. $this->success(1,$list);
  428. }
  429. //是否关注
  430. private function is_follow($user_id,$fans_id){
  431. $where = [
  432. 'user_id' => $user_id,
  433. 'fans_id' => $fans_id,
  434. ];
  435. $check = Db::name('user_fans_follow')->where($where)->find();
  436. if($check){
  437. return 1;
  438. }else{
  439. return 0;
  440. }
  441. }
  442. /**
  443. * 获取个人技能列表
  444. */
  445. public function getMySkillList() {
  446. $user_id = $this->request->request('user_id',0); // 用户ID
  447. $page = $this->request->request('page',1); // 分页
  448. $pageNum = $this->request->request('pageNum',10); // 分页
  449. if ($user_id == -1) {
  450. $user_id = $this->auth->id;
  451. } elseif($user_id>0) {
  452. $user_id = intval($user_id);
  453. } else {
  454. $this->error(__('Invalid parameters'));
  455. }
  456. // 分页搜索构建
  457. $pageStart = ($page-1)*$pageNum;
  458. $authModel = new \app\common\model\DispatchAuth();
  459. $where = [];
  460. $where["a.user_id"] = $user_id;
  461. $where["a.status"] = 1;
  462. $authskillList = $authModel->alias("a")
  463. ->field("a.id,ds.image,ds.name,a.voice,a.voice_time,a.price,a.is_main,ds.unit")
  464. ->join("hx_dispatch_skill ds","ds.id = a.skill_id")
  465. ->where($where)
  466. ->limit($pageStart,$pageNum)
  467. ->select();
  468. $this->success("获取成功!",$authskillList);
  469. }
  470. /**
  471. * 删除个人技能信息
  472. */
  473. public function delMySkillInfo() {
  474. $id = $this->request->request('id'); // 认证ID
  475. if (!$id) {
  476. $this->error(__('Invalid parameters'));
  477. }
  478. $authModel = new \app\common\model\DispatchAuth();
  479. $where = [];
  480. $where["id"] = $id;
  481. $where["user_id"] = $this->auth->id;
  482. $authInfo = $authModel->where($where)->find();
  483. if(!$authInfo) $this->error("技能认证未找到");
  484. // if($authInfo->is_main == 1) $this->error("请先取消主技能,再删除!");
  485. Db::startTrans();
  486. try{
  487. $res1 = $authInfo->delete();
  488. $res2 = \app\common\model\UserSkill::where(["user_id"=>$this->auth->id,"skill_id"=>$authInfo->skill_id])->delete();
  489. if($res1 && $res2) {
  490. Db::commit();
  491. $this->success("删除成功!");
  492. } else {
  493. $this->error("网络错误,请稍后重试!");
  494. }
  495. }catch (ValidateException $e) {
  496. Db::rollback();
  497. $this->error($e->getMessage());
  498. } catch (PDOException $e) {
  499. Db::rollback();
  500. $this->error($e->getMessage());
  501. } catch (Exception $e) {
  502. Db::rollback();
  503. $this->error($e->getMessage());
  504. }
  505. }
  506. /**
  507. * 修改个人技能信息
  508. */
  509. public function editMySkillInfo() {
  510. $price = $this->request->request('price'); // 价格
  511. $id = $this->request->request('id'); // 认证ID
  512. $is_main = $this->request->request('is_main'); // 是否设置为主技能
  513. if (!$id && !$price) {
  514. $this->error(__('Invalid parameters'));
  515. }
  516. $authModel = new \app\common\model\DispatchAuth();
  517. $where = [];
  518. $where["id"] = $id;
  519. if(!$authModel->where($where)->find()) $this->error("技能认证未找到");
  520. Db::startTrans();
  521. try{
  522. if($is_main == 1) {
  523. $where = [];
  524. $where["user_id"] = $this->auth->id;
  525. $authModel->update(["is_main"=>0],$where);
  526. }
  527. $where = [];
  528. $where["id"] = $id;
  529. $data = [];
  530. $data["price"] = $price;
  531. $data["is_main"] = $is_main;
  532. $res = $authModel->update($data,$where);
  533. $myAuthList = $authModel->where(["user_id"=>$this->auth->id,"is_main"=>1])->find();
  534. if(!$myAuthList) {
  535. $this->error("必须至少设置一个主技能");
  536. Db::rollback();
  537. }
  538. if($res) {
  539. Db::commit();
  540. $this->success("修改成功!",$data);
  541. } else {
  542. $this->error("网络错误,请稍后重试!");
  543. }
  544. }catch (ValidateException $e) {
  545. Db::rollback();
  546. $this->error($e->getMessage());
  547. } catch (PDOException $e) {
  548. Db::rollback();
  549. $this->error($e->getMessage());
  550. } catch (Exception $e) {
  551. Db::rollback();
  552. $this->error($e->getMessage());
  553. }
  554. }
  555. /**
  556. * 编辑个人信息(完善资料)
  557. */
  558. public function editUserInfo() {
  559. $avatar = $this->request->request('avatar'); // 头像
  560. $nickname = $this->request->request('nickname'); // 昵称
  561. $age = $this->request->request('age'); // 年龄
  562. $ageId = $this->request->request('age_id'); // 年龄段
  563. $gender = $this->request->request('gender'); // 性别 0=女,1=男
  564. $image = $this->request->request('image'); // 个人形象照
  565. $constellationId = $this->request->request('star_id'); //星座ID
  566. $provinceId = $this->request->request('province_id'); //省ID
  567. $cityId = $this->request->request('city_id'); //城市ID
  568. $desc = $this->request->request('desc'); //个性签名
  569. /*if (!$avatar && !$nickname && !$age && !$image && !in_array($gender,[0,1])) {
  570. $this->error(__('请输入要修改的信息'));
  571. }*/
  572. $where = [];
  573. $where["id"] = $this->auth->id;
  574. $data = [];
  575. $avatar && $data["avatar"] = $avatar;
  576. if($nickname){
  577. if (mb_strlen($nickname) > 30) {
  578. $this->error('用户昵称最多支持30个汉字或组合');
  579. }
  580. $data["nickname"] = $nickname;
  581. }
  582. $gender && $data["gender"] = $gender;
  583. $age && $data["age"] = $age;
  584. $image && $data["image"] = $image;
  585. $ageId && $data['age_id'] = $ageId;
  586. $constellationId && $data['constellation_id'] = $constellationId;
  587. $provinceId && $data['province_id'] = $provinceId;
  588. $cityId && $data['city_id'] = $cityId;
  589. $desc && $data['desc'] = $desc;
  590. $res = $this->userModel->update($data,$where);
  591. if($res) {
  592. $user = $this->userModel->where($where)->find();
  593. if (!empty($user['nickname']) && !empty($user['avatar']) && !empty($user['age_id']) && $user['has_info']==0) {
  594. $data['has_info'] = 1;
  595. $this->userModel->update($data,$where);
  596. }
  597. $this->success("修改成功!");
  598. } else {
  599. $this->error("网络错误,请稍后重试!");
  600. }
  601. }
  602. /**
  603. * 编辑个人信息(修改昵称和头像需要后台审核)
  604. */
  605. public function editUser() {
  606. $avatar = $this->request->request('avatar'); // 头像
  607. $nickname = $this->request->request('nickname'); // 昵称
  608. if (!$avatar && !$nickname) {
  609. $this->error(__('请输入要修改的信息'));
  610. }
  611. $data = [];
  612. if ($avatar && $avatar != $this->auth->avatar) {
  613. $data["pre_avatar"] = $avatar;
  614. }
  615. if($nickname && $nickname != $this->auth->nickname){
  616. if (mb_strlen($nickname) > 8) {
  617. $this->error('用户昵称最多支持8个汉字或组合');
  618. }
  619. $data["pre_nickname"] = $nickname;
  620. }
  621. if (!empty($data)) {
  622. $data['need_check'] = 1;
  623. $where["id"] = $this->auth->id;
  624. $res = $this->userModel->update($data,$where);
  625. if(!$res) {
  626. $this->error("网络错误,请稍后重试!");
  627. }
  628. }
  629. $this->success("修改成功!");
  630. }
  631. /**
  632. * 主播申请
  633. */
  634. public function anchorApply() {
  635. $type_id = $this->request->request('type_id',0); // 技能分类ID
  636. $party_type_id = $this->request->request('party_type_id'); //分类ID
  637. $desc = $this->request->request('desc'); // 申请备注
  638. if (!$party_type_id && !$desc) {
  639. $this->error(__('Invalid parameters'));
  640. }
  641. $useranchorModel = new \app\common\model\UserAnchor();
  642. $data = [];
  643. $data["user_id"] = $this->auth->id;
  644. $data["type_id"] = $type_id;
  645. $data["party_type_id"] = $party_type_id;
  646. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  647. $data["desc"] = $desc;
  648. $data["createtime"] = time();
  649. $res = $useranchorModel->insertGetId($data);
  650. if($res) {
  651. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  652. $this->success("申请发送成功!");
  653. } else {
  654. $this->error("网络错误,请稍后重试");
  655. }
  656. }
  657. /**
  658. * 实名认证
  659. */
  660. public function authApply() {
  661. $realname = $this->request->request('realname'); // 真实姓名
  662. $idcard = $this->request->request('idcard'); // 身份证号
  663. $zimage = $this->request->request('zimage'); // 身份证正面照
  664. $fimage = $this->request->request('fimage'); // 身份证反面照
  665. if (!$realname && !$idcard && !$zimage && !$fimage) {
  666. $this->error(__('Invalid parameters'));
  667. }
  668. $userauthModel = new \app\common\model\UserAuth();
  669. $data = [];
  670. $data["user_id"] = $this->auth->id;
  671. //$data["idcard"] = $idcard;
  672. $userAuth = $userauthModel->where($data)->find();
  673. if (!empty($userAuth)) {
  674. if(in_array($userAuth['status'],[0,1])) $this->error('您已经申请过了,请勿重复操作!');
  675. }
  676. // 测试需要 开始
  677. $data["realname"] = $realname;
  678. $zimage && $data["zimage"] = $zimage;
  679. $fimage && $data["fimage"] = $fimage;
  680. $data["status"] = 1;
  681. if (!empty($userAuth)) {
  682. $data["updatetime"] = time();
  683. $authWhere['user_id'] = $this->auth->id;
  684. $res = $userauthModel->where($authWhere)->update($data);
  685. } else {
  686. $data["createtime"] = time();
  687. $res = $userauthModel->insertGetId($data);
  688. }
  689. if($res) {
  690. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  691. $this->success("恭喜,实名认证成功!");
  692. } else {
  693. $this->error("网络错误,请稍后重试");
  694. }
  695. // 测试需要 结束
  696. // 实名认证验证
  697. $configInfo = config("auth");
  698. $outh = new outh($configInfo["api_url"],$configInfo["customer_code"],$configInfo["private_key"],$configInfo["key"]);
  699. $out_trade_no = date("YmdHis").rand(1000,9999);
  700. $ret = $outh->toVerify($out_trade_no,$realname,$idcard);
  701. if(isset($ret["code"])) {
  702. if($ret["code"] == "1008") {
  703. $this->error(__('身份证格式错误'));
  704. }
  705. if($ret["code"] == "1009") {
  706. $this->error(__('身份证格式错误'));
  707. }
  708. if($ret["code"] == "0001") {
  709. $this->error(__('姓名和身份证号不匹配!'));
  710. }
  711. if($ret["code"] == "0000") {
  712. $data["realname"] = $realname;
  713. $zimage && $data["zimage"] = $zimage;
  714. $fimage && $data["fimage"] = $fimage;
  715. $data["status"] = 1;
  716. $data["createtime"] = time();
  717. $res = $userauthModel->insertGetId($data);
  718. if($res) {
  719. \app\common\model\User::update(["is_auth"=>2],["id"=>$this->auth->id]);
  720. $this->success("恭喜,实名认证成功!");
  721. } else {
  722. $this->error("网络错误,请稍后重试");
  723. }
  724. }
  725. } else {
  726. $this->error("网络错误,请稍后重试");
  727. }
  728. }
  729. /**
  730. * 获取主播分类
  731. */
  732. public function getAnchorType() {
  733. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  734. }
  735. /**
  736. * 加入黑名单
  737. */
  738. public function addBlacklist() {
  739. Db::startTrans();
  740. try {
  741. $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
  742. if (!$black_user_id) {
  743. throw new Exception(__('Invalid parameters'));
  744. }
  745. $userblacklistModel = new \app\common\model\UserBlacklist();
  746. $data = [];
  747. $data["user_id"] = $this->auth->id;
  748. $data["black_user_id"] = $black_user_id;
  749. if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
  750. $data["createtime"] = time();
  751. $res = $userblacklistModel->insertGetId($data);
  752. if(!$res) {
  753. throw new Exception("网络错误,请稍后重试");
  754. }
  755. //im加入黑名单
  756. $tenimService = new TenimService();
  757. $params = [
  758. 'user_id' => $this->auth->id,
  759. 'black_user_ids' => [(string)$black_user_id],
  760. ];
  761. $imResult = $tenimService->addBlack($params);
  762. if (!$imResult['status']) {
  763. throw new Exception($imResult['msg']);
  764. }
  765. Db::commit();
  766. $this->success("加入成功!");
  767. } catch (Exception $e) {
  768. Db::rollback();
  769. $this->error($e->getMessage());
  770. }
  771. }
  772. /**
  773. * 获取黑名单用户
  774. */
  775. public function getBlacklist() {
  776. $page = $this->request->request('page',1); // 分页
  777. $pageNum = $this->request->request('pageNum',10); // 分页
  778. // 分页搜索构建
  779. $pageStart = ($page-1)*$pageNum;
  780. $userblacklistModel = new \app\common\model\UserBlacklist();// ->limit($pageStart,$pageNum)
  781. $where = [];
  782. $where["a.user_id"] = $this->auth->id;
  783. $list = $userblacklistModel->alias("a")
  784. ->field("a.id,a.black_user_id,u.avatar,u.nickname,u.level,u.gender")
  785. ->join("hx_user u","u.id = a.black_user_id")
  786. ->where($where)
  787. ->limit($pageStart,$pageNum)
  788. ->select();
  789. if($list) {
  790. $this->success("获取成功!",$list);
  791. } else {
  792. $this->success("数据为空",[]);
  793. }
  794. }
  795. /**
  796. * 移除用户黑名单
  797. */
  798. public function removeUserBlack() {
  799. Db::startTrans();
  800. try {
  801. $id = $this->request->request('id'); // 黑名单ID
  802. $userId = $this->request->request('user_id'); // 用户ID
  803. if (!$id && !$userId) {
  804. throw new Exception(__('Invalid parameters'));
  805. }
  806. $userblacklistModel = new \app\common\model\UserBlacklist();
  807. $where = [];
  808. $id && $where["id"] = $id;
  809. if ($userId) {
  810. $where['user_id'] = $this->auth->id;
  811. $where['black_user_id'] = $userId;
  812. }
  813. $userBlack = $userblacklistModel->where($where)->find();
  814. if (empty($userBlack)) {
  815. throw new Exception('未找到黑名单信息');
  816. }
  817. $blackUserId = isset($userBlack['black_user_id']) ? $userBlack['black_user_id'] : 0;
  818. $res = false;
  819. if (!empty($userBlack)) {
  820. $res = $userblacklistModel->where($where)->delete();
  821. }
  822. if(!$res) {
  823. $this->error("网络错误,请稍后重试!");
  824. }
  825. //im加入黑名单
  826. if (!empty($blackUserId)) {
  827. $tenimService = new TenimService();
  828. $params = [
  829. 'user_id' => $this->auth->id,
  830. 'black_user_ids' => [(string)$blackUserId],
  831. ];
  832. $imResult = $tenimService->delBlack($params);
  833. if (!$imResult['status']) {
  834. throw new Exception($imResult['msg']);
  835. }
  836. }
  837. Db::commit();
  838. $this->success("移除成功!",$res);
  839. } catch (Exception $e) {
  840. Db::rollback();
  841. $this->error($e->getMessage());
  842. }
  843. }
  844. /**
  845. * 举报用户
  846. */
  847. /*public function addReport() {
  848. $ruser_id = $this->request->request('ruser_id'); // 被举报用户ID
  849. $content = $this->request->request('content'); // 举报内容
  850. $image = $this->request->request('image'); // 图片描述(多个用半角逗号隔开)
  851. if (!$ruser_id) {
  852. $this->error(__('Invalid parameters'));
  853. }
  854. $userreportModel = new \app\common\model\UserReport();
  855. $data = [];
  856. $data["user_id"] = $this->auth->id;
  857. $data["reportable_id"] = $ruser_id;
  858. $data['reportable_type'] = $this->getModelName('user');
  859. $data["content"] = $content;
  860. $data["image"] = $image;
  861. $data["createtime"] = time();
  862. $res = $userreportModel->insertGetId($data);
  863. if($res) {
  864. $this->success("举报成功!");
  865. } else {
  866. $this->error("网络错误,请稍后重试");
  867. }
  868. }*/
  869. /**
  870. * 举报
  871. */
  872. /*public function addReportNew() {
  873. $params = $this->request->param();
  874. $validate = new Report();
  875. $result = $validate->check($params);
  876. if (!$result) {
  877. $this->error($validate->getError());
  878. }
  879. $userreportModel = new \app\common\model\UserReport();
  880. $data = [];
  881. $data["user_id"] = $this->auth->id;
  882. $data["reportable_id"] = $params['reportable_id'];
  883. $data['reportable_type'] = $this->getModelName($params['reportable_type']);
  884. $data["content"] = $params['content'];
  885. $data["image"] = $params['image'];
  886. $data["createtime"] = time();
  887. $res = $userreportModel->insertGetId($data);
  888. if($res) {
  889. $this->success("举报成功!");
  890. } else {
  891. $this->error("网络错误,请稍后重试");
  892. }
  893. }*/
  894. /**
  895. * redis 数据恢复---非redis数据丢失请勿使用!!!!
  896. */
  897. public function shujuhuifu() {
  898. $key = $this->request->request("key");// 操作验证 123456
  899. if($key != 123456) {
  900. $this->error(__('Invalid parameters'));
  901. }
  902. $giftuserpartyModel = new \app\common\model\GiftUserParty();
  903. $redis = new Redis();
  904. $redisconfig = config("redis");
  905. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  906. if ($redisconfig['redis_pwd']) {
  907. $redis->auth($redisconfig['redis_pwd']);
  908. }
  909. if($redisconfig['redis_selectdb'] > 0){
  910. $redis->select($redisconfig['redis_selectdb']);
  911. }
  912. // 获取本周第一天
  913. $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
  914. // 获取本月第一天
  915. $monthday = date("Ym01");
  916. $where = [];
  917. $where["createtime"] = ["gt",strtotime($weekday)];
  918. $list1 = $giftuserpartyModel->where($where)->select();
  919. foreach($list1 as $k => $v) {
  920. // 添加redis记录做财富排行榜周榜用
  921. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$weekday,$v["value"],$v["user_to_id"]);
  922. // 添加redis记录做贡献排行榜周榜用
  923. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$weekday,$v["value"],$v["user_id"]);
  924. }
  925. $where = [];
  926. $where["createtime"] = ["gt",strtotime(date("Y-m-01"))];
  927. $list2 = $giftuserpartyModel->where($where)->select();
  928. foreach($list2 as $k => $v) {
  929. // 添加redis记录做财富排行榜月榜用
  930. $redis->zIncrBy("jewel_get_".$v["party_id"].":".$monthday,$v["value"],$v["user_to_id"]);
  931. // 添加redis记录做贡献排行榜月榜用
  932. $redis->zIncrBy("jewel_to_".$v["party_id"].":".$monthday,$v["value"],$v["user_id"]);
  933. }
  934. $this->success("执行成功!");
  935. }
  936. /**
  937. * 获取用户钻石余额
  938. */
  939. public function getUserJewel() {
  940. $data = \app\common\model\User::field("Jewel,money")->where(["id"=>$this->auth->id])->find();
  941. return $this->success("获取成功!",$data);
  942. }
  943. /**
  944. * 获取用户等级说明
  945. */
  946. public function getLevelExplain() {
  947. $data = \app\common\model\UserLevelExplain::field("title,content")->select();
  948. return $this->success("获取成功!",$data);
  949. }
  950. /**
  951. * 获取用户等级信息
  952. */
  953. public function getUserLevelInfo() {
  954. $res = [];$exstart = 0;$exend = 0;
  955. $userModel = new \app\common\model\User();
  956. $userInfo = $userModel->field("id,nickname,avatar,level,empirical")->where(["id"=>$this->auth->id])->find();
  957. if(!$userInfo) {
  958. $this->error("用户信息获取失败!");
  959. }
  960. $res["avatar"] = $userInfo['avatar'];
  961. $res["nickname"] = $userInfo['nickname'];
  962. // 获取用户当前经验值对应等级
  963. $userconfigModel = new \app\common\model\UserLevelConfig();
  964. $where = [];
  965. $where["empirical"] = ["elt",$userInfo["empirical"]];
  966. $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->limit(1)->select();
  967. $where = [];
  968. $where["empirical"] = ["gt",$userInfo["empirical"]];
  969. $userexplainend = $userconfigModel->where($where)->order("empirical","asc")->limit(1)->select();
  970. if(!$userexplainstart && !$userexplainend) {
  971. $this->error("经验等级信息获取失败!");
  972. } elseif(!$userexplainstart && $userexplainend) {
  973. $res["level_start"] = 0;
  974. $res["level_end"] = $userexplainend[0]["level"];
  975. } elseif($userexplainstart && !$userexplainend) {
  976. $res["level_start"] = $userexplainstart[0]["level"];
  977. $res["level_end"] = $userexplainstart[0]["level"];
  978. } elseif($userexplainstart && $userexplainend) {
  979. $res["level_start"] = $userexplainstart[0]["level"];
  980. $res["level_end"] = $userexplainend[0]["level"];
  981. }
  982. $userexplainstart && $exstart = $userexplainstart[0]["empirical"];
  983. $userexplainend && $exend = $userexplainend[0]["empirical"];
  984. $r1 = $exend-$exstart; // 等级经验值差
  985. $r2 = $userInfo["empirical"]-$exstart; // 当前等级与最低等级经验值差
  986. $r3 = $exend-$userInfo["empirical"]; // 还需多少经验值升级
  987. if($r1 == 0) {
  988. $res["level_rate"] = 1;
  989. } elseif($r2 == 0) {
  990. $res["level_rate"] = 0;
  991. if($res["level_start"] == $res["level_end"]) {
  992. $res["level_rate"] = 1;
  993. }
  994. } else {
  995. $res["level_rate"] = intval(($r2/$r1)*100)/100;
  996. }
  997. $res["to_up_need"] = $r3>0?$r3:0;
  998. // // 满级
  999. // if($r3 == 0 && !$userexplainend) {
  1000. // $res["level_rate"] = 1;
  1001. // }
  1002. $this->success("获取成功!",$res);
  1003. }
  1004. /**
  1005. * 邀请
  1006. * @return void
  1007. */
  1008. public function addInvite()
  1009. {
  1010. try {
  1011. $inviteNo = $this->request->param('invite_no','');
  1012. $userId = $this->auth->id;
  1013. if (empty($inviteNo)) {
  1014. throw new Exception('参数错误');
  1015. }
  1016. $where['invite_no'] = $inviteNo;
  1017. $userField = 'id,invite_no,pre_userid';
  1018. $user = model('User')->field($userField)->where($where)->find();
  1019. if (empty($user)) {
  1020. throw new Exception('无效的邀请码');
  1021. }
  1022. //判断邀请码用户不能是自己的下级
  1023. if ($user['pre_userid'] == $userId) {
  1024. throw new Exception('对方已被您邀请过');
  1025. }
  1026. $userInviteWhere['invite_user_id'] = $userId;
  1027. $userInvite = model('UserInvite')->where($userInviteWhere)->find();
  1028. if (!empty($userInvite)) {
  1029. throw new Exception('您已经被邀请过');
  1030. }
  1031. $userInviteData = [
  1032. 'user_id' => $user['id'],
  1033. 'invite_user_id' => $userId,
  1034. 'createtime' => time(),
  1035. ];
  1036. $userInviteRes = model('UserInvite')->insertGetId($userInviteData);
  1037. if (!$userInviteRes) {
  1038. throw new Exception('邀请失败');
  1039. }
  1040. $userUpWhere['id'] = $userId;
  1041. $userUpdate = ['pre_userid'=>$user['id']];
  1042. $userUpdateRes = model('User')->where($userUpWhere)->update($userUpdate);
  1043. if (!$userUpdateRes) {
  1044. throw new Exception('更新邀请人失败');
  1045. }
  1046. $this->success('邀请成功');
  1047. } catch (Exception $e) {
  1048. $this->error($e->getMessage());
  1049. }
  1050. }
  1051. /**
  1052. * 邀请详情
  1053. * @return void
  1054. */
  1055. public function inviteInfo()
  1056. {
  1057. try {
  1058. $userId = $this->auth->id;
  1059. $field = 'id,invite_no';
  1060. $where['id'] = $userId;
  1061. $user = model('User')->field($field)->where($where)->find();
  1062. $inviteNo = isset($user['invite_no']) ? $user['invite_no'] : '';
  1063. $todayNow = day_now();
  1064. $todayStart = $todayNow[0];
  1065. $todayEnd = $todayNow[1]+1;
  1066. $userMoneyLogWhere['user_id'] = $userId;
  1067. $userMoneyLogWhere['type'] = 103;
  1068. $appendWhere['createtime'] = [['egt', $todayStart],['lt', $todayEnd],'and'];
  1069. $todayMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->where($appendWhere)->sum('value');
  1070. $totalMoney = model('UserMoneyLog')->where($userMoneyLogWhere)->sum('value');
  1071. //本周
  1072. $weekNow = week_now();
  1073. $userInviteWhere['user_id'] = $userId;
  1074. $userInviteAppendWhere['createtime'] = [['egt', $weekNow[0]],['lt', $weekNow[1]+1],'and'];
  1075. $userInviteModel = model('UserInvite');
  1076. $weekNowNum = $userInviteModel->where($userInviteWhere)->where($userInviteAppendWhere)->count();
  1077. //上周
  1078. $lastWeek = last_week();
  1079. $appendLastWhere['createtime'] = [['egt', $lastWeek[0]],['lt', $lastWeek[1]+1],'and'];
  1080. $lastWeekNum = $userInviteModel->where($userInviteWhere)->where($appendLastWhere)->count();
  1081. //全部
  1082. $totalNum = $userInviteModel->where($userInviteWhere)->count();
  1083. $inviteMoney = config('site.invite_money');
  1084. $inviteRule = config('site.invite_rule');
  1085. $result = [
  1086. 'invite_money' => (int)$inviteMoney,
  1087. 'invite_no' => $inviteNo,//邀请码
  1088. 'today_money' => $todayMoney,//今日收益
  1089. 'total_money' => $totalMoney,//总收益
  1090. 'week_now_num' => $weekNowNum,//本周邀请数
  1091. 'last_week_num' => $lastWeekNum,//上周邀请数
  1092. 'total_num' => $totalNum,//总邀请数
  1093. 'invite_rule' => $inviteRule,//规则说明
  1094. ];
  1095. $this->success('获取成功',$result);
  1096. } catch (Exception $e) {
  1097. $this->error($e->getMessage());
  1098. }
  1099. }
  1100. /**
  1101. * 邀请列表
  1102. * @return void
  1103. */
  1104. public function inviteList()
  1105. {
  1106. try {
  1107. $userId = $this->auth->id;
  1108. $where['user_id'] = $userId;
  1109. $userInvite = model('UserInvite')->where($where)->with(['user'=>function($uQuery){
  1110. $uQuery->field('id,avatar,u_id,nickname');
  1111. }])->autopage()->order('createtime desc')->select();
  1112. $result = [];
  1113. if (!empty($userInvite)) {
  1114. foreach ($userInvite as $key => $value) {
  1115. $user = isset($value['user']) ? $value['user'] : [];
  1116. $temp = [
  1117. 'user_id' => isset($user['id']) ? $user['id'] : 0,
  1118. 'u_id' => isset($user['u_id']) ? $user['u_id'] : 0,
  1119. 'avatar' => isset($user['avatar']) ? $user['avatar'] : 0,
  1120. 'nickname' => isset($user['nickname']) ? $user['nickname'] : 0,
  1121. 'create_time_text' => !empty($value['createtime']) ? date('Y-m-d', $value['createtime']) : '',
  1122. ];
  1123. $result[] = $temp;
  1124. }
  1125. }
  1126. $this->success('获取成功',$result);
  1127. } catch (Exception $e) {
  1128. $this->error($e->getMessage());
  1129. }
  1130. }
  1131. /**
  1132. * 钻石兑换记录
  1133. * @return void
  1134. */
  1135. public function exchangeList()
  1136. {
  1137. try {
  1138. $field = 'id,sound_coin,createtime';
  1139. $where['user_id'] = $this->auth->id;
  1140. $result = model('UserExchangeLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1141. if (!empty($result)) {
  1142. foreach ($result as $key => &$value) {
  1143. $value['jewel'] = '+'.$value['sound_coin'];
  1144. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  1145. unset($value['sound_coin']);
  1146. }
  1147. }
  1148. $this->success('获取成功',$result);
  1149. } catch (Exception $e) {
  1150. $this->error($e->getMessage());
  1151. }
  1152. }
  1153. /**
  1154. * 钻石充值记录
  1155. * @return void
  1156. */
  1157. public function rechargeList()
  1158. {
  1159. try {
  1160. $field = 'id,detail,mode,value,createtime';
  1161. $where['user_id'] = $this->auth->id;
  1162. $result = model('UserJewelLog')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1163. if (!empty($result)) {
  1164. foreach ($result as $key => &$value) {
  1165. $value['value'] = $value['mode'].$value['value'];
  1166. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i',$value['createtime']) : '';
  1167. }
  1168. }
  1169. $this->success('获取成功',$result);
  1170. } catch (Exception $e) {
  1171. $this->error($e->getMessage());
  1172. }
  1173. }
  1174. /**
  1175. * 提现配置列表
  1176. * @return void
  1177. */
  1178. public function withdrawalConfigList()
  1179. {
  1180. try {
  1181. $field = 'id,money,real_money';
  1182. $result = model('WithdrawalConfig')->field($field)->autopage()->order('weigh asc')->select();
  1183. if (!empty($result)) {
  1184. //设置是否使用自定义
  1185. $withdrawDefine = config('site.withdraw_define');
  1186. if ($withdrawDefine == 1) {
  1187. $fieldArr = [[
  1188. 'id' => -1,
  1189. 'money' => 0,
  1190. 'real_money' => 0.00,
  1191. ],];
  1192. $result = array_merge($result,$fieldArr);
  1193. }
  1194. }
  1195. $this->success('获取成功',$result);
  1196. } catch (Exception $e) {
  1197. $this->error($e->getMessage());
  1198. }
  1199. }
  1200. /**
  1201. * 提现
  1202. * @return void
  1203. */
  1204. public function withdrawal()
  1205. {
  1206. Db::startTrans();
  1207. try {
  1208. $withdrawConfigId = $this->request->param('id',0);
  1209. $money = $this->request->param('money',0.00);
  1210. $type = $this->request->param('type',0);
  1211. $userId = $this->auth->id;
  1212. $isAnchor = $this->auth->is_anchor;
  1213. if (empty($withdrawConfigId) && empty($money)) {
  1214. throw new Exception('参数错误');
  1215. }
  1216. //只有主播可以提现
  1217. if ($isAnchor != 2) {
  1218. throw new Exception('您不是主播不允许提现');
  1219. }
  1220. if ($this->auth->power->withdraw == 1) {
  1221. throw new Exception('您已被禁止提现');
  1222. }
  1223. //验证提现类型
  1224. $withdrawTypeConfig = config('wallet.withdraw_type');
  1225. $typeIds = array_keys($withdrawTypeConfig);
  1226. if (!in_array($type,$typeIds)) {
  1227. throw new Exception('未知的提现类型');
  1228. }
  1229. $typeStr = isset($withdrawTypeConfig[$type]) ? $withdrawTypeConfig[$type] : '';
  1230. $withdrawRateConfig = config('site.withdrawRate');//用户获取的金额比例(需要/100)
  1231. $withdrawRate = bcdiv($withdrawRateConfig,100,2);
  1232. if (!empty($money)) {//自定义金额
  1233. if ($money <= 0) {
  1234. throw new Exception('金额有误');
  1235. }
  1236. $inputMoney = $money;
  1237. $moneys = bcmul($money,$withdrawRate,2);
  1238. $platformMoney = bcsub($money,$moneys,2);
  1239. } else {//提现配置
  1240. $where['id'] = $withdrawConfigId;
  1241. $withdrawalConfig = model('WithdrawalConfig')->where($where)->find();
  1242. if (empty($withdrawalConfig)) {
  1243. throw new Exception('未知的配置信息');
  1244. }
  1245. $inputMoney = $withdrawalConfig['money'];
  1246. $moneys = $withdrawalConfig['money'];
  1247. $platformMoney = bcsub($moneys,$withdrawalConfig['real_money'],2);;
  1248. }
  1249. if ($moneys <= 0) {
  1250. throw new Exception('申请金额异常');
  1251. }
  1252. //扣减余额 记录余额日志
  1253. $walletRes = model('wallet')->lockChangeAccountRemain($userId, $inputMoney, '-', 0, '申请提现', 104,'money');
  1254. if (!$walletRes['status']) {
  1255. throw new Exception($walletRes['msg']);
  1256. }
  1257. $account = $name = '';
  1258. if ($type == 1) {//微信
  1259. $account = '';
  1260. $name = '';
  1261. } elseif ($type == 2) {//支付宝
  1262. $userAlipayWhere['user_id'] = $userId;
  1263. $userAlipay = model('UserAlipay')->where($userAlipayWhere)->find();
  1264. if (empty($userAlipay)) {
  1265. throw new Exception('请绑定支付宝');
  1266. }
  1267. $account = $userAlipay['pay_no'];
  1268. $name = $userAlipay['realname'];
  1269. } elseif ($type == 3) {//银行
  1270. $userBankWhere['user_id'] = $userId;
  1271. $userBank = model('UserBank')->where($userBankWhere)->find();
  1272. if (empty($userBank)) {
  1273. throw new Exception('请绑定银行卡');
  1274. }
  1275. $account = $userBank['bank_no'];
  1276. $name = $userBank['realname'];
  1277. }
  1278. $data = [
  1279. 'user_id' => $userId,//用户ID
  1280. 'money' => $inputMoney,//金额
  1281. 'handingfee' => $platformMoney,//手续费
  1282. 'real_money' => bcsub($inputMoney,$platformMoney,2),//金额
  1283. 'taxes' => 0.00,//税费
  1284. 'type' => $typeStr,//类型
  1285. 'account' => $account,//提现账户
  1286. 'name' => $name,//真实姓名
  1287. //'memo' => '',//备注
  1288. //'orderid' => '',//订单号
  1289. //'transactionid' => '',//流水号
  1290. 'status' => 'created',//状态:created=申请中,successed=成功,rejected=已拒绝
  1291. //'transfertime' => '',//转账时间
  1292. 'createtime' => time(),//添加时间
  1293. ];
  1294. $withdrawRes = model('Withdraw')->insertGetId($data);
  1295. if (!$withdrawRes) {
  1296. throw new Exception('提现失败');
  1297. }
  1298. Db::commit();
  1299. $this->success('操作成功待审核');
  1300. } catch (Exception $e) {
  1301. Db::rollback();
  1302. $this->error($e->getMessage());
  1303. }
  1304. }
  1305. /**
  1306. * 提现列表
  1307. * @return void
  1308. */
  1309. public function withdrawalList()
  1310. {
  1311. try {
  1312. $field = 'id,money,type,status,createtime,transfertime';
  1313. $where=[];
  1314. $where['user_id'] = $this->auth->id;
  1315. //$where['status'] = 'successed';//状态:created=申请中,successed=成功,rejected=已拒绝
  1316. $result = model('Withdraw')->field($field)->where($where)->autopage()->order('createtime desc')->select();
  1317. if (!empty($result)) {
  1318. foreach ($result as $key => &$value) {
  1319. $value['money'] = '-'.$value['money'];
  1320. $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i', $value['createtime']) : '';
  1321. $value['transfertime'] = !empty($value['transfertime']) ? date('Y-m-d H:i', $value['transfertime']) : '';
  1322. }
  1323. }
  1324. $this->success('获取成功',$result);
  1325. } catch (Exception $e) {
  1326. $this->error($e->getMessage());
  1327. }
  1328. }
  1329. }