SpecialTask.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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\special;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. /**
  15. * Class SpecialTask 专题任务
  16. * @package app\admin\model\special
  17. */
  18. class SpecialTask extends ModelBasic
  19. {
  20. use ModelTrait;
  21. public static function getAddTimeAttr($value)
  22. {
  23. return $value ? date("Y-m-d H:i:s", $value) : '';
  24. }
  25. public static function getCouresNameAttr($value, $data)
  26. {
  27. return SpecialCourse::where('id', $data['coures_id'])->value('course_name');
  28. }
  29. //设置where条件
  30. public static function setWhere($where, $alirs = '', $model = null)
  31. {
  32. $model = $model === null ? new self() : $model;
  33. $model = $alirs === '' ? $model->alias($alirs) : $model;
  34. $alirs = $alirs === '' ? $alirs : $alirs . '.';
  35. if ($where['is_show'] !== '') $model = $model->where("{$alirs}is_show", $where['is_show']);
  36. if ($where['pid']>0) {
  37. $pids=SpecialTaskCategory::categoryId($where['pid']);
  38. array_push($pids,$where['pid']);
  39. if(count($pids)>0){
  40. $model = $model->where("{$alirs}pid",'in', $pids);
  41. }else{
  42. $model = $model->where("{$alirs}pid", $where['pid']);
  43. }
  44. }
  45. if ($where['title']) $model = $model->where("{$alirs}title", 'LIKE', "%$where[title]%");
  46. if (isset($where['special_type']) && $where['special_type']) $model = $model->where("{$alirs}type", $where['special_type']);
  47. $model = $model->where("{$alirs}is_del", 0);
  48. if ($where['order'])
  49. $model = $model->order($alirs . self::setOrder($where['order']));
  50. else
  51. $model = $model->order("{$alirs}sort desc,{$alirs}id desc");
  52. return $model;
  53. }
  54. public static function getTaskCount($special_id)
  55. {
  56. $ids = self::getDb('special_course')->where('special_id', $special_id)->where('is_show', 1)->column('id');
  57. return self::where('is_show', 1)->where('is_del',0)->where('coures_id', 'in', $ids)->count();
  58. }
  59. //查找任务列表-对getTaskList2
  60. public static function getTaskList($where)
  61. {
  62. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  63. $data = count($data) ? $data->toArray() : [];
  64. foreach ($data as &$item) {
  65. $item['course_name'] = Special::where('id', $item['special_id'])->value('title');
  66. }
  67. $count = self::setWhere($where)->count();
  68. return compact('data', 'count');
  69. }
  70. public static function getTaskList2($where)
  71. {
  72. if (isset($where['special_type']) && $where['special_type'] == SPECIAL_COLUMN){
  73. unset($where['special_type']);
  74. $where['store_name']=$where['title'];
  75. if($where['type']==''){
  76. $data = Special::setWhere($where)->whereIn('type',[SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO])->page((int)$where['page'], (int)$where['limit'])->select();
  77. $data = count($data) ? $data->toArray() : [];
  78. $count = Special::setWhere($where)->whereIn('type',[SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO])->count();
  79. }else{
  80. $data = Special::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  81. $data = count($data) ? $data->toArray() : [];
  82. $count = Special::setWhere($where)->count();
  83. }
  84. }elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_LIVE){
  85. unset($where['special_type']);
  86. $where['store_name']=$where['title'];
  87. if($where['type']==''){
  88. $data = Special::setWhere($where)->whereIn('type',[SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO])->page((int)$where['page'], (int)$where['limit'])->select();
  89. $data = count($data) ? $data->toArray() : [];
  90. $count = Special::setWhere($where)->whereIn('type',[SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO])->count();
  91. }else{
  92. $data = Special::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  93. $data = count($data) ? $data->toArray() : [];
  94. $count = Special::setWhere($where)->count();
  95. }
  96. }else{
  97. if($where['pid']>0){$where['special_type']=0;}
  98. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  99. $data = count($data) ? $data->toArray() : [];
  100. $count = self::setWhere($where)->count();
  101. }
  102. return compact('data', 'count');
  103. }
  104. /**
  105. * 删除任务
  106. * @param $id
  107. * @return bool|int
  108. * @throws \think\exception\DbException
  109. */
  110. public static function delTask($id)
  111. {
  112. $task = self::get($id);
  113. if (!$task) return self::setErrorInfo('删除的数据不存在');
  114. return $task->delete();
  115. }
  116. /**
  117. * 设置直播关联查询条件
  118. * @param $where
  119. * @return $this
  120. */
  121. public static function setLiveWhereTask($where)
  122. {
  123. $model = self::where('live_id', $where['live_id']);
  124. if ($where['title']) $model = $model->where('title', 'like', "%$where[title]%");
  125. if ($where['start_time'] && $where['end_time']) $model = $model->where('add_time', 'between', [strtotime($where['start_time']), strtotime($where['end_time'])]);
  126. return $model;
  127. }
  128. /**
  129. * 获取直播关联的任务
  130. * @param $where
  131. * @return array
  132. * @throws \think\Exception
  133. * @throws \think\db\exception\DataNotFoundException
  134. * @throws \think\db\exception\ModelNotFoundException
  135. * @throws \think\exception\DbException
  136. */
  137. public static function getRelationTask($where)
  138. {
  139. $data = self::setLiveWhereTask($where)->page((int)$where['page'], (int)$where['limit'])->order('sort desc')->select();
  140. $data = count($data) ? $data->toArray() : [];
  141. foreach ($data as &$item) {
  142. $special = SpecialCourse::where('a.id', $item['coures_id'])->alias('a')->join('special s', 's.id=a.special_id')->field('s.id,s.title')->find();
  143. if ($special)
  144. $item['special_title'] = $special['title'] . '&nbsp/&nbsp' . $special['id'];
  145. else
  146. $item['special_title'] = '';
  147. }
  148. $count = self::setLiveWhereTask($where)->count();
  149. return compact('data', 'count');
  150. }
  151. }