RecommendRelation.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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\activity\EventRegistration;
  13. use app\wap\model\live\LiveStudio;
  14. use app\wap\model\special\Lecturer;
  15. use app\wap\model\special\Special;
  16. use app\wap\model\article\Article;
  17. use app\wap\model\special\SpecialTask;
  18. use app\wap\model\topic\TestPaper;
  19. use basic\ModelBasic;
  20. use service\GroupDataService;
  21. use traits\ModelTrait;
  22. use app\wap\model\store\StoreProduct;
  23. /**推荐内容 model
  24. * Class RecommendRelation
  25. * @package app\wap\model\recommend
  26. */
  27. class RecommendRelation extends ModelBasic
  28. {
  29. use ModelTrait;
  30. /**
  31. * 获取主页推荐列表下的专题和图文内容
  32. * @param int $recommend_id 推荐id
  33. * @param int $type 类型 0=专题,1=图文
  34. * @param int $imagetype 图片显示类型
  35. * @param int $limit 显示多少条
  36. * @return array
  37. * */
  38. public static function getRelationList($recommend_id, $type, $imagetype, $limit, $is_member)
  39. {
  40. $limit = $limit ? $limit : 4;
  41. if ($type == 0 || $type == 8) {
  42. $model = self::where('a.recommend_id', $recommend_id)
  43. ->alias('a')->order('a.sort desc,a.add_time desc')
  44. ->join("__SPECIAL__ p", 'p.id=a.link_id')
  45. ->join('__SPECIAL_SUBJECT__ j', 'j.id=p.subject_id', 'LEFT')
  46. ->where(['p.is_show' => 1, 'p.status' => 1, 'p.is_del' => 0]);
  47. if (!$is_member) $model = $model->where(['p.is_mer_visible' => 0]);
  48. $list = $model->limit($limit)->field(['p.id', 'p.pink_money', 'p.status', 'p.is_light', 'p.light_type', 'p.is_mer_visible', 'p.is_pink', 'p.sort', 'p.title', 'p.image', 'p.abstract', 'p.label', 'p.image', 'p.money', 'p.pay_type', 'p.type as special_type', 'a.link_id', 'a.add_time', 'p.browse_count', 'p.fake_sales', 'p.member_pay_type', 'p.member_money'])
  49. ->select();
  50. } elseif ($type == 4) {
  51. $list = self::where('a.recommend_id', $recommend_id)
  52. ->alias('a')->order('a.sort desc,a.add_time desc')->limit($limit)
  53. ->join("StoreProduct p", 'p.id=a.link_id')
  54. ->where(['p.is_show' => 1, 'p.status' => 1, 'p.is_del' => 0])
  55. ->field(['p.id', 'p.price', 'p.store_name', 'p.status', 'p.image', 'p.sales', 'p.ficti', 'p.store_info', 'p.keyword', 'p.vip_price', 'p.member_pay_type', 'a.link_id', 'a.add_time'])
  56. ->select();
  57. } elseif ($type == 5) {
  58. //热门直播
  59. $list = LiveStudio::getLiveList(10, $is_member);
  60. } elseif ($type == 6) {
  61. //讲师
  62. $list = self::where('a.recommend_id', $recommend_id)
  63. ->alias('a')->order('a.sort desc,a.add_time desc')->limit($limit)
  64. ->join("Lecturer l", 'l.id=a.link_id')
  65. ->where(['l.is_show' => 1, 'l.is_del' => 0])
  66. ->field(['l.id', 'l.lecturer_name', 'l.lecturer_head', 'l.label', 'l.is_show', 'l.is_del', 'a.link_id', 'a.add_time'])
  67. ->select();
  68. } elseif ($type == 7) {
  69. //线下活动
  70. $list = EventRegistration::eventRegistrationList(1, 2);
  71. } elseif ($type == 1) {
  72. $list = self::alias('a')->join('__ARTICLE__ e', 'e.id=a.link_id')
  73. ->where(['a.recommend_id' => $recommend_id, 'e.is_show' => 1])
  74. ->field(['e.title', 'e.image_input as image', 'e.synopsis as abstract', 'e.label', 'a.link_id', 'e.visit as browse_count', 'a.add_time'])
  75. ->limit($limit)->order('a.sort desc,a.add_time desc')->select();
  76. } elseif ($type == 10) {
  77. $list = self::alias('a')->join('SpecialTask t', 't.id=a.link_id')
  78. ->where(['a.recommend_id' => $recommend_id, 't.is_show' => 1, 't.is_del' => 0])
  79. ->field(['t.title', 't.image', 't.abstract', 't.type as task_type', 'a.link_id', 't.play_count as browse_count', 'a.add_time'])
  80. ->limit($limit)->order('a.sort desc,a.add_time desc')->select();
  81. } elseif ($type == 11 || $type == 12) {
  82. if ($type == 11) $types = 1;
  83. else $types = 2;
  84. $list = self::where('a.recommend_id', $recommend_id)
  85. ->alias('a')->order('a.sort desc,a.add_time desc')->limit($limit)
  86. ->join("TestPaper t", 't.id=a.link_id')
  87. ->where(['t.is_show' => 1, 't.status' => 1, 't.is_del' => 0, 't.type' => $types])
  88. ->field(['t.id', 't.title', 't.type', 't.status', 't.image', 't.item_number', 't.answer', 't.money', 't.pay_type', 't.is_show', 't.fake_sales', 't.mer_id', 'a.link_id', 'a.add_time'])
  89. ->select();
  90. } elseif ($type == 13) {
  91. //首页广告
  92. $list = GroupDataService::getData('homepage_ads') ?: [];
  93. } elseif ($type == 14) {
  94. $list = self::where('a.recommend_id', $recommend_id)
  95. ->alias('a')->order('a.sort desc,a.add_time desc')->limit($limit)
  96. ->join("DataDownload d", 'd.id=a.link_id')
  97. ->where(['d.is_show' => 1, 'd.status' => 1, 'd.is_del' => 0])
  98. ->field(['d.id', 'd.title', 'd.image', 'd.status', 'd.sales', 'd.ficti', 'd.money', 'd.pay_type', 'd.is_show', 'd.member_pay_type', 'd.member_money', 'd.is_del', 'a.link_id', 'a.add_time'])
  99. ->select();
  100. }
  101. $list = (count($list) && !in_array($type, [5, 6, 7, 13])) ? $list->toArray() : $list;
  102. foreach ($list as &$item) {
  103. if ($type == 0 || $type == 8) {
  104. if (!isset($item['money'])) $item['money'] = 0;
  105. if ($type == 0 || $type == 8) {
  106. $item['count'] = Special::numberChapters($item['special_type'], $item['id']);
  107. } else $item['count'] = 0;
  108. $item['image'] = isset($item['image']) ? get_oss_process($item['image'], $imagetype) : "";
  109. $item['label'] = (isset($item['label']) && $item['label'] && !is_array($item['label'])) ? json_decode($item['label']) : [];
  110. $special_type_name = "";
  111. if (isset($item['special_type']) && SPECIAL_TYPE[$item['special_type']] && $item['special_type'] != 6) {
  112. $special_type_name = explode("专题", SPECIAL_TYPE[$item['special_type']]) ? explode("专题", SPECIAL_TYPE[$item['special_type']])[0] : "";
  113. } else {
  114. if ($item['is_light']) {
  115. $special_type_name = lightTypeNmae($item['light_type']);
  116. }
  117. }
  118. $item['special_type_name'] = $special_type_name;
  119. $count = Special::learning_records($item['id']);
  120. $item['browse_count'] = processingData(bcadd($item['fake_sales'], $count, 0));
  121. } else if ($type == 4) {
  122. $item['title'] = $item['store_name'];
  123. $item['money'] = $item['price'];
  124. $item['image'] = get_oss_process($item['image'], $imagetype);
  125. $item['label'] = explode(',', $item['keyword']);
  126. $item['special_type_name'] = '商品';
  127. $item['count'] = bcadd($item['sales'], $item['ficti'], 0);
  128. } else if ($type == 10) {
  129. if (!isset($item['money'])) $item['money'] = 0;
  130. $item['label'] = [];
  131. if ($item['task_type'] == 1) {
  132. $item['special_type_name'] = '图文';
  133. } elseif ($item['task_type'] == 2) {
  134. $item['special_type_name'] = '音频';
  135. } elseif ($item['task_type'] == 3) {
  136. $item['special_type_name'] = '视频';
  137. }
  138. $item['count'] = 0;
  139. } else if ($type == 11 || $type == 12) {
  140. $item['image'] = get_oss_process($item['image'], $imagetype);
  141. if ($type == 11) $item['special_type_name'] = '练习';
  142. else $item['special_type_name'] = '考试';
  143. $item['count'] = bcadd($item['answer'], $item['fake_sales'], 0);
  144. } else if ($type == 1) {
  145. $item['label'] = json_decode($item['label'], true);
  146. } else if ($type == 14) {
  147. $item['image'] = get_oss_process($item['image'], $imagetype);
  148. $item['special_type_name'] = '资料';
  149. $item['count'] = bcadd($item['sales'], $item['ficti'], 0);
  150. }
  151. }
  152. return $list;
  153. }
  154. /**
  155. * 获取主页推荐下图文或者专题的总条数
  156. * @param int $recommend_id 推荐id
  157. * @param int $type 类型
  158. * @return int
  159. * */
  160. public static function getRelationCount($recommend_id, $type)
  161. {
  162. if ($type == 0) {
  163. $count = self::where('a.recommend_id', $recommend_id)->alias('a')->join("__SPECIAL__ p", 'p.id=a.link_id')
  164. ->join('__SPECIAL_SUBJECT__ j', 'j.id=p.subject_id', 'LEFT')->where(['p.is_show' => 1, 'p.status' => 1, 'p.is_del' => 0])->count();
  165. } else if ($type == 1) {
  166. $count = self::alias('a')->join('__ARTICLE__ e', 'e.id=a.link_id')->where(['a.recommend_id' => $recommend_id, 'e.is_show' => 1])->count();
  167. } else if ($type == 4) {
  168. $count = self::where('a.recommend_id', $recommend_id)->alias('a')->join("StoreProduct p", 'p.id=a.link_id')
  169. ->where(['p.is_del' => 0, 'p.status' => 1, 'p.is_show' => 1,])->count();
  170. } else if ($type == 5) {
  171. $count = Special::PreWhere()->where(['type' => 4])->count();
  172. } else if ($type == 6) {
  173. $count = self::where('a.recommend_id', $recommend_id)->alias('a')->join("Lecturer l", 'l.id=a.link_id')
  174. ->where(['l.is_show' => 1, 'l.is_del' => 0])->count();
  175. } else if ($type == 7) {
  176. $count = EventRegistration::homeCount() > 0 ? 2 : 0;
  177. } else if ($type == 8) {
  178. $count = self::where('a.recommend_id', $recommend_id)->alias('a')->join("__SPECIAL__ p", 'p.id=a.link_id')
  179. ->join('__SPECIAL_SUBJECT__ j', 'j.id=p.subject_id', 'LEFT')->where(['p.is_show' => 1, 'p.status' => 1, 'p.is_pink' => 1, 'p.is_del' => 0])->count();
  180. } else if ($type == 10) {
  181. $count = self::where('a.recommend_id', $recommend_id)->alias('a')->join("__SPECIAL_TASK__ t", 't.id=a.link_id')
  182. ->where(['t.is_show' => 1, 't.is_del' => 0])->count();
  183. } else if ($type == 11) {
  184. $count = self::where('a.recommend_id', $recommend_id)->alias('a')->join("TestPaper t", 't.id=a.link_id')
  185. ->where(['t.is_show' => 1, 't.status' => 1, 't.is_del' => 0, 't.type' => 1])->count();
  186. } else if ($type == 12) {
  187. $count = self::where('a.recommend_id', $recommend_id)->alias('a')->join("TestPaper t", 't.id=a.link_id')
  188. ->where(['t.is_show' => 1, 't.status' => 1, 't.is_del' => 0, 't.type' => 2])->count();
  189. } else if ($type == 13) {
  190. $ads = GroupDataService::getData('homepage_ads');
  191. $count = count($ads);
  192. } else if ($type == 14) {
  193. $count = self::where('a.recommend_id', $recommend_id)->alias('a')->join("DataDownload d", 'd.id=a.link_id')
  194. ->where(['d.is_show' => 1, 'd.status' => 1, 'd.is_del' => 0])->count();
  195. } else {
  196. $count = 0;
  197. }
  198. return $count;
  199. }
  200. }