Recommend.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\wap\model\recommend;
  12. use app\wap\model\user\User;
  13. use basic\ModelBasic;
  14. use traits\ModelTrait;
  15. /**移动端推荐、导航
  16. * Class Recommend
  17. * @package app\wap\model\recommend
  18. */
  19. class Recommend extends ModelBasic
  20. {
  21. use ModelTrait;
  22. /**首页导航
  23. * @return false|\PDOStatement|string|\think\Collection
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. */
  28. public static function getRecommend()
  29. {
  30. return self::where(['is_fixed' => 1, 'is_show' => 1])->order('sort desc,add_time desc')
  31. ->field(['title', 'icon', 'type', 'link', 'grade_id', 'id'])->select();
  32. }
  33. /**个人中心菜单
  34. * @return false|\PDOStatement|string|\think\Collection
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. * @throws \think\exception\DbException
  38. */
  39. public static function getPersonalCenterMenuList($is_statu, $is_write_off, $business)
  40. {
  41. $model = self::where(['is_fixed' => 2, 'is_show' => 1]);
  42. if (!$is_statu) {
  43. $model = $model->where('is_promoter', 0);
  44. }
  45. if (!$is_write_off) {
  46. $model = $model->where('is_write_off', 0);
  47. }
  48. if (!$business) {
  49. $model = $model->where('is_lecturer', 'in', [0, 1]);
  50. } else {
  51. $model = $model->where('is_lecturer', 'in', [0, 2]);
  52. }
  53. return $model->order('sort desc,add_time desc')->field(['title', 'icon', 'type', 'link', 'is_promoter', 'id'])->select();
  54. }
  55. /**
  56. * @param $uid
  57. * @return array
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. * @throws \think\exception\DbException
  61. */
  62. public static function getRecommendIdAll()
  63. {
  64. $model = self::where(['is_fixed' => 0, 'is_show' => 1]);
  65. $all = $model->field('id,type')->select();
  66. $all = count($all) > 0 ? $all->toArray() : [];
  67. $idsAll = [];
  68. foreach ($all as $item) {
  69. if (RecommendRelation::getRelationCount($item['id'], (int)$item['type'])) {
  70. array_push($idsAll, $item['id']);
  71. }
  72. }
  73. return $idsAll;
  74. }
  75. /**
  76. * 获取主页推荐列表
  77. * $page 分页
  78. * $limit
  79. * */
  80. public static function getContentRecommend($uid, $is_member)
  81. {
  82. $idsAll = self::getRecommendIdAll();
  83. $model = self::where(['is_fixed' => 0, 'is_show' => 1])->where('id', 'in', $idsAll)
  84. ->field(['id', 'typesetting', 'title', 'type', 'icon', 'image', 'grade_id', 'show_count'])
  85. ->order('sort desc,add_time desc');
  86. $recommend = $model->select();
  87. $recommend = count($recommend) ? $recommend->toArray() : [];
  88. foreach ($recommend as &$item) {
  89. $item['sum_count'] = RecommendRelation::getRelationCount($item['id'], (int)$item['type']);
  90. $item['list'] = RecommendRelation::getRelationList($item['id'], (int)$item['type'], $item['typesetting'], $item['show_count'], $is_member);
  91. if ($item['typesetting'] == 4 && count($item['list']) > 0) {
  92. list($ceilCount, $data) = self::getTypesettingList($item['list']);
  93. $item['data'] = $data;
  94. $item['ceilCount'] = $ceilCount;
  95. } else {
  96. $item['data'] = [];
  97. $item['ceilCount'] = 0;
  98. }
  99. $item['courseIndex'] = 1;
  100. }
  101. return compact('recommend');
  102. }
  103. /**
  104. * 获取数组
  105. * @param array $list
  106. * @return array
  107. */
  108. public static function getTypesettingList(array $list)
  109. {
  110. $ceilCount = ceil(count($list) / 3);
  111. $data = [];
  112. for ($i = 0; $i < $ceilCount; $i++) {
  113. $data[] = ['value' => array_slice($list, $i * 3, 3)];
  114. }
  115. return [$ceilCount, $data];
  116. }
  117. }