IndexController.php 4.1 KB

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