Recommend.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model\system;
  12. use app\admin\model\special\Grade;
  13. use app\admin\model\special\SpecialSubject;
  14. use traits\ModelTrait;
  15. use basic\ModelBasic;
  16. use app\admin\model\ump\EventRegistration;
  17. use app\admin\model\special\Lecturer;
  18. use app\admin\model\special\Special;
  19. /**
  20. * Class SystemAdmin
  21. * @package app\admin\model\system
  22. */
  23. class Recommend extends ModelBasic
  24. {
  25. use ModelTrait;
  26. protected $insert = ['add_time'];
  27. public static function setAddTimeAttr($value)
  28. {
  29. return time();
  30. }
  31. public static function getTypeseTingAttr($value, $data)
  32. {
  33. $name = '';
  34. switch ($data['typesetting']) {
  35. case 1:
  36. $name = '大图';
  37. break;
  38. case 2:
  39. $name = '宫图';
  40. break;
  41. case 3:
  42. $name = '小图';
  43. break;
  44. case 4:
  45. $name = '左右切换';
  46. break;
  47. default:
  48. $name = '其他';
  49. break;
  50. }
  51. return $name;
  52. }
  53. public static function getTypeNameAttr($value, $data)
  54. {
  55. $name = '';
  56. switch ($data['type']) {
  57. case 1:
  58. $name = '图文';
  59. break;
  60. case 0:
  61. $name = '专题';
  62. break;
  63. case 2:
  64. $name = '直播';
  65. break;
  66. case 3:
  67. $name = '自定义';
  68. break;
  69. case 4:
  70. $name = '商品';
  71. break;
  72. case 5:
  73. $name = '直播[内置]';
  74. break;
  75. case 6:
  76. $name = '讲师[内置]';
  77. break;
  78. case 7:
  79. $name = '活动[内置]';
  80. break;
  81. }
  82. return $name;
  83. }
  84. public static function getAddTimeAttr($value)
  85. {
  86. return date('Y-m-d H:i:s', $value);
  87. }
  88. public static function getIconKeyAttr($value, $data)
  89. {
  90. if (!$data['icon']) return '';
  91. $value = parse_url($data['icon']);
  92. $value = isset($value['path']) ? substr($value['path'], 1) : '';
  93. return $value;
  94. }
  95. public static function getImageKeyAttr($value, $data)
  96. {
  97. if (!$data['image']) return '';
  98. $value = parse_url($data['image']);
  99. $value = isset($value['path']) ? substr($value['path'], 1) : '';
  100. return $value;
  101. }
  102. public static function fixedList()
  103. {
  104. $list = self::where('is_fixed', 1)->order('sort desc,add_time desc')->select();
  105. foreach ($list as &$item) {
  106. $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->count();
  107. }
  108. return $list;
  109. }
  110. public static function getRecommendList($where)
  111. {
  112. $model = self::where('is_fixed', $where['is_fixed']);
  113. if ($where['order']) {
  114. $model->order(self::setOrder($where['order']));
  115. } else $model->order('sort desc,add_time desc');
  116. $data = $model->page((int)$where['page'], (int)$where['limit'])->select();
  117. foreach ($data as $item) {
  118. $item['type_name'] = self::getTypeNameAttr('', $item);
  119. $item['type_ting'] = self::getTypeseTingAttr('', $item);
  120. switch ($item['type']){
  121. case 0:
  122. case 4:
  123. $item['number'] = RecommendRelation::where(['recommend_id' => $item['id']])->count();
  124. break;
  125. case 5:
  126. $item['number'] = Special::where(['type' =>4, 'is_show' => 1, 'is_del' => 0])->count();
  127. break;
  128. case 6:
  129. $count=Lecturer::where(['is_del'=>0,'is_show'=>1])->count();
  130. $item['number'] = $count >=6 ? 6 : $count;
  131. break;
  132. case 7:
  133. $item['number'] = 1;
  134. break;
  135. }
  136. $item['grade_title'] =$item['grade_id']>0 ? Grade::where(['id' => $item['grade_id'],'is_del'=>0])->value('name') : '无';
  137. }
  138. $count = self::where('is_fixed', $where['is_fixed'])->count();
  139. return compact('data', 'count');
  140. }
  141. }