SpecialCourse.php 7.8 KB

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