SpecialCourse.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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\special;
  12. use app\wap\model\user\User;
  13. use basic\ModelBasic;
  14. use traits\ModelTrait;
  15. class SpecialCourse extends ModelBasic
  16. {
  17. use ModelTrait;
  18. public static function getCouresCount($special_id)
  19. {
  20. $tasjIds = self::where(['is_show' => 1, 'special_id' => $special_id])->column('id');
  21. $ids = [];
  22. foreach ($tasjIds as $id) {
  23. if (SpecialTask::getTashCount($id)) $ids[] = $id;
  24. }
  25. return $ids;
  26. }
  27. public static function getSpecialCouresList($special_id, $limit = 10, $page = 1)
  28. {
  29. $list = SpecialTask::where('special_id', $special_id)->order('sort desc,add_time desc')->page($page, $limit)->select();
  30. $page++;
  31. return compact('page', 'list');
  32. }
  33. public static function getSpecialSourceList($special_id, $limit = 10, $page = 1,$uid=0)
  34. {
  35. $special = Special::where('id',$special_id)->where(['is_del'=>0,'is_show'=>1])->find();
  36. if (!$special) return compact('page', 'list');
  37. //获得专栏下面的专题
  38. $cloumnSource = SpecialSource::getSpecialSource($special_id, false, $limit, $page);
  39. $list = array();
  40. if (!$cloumnSource) return compact('page', 'list');
  41. foreach ($cloumnSource as $k => $v) {
  42. if ($special['type'] == SPECIAL_COLUMN) {
  43. $cloumnTask = Special::where('id',$v['source_id'])->where(['is_del'=>0,'is_show'=>1])->find();
  44. $cloumnTask = $cloumnTask ? $cloumnTask->toArray() : [];
  45. //获得专题下面的素材
  46. $specialTask = array();
  47. $specialSource = SpecialSource::getSpecialSource($v['source_id']);
  48. if(count($specialSource) > 0){
  49. foreach ($specialSource as $sk => $sv) {
  50. $task = SpecialTask::where(['is_show'=>1,'is_del'=>0])->where('id',$sv['source_id'])->field('id,special_id,title,detail,type,is_pay,image,abstract,sort,play_count,is_show,add_time,live_id')->order('sort DESC')->find();
  51. if ($task ? $task = $task->toArray() : false){
  52. $task['special_id'] = $sv['special_id'];
  53. $task['is_free'] = $sv['pay_status'];
  54. $task['pay_status'] = $sv['pay_status'];
  55. $taskSpecialIsPay = self::specialIsPay($special_id,$uid);
  56. if (!$taskSpecialIsPay){//如果整个专题免费,那么里面素材都免非,否则就默认素材本身的状态
  57. $task['pay_status'] = $taskSpecialIsPay;
  58. }
  59. $specialTask[] = $task;
  60. }
  61. }
  62. }
  63. if ($cloumnTask) {
  64. $cloumnTask['special_task'] = $specialTask;
  65. $cloumnTask['pay_status'] = $v['pay_status'];//付费,先默认素材本身的付费状态
  66. $cloumnTask['is_free'] = $v['pay_status'];
  67. $specialIsPay = self::specialIsPay($v['source_id'],$uid);
  68. if (!$specialIsPay){//如果整个专题免费,那么里面素材都免非,否则就默认素材本身的状态
  69. $cloumnTask['pay_status'] = $specialIsPay;
  70. }
  71. $cloumnTask['cloumn_special_id'] = $special_id;
  72. if ($cloumnTask['is_show'] == 1) {
  73. $list[] = $cloumnTask;
  74. }
  75. }
  76. } else {
  77. $task = SpecialTask::getSpecialTaskOne($v['source_id']);
  78. if ($task ? $task = $task->toArray() : false) {
  79. $task['pay_status'] = $v['pay_status'];//付费
  80. $task['is_free'] = $v['pay_status'];
  81. $specialIsPay = self::specialIsPay($special_id,$uid);
  82. if (!$specialIsPay){//如果整个专题免费,那么里面素材都免非,否则就默认素材本身的状态
  83. $task['pay_status'] = $specialIsPay;
  84. }
  85. $task['special_id'] = $special_id;
  86. if ($task['is_show'] == 1 && $special['is_show'] == 1) {
  87. $list[] = $task;
  88. }
  89. }
  90. }
  91. }
  92. $page++;
  93. return compact('page', 'list');
  94. }
  95. /**
  96. * @param $special_id
  97. * @param bool $source_id
  98. * @param int $limit
  99. * @param int $page
  100. * @param int $uid
  101. * @return array
  102. * @throws \think\db\exception\DataNotFoundException
  103. * @throws \think\db\exception\ModelNotFoundException
  104. * @throws \think\exception\DbException
  105. */
  106. public static function get_cloumn_task($special_id, $source_id = false, $limit = 10, $page = 1,$uid=0)
  107. {
  108. $special = Special::where('id',$special_id)->where(['is_del'=>0,'is_show'=>1])->find();
  109. if (!$special) return [];
  110. $cloumn_source = SpecialSource::getSpecialSource($special_id, $source_id);
  111. if (!$cloumn_source) return [];
  112. $cloumn_source = array_column($cloumn_source->toArray(), 'source_id');
  113. $special_source = SpecialSource::getSpecialSource($cloumn_source, $source_id, $limit, $page);
  114. $list = array();
  115. if (!$special_source) return compact('page', 'list');
  116. foreach ($special_source as $k => $v) {
  117. $task = SpecialTask::getSpecialTaskOne($v['source_id']);
  118. if(!$task) continue;
  119. $task_special = Special::where('id',$v['special_id'])->where(['is_del'=>0,'is_show'=>1])->find();
  120. $specialIsPay = self::specialIsPay($v['special_id'],$uid);
  121. $task['is_free'] = $v['pay_status'];
  122. $task['pay_status'] = $specialIsPay;
  123. $task['special_id'] = $v['special_id'];
  124. if ($task['is_show'] == 1 && $task_special['is_show'] == 1) {
  125. $list[] = $task;
  126. }
  127. }
  128. $page++;
  129. return compact('page', 'list');
  130. }
  131. /**专题是否需要付费
  132. * @param $special_id
  133. * @return int
  134. * @throws \think\exception\DbException
  135. */
  136. public static function specialIsPay($special_id,$uid)
  137. {
  138. if (!$special_id) return false;
  139. $special = Special::get($special_id);
  140. if (!$special) return false;
  141. $specialIsPay = 1;//收费
  142. if(!$uid) return $specialIsPay;
  143. $uid = User::getActiveUid();
  144. $isMember = User::getUserInfo($uid);
  145. $isPay = SpecialBuy::PaySpecial($special['id'], $uid);
  146. if ($special['pay_type'] == 0) {//专栏里面整个专题免费
  147. $specialIsPay = 0;//免费
  148. }
  149. if ($isPay === false && $special['pay_type'] == 0 && $special['is_pink'] == 0) {//没有购买,
  150. $specialIsPay = 0;//免费
  151. }
  152. if ($isMember['level'] > 0 && $special['member_pay_type'] == 0) {//会员,
  153. $specialIsPay = 0;//免费
  154. }
  155. if ($isPay) {//购买过,
  156. $specialIsPay = 0;//免费
  157. }
  158. return $specialIsPay;
  159. }
  160. }