IndexController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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\ActiveApplyModel;
  17. use app\love\model\UserFriendModel;
  18. use app\love\model\UserInviteModel;
  19. use app\love\model\UserMatingModel;
  20. use app\love\model\UserOutlookModel;
  21. use app\love\model\UserSelectLogModel;
  22. use app\portal\model\UserModel;
  23. class IndexController extends LoveBaseController
  24. {
  25. public function index()
  26. {
  27. $user_id = cmf_get_current_user_id();
  28. //判断三观
  29. $outlook = UserOutlookModel::where('user_id',$user_id)->find();
  30. if (empty($outlook)) {
  31. return redirect('/love/my/outlook');
  32. }
  33. // $active = ActiveApplyModel::where('user_id',$user_id)->where('active_id',2)->find();
  34. // if ($active) {
  35. // $outlook = UserOutlookModel::where('user_id',$user_id)->find();
  36. // if (empty($outlook)) {
  37. // return redirect('/love/my/outlook');
  38. // }
  39. // }
  40. $user = UserModel::get($user_id);
  41. $matting = UserMatingModel::where('user_id', $user_id)->find();
  42. $where = [
  43. ['user_type', '=', 2],
  44. ['check_status', '=', 2],
  45. ['is_complete', '=', 1],
  46. ['is_public', '=', 1],
  47. ['id', '<>', $user_id],
  48. ['sex', '=', $user['sex'] == 1 ? 2 : 1],
  49. ];
  50. //年龄
  51. $age_start = 0;
  52. $age_end = time();
  53. if (!empty($matting['max_age'])) {
  54. $age_start = strtotime("-{$matting['max_age']} year");
  55. }
  56. if (!empty($matting['min_age'])) {
  57. $age_end = strtotime("-{$matting['min_age']} year");
  58. }
  59. $where[] = ['birthday', 'between', [$age_start, $age_end]];
  60. //身高
  61. $max_high = 200;
  62. if (!empty($matting['max_high'])) {
  63. $max_high = $matting['max_high'];
  64. }
  65. $where[] = ['high', 'between', [$matting['min_high'], $max_high]];
  66. //体重
  67. $max_weight = 200;
  68. if (!empty($matting['max_weight'])) {
  69. $max_weight = $matting['max_weight'];
  70. }
  71. $where[] = ['weight', 'between', [$matting['min_weight'], $max_weight]];
  72. //会员
  73. $list = UserModel::where($where)
  74. ->order('star desc')
  75. ->limit(6)
  76. ->select();
  77. foreach ($list as $v) {
  78. $v['age'] = Fun::getAgeByBirth($v['birthday']);
  79. }
  80. $this->assign('list', json_encode($list));
  81. //幻灯片
  82. $images = SlideItemModel::where('slide_id', 1)->select();
  83. foreach ($images as $image) {
  84. $image['image'] = cmf_get_image_url($image['image']);
  85. }
  86. $this->assign('images', json_encode($images));
  87. //未读消息数
  88. $unread_num = UserFriendModel::where('user_id', cmf_get_current_user_id())->sum('unread_num');
  89. $invite_num = UserInviteModel::where('to_id', cmf_get_current_user_id())
  90. ->where('status', 1)
  91. ->count();
  92. $this->assign('unread_num', $unread_num + $invite_num);
  93. //配对播报
  94. /*$select = UserSelectLogModel::with(['user1','user2'])->order('id desc')->limit(3)->select();
  95. if (!empty($select)) {
  96. foreach ($select as $v) {
  97. $v['name1'] = Fun::getEncodeName($v['user1']['realname']);
  98. $v['name2'] = Fun::getEncodeName($v['user2']['realname']);
  99. }
  100. }
  101. $this->assign('select',json_encode($select));
  102. $select_count = UserSelectLogModel::useGlobalScope(false)->count();
  103. $this->assign('select_count', $select_count + 4);*/
  104. return $this->fetch(':index');
  105. }
  106. public function demo()
  107. {
  108. return $this->fetch(':demo');
  109. }
  110. }