UserwallController.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 老猫 <thinkcmf@126.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\love\controller;
  12. use app\common\Constant;
  13. use app\common\Fun;
  14. use app\love\model\GiftModel;
  15. use app\love\model\UserFavoriteModel;
  16. use app\love\model\UserFriendModel;
  17. use app\love\model\UserGiftModel;
  18. use app\love\model\UserInviteModel;
  19. use app\love\model\UserMatingModel;
  20. use app\love\model\UserModel;
  21. use app\love\model\UserSelectModel;
  22. use app\love\model\UserVisitModel;
  23. class UserwallController extends LoveBaseController
  24. {
  25. private $_age = [[0, 100], [18, 25], [25, 30], [30, 40], [40, 50], [50, 100]];
  26. private $_high = [[0, 250], [150, 160], [161, 170], [171, 180], [180, 250]];
  27. private $_weight = [[0, 150], [40, 50], [51, 60], [61, 70], [71, 80], [81, 150]];
  28. /**
  29. * 缘份列表
  30. */
  31. public function index()
  32. {
  33. $list = UserModel::where('user_type', 2)
  34. ->where('check_status', 2)
  35. ->where('is_complete', 1)
  36. ->where('is_public', 1)
  37. ->where('id', '<>', cmf_get_current_user_id())
  38. ->where('sex', '<>', cmf_get_current_user()['sex'])
  39. ->limit(4)
  40. ->select();
  41. foreach ($list as $v) {
  42. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  43. }
  44. $this->assign('list', $list);
  45. //未读消息数
  46. $unread_num = UserFriendModel::where('user_id', cmf_get_current_user_id())->sum('unread_num');
  47. $invite_num = UserInviteModel::where('to_id', cmf_get_current_user_id())
  48. ->where('status', 1)
  49. ->count();
  50. $this->assign('unread_num', $unread_num + $invite_num);
  51. return $this->fetch("");
  52. }
  53. /**
  54. * 列表
  55. */
  56. public function getList()
  57. {
  58. $param = $this->request->post();
  59. $where = [
  60. ['user_type', '=', 2],
  61. ['id', '<>', cmf_get_current_user_id()],
  62. ['check_status', '=', 2],
  63. ['is_complete', '=', 1],
  64. ['is_public', '=', 1],
  65. ['sex', '<>', cmf_get_current_user()['sex']],
  66. ];
  67. if (!empty($param['age'])) {
  68. $age = $this->_age[$param['age']];
  69. $start_time = strtotime("-{$age[1]} year");
  70. $end_time = strtotime("-{$age[0]} year");
  71. $where[] = ['birthday', 'between', [$start_time, $end_time]];
  72. }
  73. // if (!empty($param['sex'])) {
  74. // $where[] = ['sex', '=', $param['sex']];
  75. // }
  76. if (!empty($param['id'])) {
  77. $where[] = ['id|realname', 'like', "%{$param['id']}%"];
  78. }
  79. if (!empty($param['high'])) {
  80. $high = $this->_high[$param['high']];
  81. $where[] = ['high', 'between', [$high[0], $high[1]]];
  82. }
  83. if (!empty($param['weight'])) {
  84. $weight = $this->_weight[$param['weight']];
  85. $where[] = ['weight', 'between', [$weight[0], $weight[1]]];
  86. }
  87. if (!empty($param['education'])) {
  88. $where[] = ['education', '=', $param['education']];
  89. }
  90. $list = UserModel::where($where)
  91. ->page($param['page'])
  92. ->limit(4)
  93. ->order($param['sort'])
  94. ->select();
  95. foreach ($list as $v) {
  96. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  97. }
  98. $this->result($list, 1);
  99. }
  100. /**
  101. * 详情
  102. */
  103. public function detail()
  104. {
  105. //获取会员信息
  106. $id = $this->request->param('id');
  107. $user_id = cmf_get_current_user_id();
  108. $this->assign('user_id', $user_id);
  109. if (empty($id)) {
  110. $this->error('该会员不存在!');
  111. }
  112. $user = UserModel::get(['id' => $id, 'user_type' => 2]);
  113. if (empty($user)) {
  114. $this->error('该会员不存在!');
  115. }
  116. //信息处理
  117. $user->star++;
  118. $user->save();
  119. $user['age'] = Fun::getAgeByBirth($user['birthday']);
  120. $user['have_house'] = Constant::COND_TINYINT[$user['have_house']];
  121. $user['have_car'] = Constant::COND_TINYINT[$user['have_car']];
  122. $user['with_parent_live'] = Constant::COND_TINYINT[$user['with_parent_live']];
  123. $user['sex_text'] = $user['sex_text'];
  124. if (empty($user['more'])) {
  125. $user['more'] = [];
  126. }
  127. $this->assign('user', $user);
  128. //择偶要求
  129. $mating = UserMatingModel::get(['user_id' => $id]);
  130. $mating['have_house'] = Constant::COND_TINYINT[$mating['have_house']];
  131. $mating['have_car'] = Constant::COND_TINYINT[$mating['have_car']];
  132. $mating['with_parent_live'] = Constant::COND_TINYINT[$mating['with_parent_live']];
  133. $this->assign('mating', $mating);
  134. //礼物列表
  135. $gift = GiftModel::all();
  136. $this->assign('gift', $gift);
  137. //收到的礼物
  138. $user_gift = UserGiftModel::with('gift')->where('to_id', $id)->limit(4)->order('create_time desc')->select();
  139. $this->assign('user_gift', $user_gift);
  140. //收藏
  141. $where = [
  142. ['user_id', '=', $user_id],
  143. ['uid', '=', $id],
  144. ];
  145. $favorite_check = UserFavoriteModel::where($where)->find();
  146. $this->assign('is_favorite', $favorite_check ? 'true' : 'false');
  147. //选择
  148. $select_check = UserSelectModel::where($where)->find();
  149. $this->assign('is_select', $select_check ? 'true' : 'false');
  150. //增加访客记录
  151. //足迹
  152. $current_user = UserModel::get($user_id);
  153. if ($user_id != $id && $current_user['show_footmark'] == 1) {
  154. $visit = UserVisitModel::get(['from_id' => $user_id, 'to_id' => $id]);
  155. $time = time();
  156. if (empty($visit)) {
  157. UserVisitModel::create([
  158. 'from_id' => $user_id,
  159. 'to_id' => $id,
  160. 'num' => 1,
  161. 'create_time' => $time,
  162. 'last_visit_time' => $time,
  163. ]);
  164. } else {
  165. $visit->num++;
  166. $visit->last_visit_time = $time;
  167. $visit->save();
  168. }
  169. }
  170. //是否好友
  171. $is_friend = UserFriendModel::get([
  172. 'user_id' => $id,
  173. 'friend_id' => $user_id,
  174. ]);
  175. $this->assign('is_friend', $is_friend ? 'true' : 'false');
  176. $this->assign('share_image_url', $user['main_image_thumb']);
  177. $this->assign('share_link', $this->request->url(true));
  178. $this->assign('share_desc', $user['username'] . (empty($user['signature']) ? '' : (':' . $user['signature'])));
  179. return $this->fetch();
  180. }
  181. /**
  182. * 赠送礼物
  183. */
  184. public function giveGift()
  185. {
  186. $this->checkStatus();
  187. $post = $this->request->param();
  188. $from_id = cmf_get_current_user_id();
  189. if ($from_id == $post['to_id']) {
  190. $this->error('不可以给自己送礼');
  191. }
  192. UserGiftModel::create([
  193. 'from_id' => $from_id,
  194. 'to_id' => $post['to_id'],
  195. 'gift_id' => $post['gift_id'],
  196. 'create_time' => time(),
  197. ]);
  198. $this->success('赠送成功');
  199. }
  200. /**
  201. * 收到的礼物
  202. */
  203. public function userGift()
  204. {
  205. $id = $this->request->param('id');
  206. $user_gift = UserGiftModel::with('gift')->where('to_id', $id)->limit(4)->order('create_time desc')->select();
  207. $this->result($user_gift, 1);
  208. }
  209. /**
  210. * 收藏
  211. */
  212. public function favorite()
  213. {
  214. $this->checkStatus();
  215. $id = $this->request->param('id');
  216. $user_id = cmf_get_current_user_id();
  217. if ($id == $user_id) {
  218. $this->error('不可以收藏自己');
  219. }
  220. $where = [
  221. ['user_id', '=', $user_id],
  222. ['uid', '=', $id],
  223. ];
  224. $check = UserFavoriteModel::where($where)->find();
  225. if ($check) {
  226. UserFavoriteModel::where($where)->delete();
  227. } else {
  228. UserFavoriteModel::create([
  229. 'user_id' => $user_id,
  230. 'uid' => $id,
  231. 'create_time' => time(),
  232. ]);
  233. }
  234. $this->success('操作成功');
  235. }
  236. /**
  237. * 选择
  238. */
  239. public function select()
  240. {
  241. $this->checkStatus();
  242. $id = $this->request->param('id');
  243. $user_id = cmf_get_current_user_id();
  244. if ($id == $user_id) {
  245. $this->error('不可以选择自己');
  246. }
  247. //已互选
  248. $is_select = UserSelectModel::where('user_id|uid', '=', $user_id)->where('is_confirm', 1)->find();
  249. if ($is_select) {
  250. $this->error('您已有互选对象!');
  251. }
  252. //判断性别
  253. $from_user = UserModel::get($user_id);
  254. $to_user = UserModel::get($id);
  255. if ($from_user['sex'] == $to_user['sex']) {
  256. $this->error('请选择异性!');
  257. }
  258. //此人已恋爱,请重新选择
  259. $is_love = UserSelectModel::where('user_id|uid', '=', $id)->where('is_confirm', 1)->find();
  260. if ($is_love) {
  261. $this->error('此人正在交往中,请重新选择!');
  262. }
  263. //选择
  264. $where = [
  265. ['user_id', '=', $user_id],
  266. ['uid', '=', $id],
  267. ];
  268. $check = UserSelectModel::where($where)->find();
  269. if ($check) {
  270. UserSelectModel::where($where)->delete();
  271. } else {
  272. UserSelectModel::create([
  273. 'user_id' => $user_id,
  274. 'uid' => $id,
  275. 'create_time' => time(),
  276. ]);
  277. }
  278. $this->success('操作成功');
  279. }
  280. /**
  281. * 申请聊天(旧)
  282. */
  283. /*public function chat()
  284. {
  285. $this->checkStatus();
  286. $id = $this->request->param('id');
  287. $user_id = cmf_get_current_user_id();
  288. $time = time();
  289. //聊天申请
  290. $invite_get = UserInviteModel::where([
  291. ['from_id', '=', $id],
  292. ['to_id', '=', $user_id],
  293. ])->find();
  294. $invite_apply = UserInviteModel::where([
  295. ['from_id', '=', $user_id],
  296. ['to_id', '=', $id],
  297. ])->find();
  298. //都没有邀请
  299. if (empty($invite_get) && empty($invite_apply)) {
  300. UserInviteModel::create([
  301. 'from_id' => $user_id,
  302. 'to_id' => $id,
  303. 'create_time' => $time,
  304. ]);
  305. UserModel::where('id', $id)->setInc('invite_num');
  306. $this->error('请等待对方通过聊天邀请');
  307. }
  308. //已收到过邀请
  309. if (!empty($invite_get)) {
  310. if ($invite_get['status'] == 1) {
  311. UserFriendModel::create([
  312. 'user_id' => $id,
  313. 'friend_id' => $user_id,
  314. 'last_msg_time' => time(),
  315. ]);
  316. UserFriendModel::create([
  317. 'user_id' => $user_id,
  318. 'friend_id' => $id,
  319. 'last_msg_time' => time(),
  320. ]);
  321. $invite_get->status = 2;
  322. $invite_get->save();
  323. $this->success('', url('message/detail') . '?id=' . $id);
  324. } elseif ($invite_get['status'] == 2) {
  325. $this->success('', url('message/detail') . '?id=' . $id);
  326. } else {
  327. $this->error('您已拒绝过对方的聊天邀请');
  328. }
  329. }
  330. //已发起过邀请
  331. if (!empty($invite_apply)) {
  332. if ($invite_apply['status'] == 1) {
  333. $this->error('请等待对方同意申请');
  334. } elseif ($invite_apply['status'] == 2) {
  335. $this->success('', url('message/detail') . '?id=' . $id);
  336. } else {
  337. $this->error('对方拒绝跟您聊天');
  338. }
  339. }
  340. }*/
  341. /**
  342. * 申请聊天
  343. */
  344. /*public function chat()
  345. {
  346. $this->checkStatus();
  347. $id = $this->request->param('id');
  348. $user_id = cmf_get_current_user_id();
  349. $time = time();
  350. //聊天申请
  351. $invite_get = UserInviteModel::where([
  352. ['from_id', '=', $id],
  353. ['to_id', '=', $user_id],
  354. ])->find();
  355. $invite_apply = UserInviteModel::where([
  356. ['from_id', '=', $user_id],
  357. ['to_id', '=', $id],
  358. ])->find();
  359. //都没有邀请
  360. if (empty($invite_get) && empty($invite_apply)) {
  361. UserInviteModel::create([
  362. 'from_id' => $user_id,
  363. 'to_id' => $id,
  364. 'create_time' => $time,
  365. ]);
  366. UserModel::where('id', $id)->setInc('invite_num');
  367. $this->error('请等待对方通过聊天邀请');
  368. }
  369. //已收到过邀请
  370. if (!empty($invite_get)) {
  371. if ($invite_get['status'] == 1) {
  372. UserFriendModel::create([
  373. 'user_id' => $id,
  374. 'friend_id' => $user_id,
  375. 'last_msg_time' => time(),
  376. ]);
  377. UserFriendModel::create([
  378. 'user_id' => $user_id,
  379. 'friend_id' => $id,
  380. 'last_msg_time' => time(),
  381. ]);
  382. $invite_get->status = 2;
  383. $invite_get->save();
  384. $this->success('', url('message/detail') . '?id=' . $id);
  385. } elseif ($invite_get['status'] == 2) {
  386. $this->success('', url('message/detail') . '?id=' . $id);
  387. } else {
  388. $this->error('您已拒绝过对方的聊天邀请');
  389. }
  390. }
  391. //已发起过邀请
  392. if (!empty($invite_apply)) {
  393. if ($invite_apply['status'] == 1) {
  394. $this->error('请等待对方同意申请');
  395. } elseif ($invite_apply['status'] == 2) {
  396. $this->success('', url('message/detail') . '?id=' . $id);
  397. } else {
  398. $this->error('对方拒绝跟您聊天');
  399. }
  400. }
  401. }*/
  402. /**
  403. * 聊天
  404. */
  405. public function chat()
  406. {
  407. $this->checkStatus();
  408. $id = $this->request->param('id');
  409. $user_id = cmf_get_current_user_id();
  410. $time = time();
  411. $select = UserSelectModel::where('user_id|uid', '=', $user_id)
  412. ->where('is_confirm', 1)
  413. ->find();
  414. if (!empty($select)) {
  415. $this->error('您已有心上人,请一心一意对待哦(*^_^*)');
  416. }
  417. $has_freind = UserFriendModel::where([
  418. 'user_id' => $user_id,
  419. 'friend_id' => $id,
  420. ])->find();
  421. //无好友先添加成好友
  422. if (empty($has_freind)) {
  423. UserFriendModel::create([
  424. 'user_id' => $id,
  425. 'friend_id' => $user_id,
  426. 'last_msg_time' => $time,
  427. ]);
  428. UserFriendModel::create([
  429. 'user_id' => $user_id,
  430. 'friend_id' => $id,
  431. 'last_msg_time' => $time,
  432. ]);
  433. }
  434. $this->success('', url('message/detail') . '?id=' . $id);
  435. }
  436. }