RecommendRelation.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\wap\model\recommend;
  12. use app\admin\model\special\SpecialSource;
  13. use app\wap\model\activity\EventRegistration;
  14. use app\wap\model\live\LiveStudio;
  15. use app\wap\model\special\Lecturer;
  16. use app\wap\model\special\Special;
  17. use basic\ModelBasic;
  18. use service\GroupDataService;
  19. use traits\ModelTrait;
  20. use app\admin\model\store\StoreProduct;
  21. class RecommendRelation extends ModelBasic
  22. {
  23. use ModelTrait;
  24. /**
  25. * 获取主页推荐列表下的专题和图文内容
  26. * @param int $recommend_id 推荐id
  27. * @param int $type 类型 0=专题,1=图文
  28. * @param int $imagetype 图片显示类型
  29. * @param int $limit 显示多少条
  30. * @return array
  31. * */
  32. public static function getRelationList($recommend_id, $type, $imagetype, $limit = 0)
  33. {
  34. $limit = $limit ? $limit : 4;
  35. if ($type == 0){
  36. $list = self::where('a.recommend_id', $recommend_id)
  37. ->alias('a')->order('a.sort desc')->limit($limit)
  38. ->join("__SPECIAL__ p", 'p.id=a.link_id')
  39. ->join('__SPECIAL_SUBJECT__ j', 'j.id=p.subject_id', 'LEFT')
  40. ->where(['p.is_show' => 1, 'p.is_del' => 0])
  41. ->field(['p.id','p.pink_money', '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','j.name as subject_name', 'a.link_id','p.browse_count','p.member_pay_type', 'p.member_money'])
  42. ->select();
  43. }elseif ($type == 4){
  44. $list = self::where('a.recommend_id', $recommend_id)
  45. ->alias('a')->order('a.sort desc')->limit($limit)
  46. ->join("StoreProduct p", 'p.id=a.link_id')
  47. ->where(['p.is_show' => 1, 'p.is_del' => 0])
  48. ->field(['p.id','p.price', 'p.store_name', 'p.image','p.sales','p.ficti', 'p.store_info', 'p.keyword', 'p.vip_price', 'p.member_pay_type', 'a.link_id'])
  49. ->select();
  50. }elseif($type == 5){
  51. //热门直播
  52. $list = LiveStudio::getLiveList(10);
  53. }elseif($type == 6){
  54. //讲师
  55. $list = Lecturer::getLecturer(1,6);
  56. }elseif($type == 7){
  57. //线下活动
  58. $list = EventRegistration::eventRegistrationList(1,1);
  59. }else {
  60. $list = self::alias('a')->join('__ARTICLE__ e', 'e.id=a.link_id')
  61. ->where(['a.recommend_id' => $recommend_id, 'e.is_show' => 1])
  62. ->field(['e.title', 'e.image_input as image', 'e.synopsis as abstract', 'e.label', 'a.link_id', 'e.visit as browse_count'])
  63. ->limit($limit)->order('a.sort desc')->select();
  64. }
  65. $list = (count($list) && !in_array($type,[5,6,7])) ? $list->toArray() : $list;
  66. foreach ($list as &$item) {
  67. if($type!=4){
  68. if (!isset($item['subject_name'])) $item['subject_name'] = '';
  69. if (!isset($item['money'])) $item['money'] = 0;
  70. if($type==0){
  71. $specialSourceId = SpecialSource::getSpecialSource($item['id']);
  72. if($specialSourceId) $item['count']=count($specialSourceId);
  73. else $item['count']=0;
  74. }else $item['count'] =0;
  75. $item['image'] = isset($item['image']) ? get_oss_process($item['image'],$imagetype) : "";
  76. $item['label'] = (isset($item['label']) && $item['label'] && !is_array($item['label'])) ? json_decode($item['label']) : [];
  77. $special_type_name = "";
  78. if (isset($item['special_type']) && SPECIAL_TYPE[$item['special_type']]) {
  79. $special_type_name = explode("专题",SPECIAL_TYPE[$item['special_type']]) ? explode("专题",SPECIAL_TYPE[$item['special_type']])[0] : "";
  80. }
  81. $item['special_type_name'] = $special_type_name;
  82. }else{
  83. $item['subject_name'] = $item['store_name'];
  84. $item['title'] = $item['store_name'];
  85. $item['money'] =$item['price'];
  86. $item['image'] = get_oss_process($item['image'],$imagetype);
  87. $item['label'] = explode(',',$item['keyword']);
  88. $item['special_type_name'] ='商品';
  89. $item['count']=bcadd($item['sales'],$item['ficti'],0);
  90. }
  91. }
  92. return $list;
  93. }
  94. /**
  95. * 获取主页推荐下图文或者专题的总条数
  96. * @param int $recommend_id 推荐id
  97. * @param int $type 类型
  98. * @return int
  99. * */
  100. public static function getRelationCount($recommend_id, $type)
  101. {
  102. if ($type == 0){
  103. $count = self::where('a.recommend_id', $recommend_id)->alias('a')
  104. ->join("__SPECIAL__ p", 'p.id=a.link_id')
  105. ->join('__SPECIAL_SUBJECT__ j', 'j.id=p.subject_id', 'LEFT')
  106. ->where(['p.is_show' => 1,'p.is_del' => 0])->count();
  107. }else if($type == 4){
  108. $count = self::where('a.recommend_id', $recommend_id)->alias('a')
  109. ->join("StoreProduct p", 'p.id=a.link_id')
  110. ->where(['p.is_del' => 0,'p.is_show' => 1,])->count();
  111. }else if($type == 5){
  112. $count = Special::where(['type' =>4, 'is_show' => 1, 'is_del' => 0])->count();
  113. }else if($type == 6){
  114. $count = Lecturer::where(['is_del'=>0,'is_show'=>1])->count();
  115. }else if($type == 7){
  116. $count = count(EventRegistration::eventRegistrationList(1,1));
  117. }else{
  118. $count = self::alias('a')->join('__ARTICLE__ e', 'e.id=a.link_id')->where(['a.recommend_id' => $recommend_id, 'e.is_show' => 1])->count();
  119. }
  120. return $count;
  121. }
  122. }