IndexController.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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\portal\controller;
  12. use app\admin\model\SlideItemModel;
  13. use app\common\Excel;
  14. use app\common\Fun;
  15. use app\love\controller\LoveBaseController;
  16. use app\love\model\UserFriendModel;
  17. use app\love\model\UserInviteModel;
  18. use app\love\model\UserMatingModel;
  19. use app\portal\model\UserModel;
  20. class IndexController extends LoveBaseController
  21. {
  22. public function index()
  23. {
  24. $user_id = cmf_get_current_user_id();
  25. $user = UserModel::get($user_id);
  26. $matting = UserMatingModel::where('user_id', $user_id)->find();
  27. $where = [
  28. ['user_type', '=', 2],
  29. ['check_status', '=', 2],
  30. ['is_complete', '=', 1],
  31. ['is_public', '=', 1],
  32. ['id', '<>', $user_id],
  33. ['sex', '=', $user['sex'] == 1 ? 2 : 1],
  34. ];
  35. //年龄
  36. $age_start = 0;
  37. $age_end = time();
  38. if (!empty($matting['max_age'])) {
  39. $age_start = strtotime("-{$matting['max_age']} year");
  40. }
  41. if (!empty($matting['min_age'])) {
  42. $age_end = strtotime("-{$matting['min_age']} year");
  43. }
  44. $where[] = ['birthday', 'between', [$age_start, $age_end]];
  45. //身高
  46. $max_high = 200;
  47. if (!empty($matting['max_high'])) {
  48. $max_high = $matting['max_high'];
  49. }
  50. $where[] = ['high', 'between', [$matting['min_high'], $max_high]];
  51. //体重
  52. $max_weight = 200;
  53. if (!empty($matting['max_weight'])) {
  54. $max_weight = $matting['max_weight'];
  55. }
  56. $where[] = ['weight', 'between', [$matting['min_weight'], $max_weight]];
  57. //会员
  58. $list = UserModel::where($where)
  59. ->order('star desc')
  60. ->limit(6)
  61. ->select();
  62. foreach ($list as $v) {
  63. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  64. }
  65. $this->assign('list', json_encode($list));
  66. //幻灯片
  67. $images = SlideItemModel::where('slide_id', 1)->select();
  68. foreach ($images as $image) {
  69. $image['image'] = cmf_get_image_url($image['image']);
  70. }
  71. $this->assign('images', json_encode($images));
  72. //未读消息数
  73. $unread_num = UserFriendModel::where('user_id', cmf_get_current_user_id())->sum('unread_num');
  74. $invite_num = UserInviteModel::where('to_id', cmf_get_current_user_id())
  75. ->where('status', 1)
  76. ->count();
  77. $this->assign('unread_num', $unread_num + $invite_num);
  78. return $this->fetch(':index');
  79. }
  80. public function demo()
  81. {
  82. return $this->fetch(':demo');
  83. }
  84. }