IndexController.php 3.7 KB

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