SpecialTask.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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\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 (isset($where['is_show']) && $where['is_show'] !== '') $model = $model->where("{$alirs}is_show", $where['is_show']);
  36. if (isset($where['pid']) && $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 (isset($where['title']) && $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)->where("{$alirs}mer_id", 0);
  48. if (isset($where['special_id']) && $where['special_id']) $model = $model->where("{$alirs}special_id", 'in', [0, $where['special_id']]);
  49. if ($where['order'])
  50. $model = $model->order($alirs . self::setOrder($where['order']));
  51. else
  52. $model = $model->order("{$alirs}sort desc,{$alirs}id desc");
  53. return $model;
  54. }
  55. public static function getTaskCount($special_id)
  56. {
  57. $ids = self::getDb('special_source')->where('special_id', $special_id)->column('source_id');
  58. return self::where('is_show', 1)->where('is_del', 0)->where('id', 'in', $ids)->count();
  59. }
  60. //查找素材列表
  61. public static function getTaskList($where)
  62. {
  63. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  64. $data = count($data) ? $data->toArray() : [];
  65. $count = self::setWhere($where)->count();
  66. return compact('data', 'count');
  67. }
  68. public static function getTaskList2($where, $special_source)
  69. {
  70. if (isset($where['special_type']) && $where['special_type'] == SPECIAL_COLUMN) {
  71. unset($where['special_type']);
  72. $where['store_name'] = $where['title'];
  73. if ($where['type'] == '') {
  74. $data = Special::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_OTHER])->page((int)$where['page'], (int)$where['limit'])->select();
  75. $data = count($data) ? $data->toArray() : [];
  76. $count = Special::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_OTHER])->count();
  77. } else {
  78. $data = Special::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  79. $data = count($data) ? $data->toArray() : [];
  80. $count = Special::setWhere($where)->where('id', 'not in', $special_source)->count();
  81. }
  82. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_LIVE) {
  83. unset($where['special_type']);
  84. $where['store_name'] = $where['title'];
  85. if ($where['type'] == '') {
  86. $data = Special::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_COLUMN, SPECIAL_OTHER])->page((int)$where['page'], (int)$where['limit'])->select();
  87. $data = count($data) ? $data->toArray() : [];
  88. $count = Special::setWhere($where)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_COLUMN, SPECIAL_OTHER])->count();
  89. } else {
  90. $data = Special::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  91. $data = count($data) ? $data->toArray() : [];
  92. $count = Special::setWhere($where)->where('id', 'not in', $special_source)->count();
  93. }
  94. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_SEVEN) {
  95. unset($where['special_type']);
  96. $where['store_name'] = $where['title'];
  97. $data = Special::setWhere($where)->where('id', 'not in', $special_source)->where('type', 'in', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_COLUMN, SPECIAL_OTHER])->page((int)$where['page'], (int)$where['limit'])->select();
  98. $data = count($data) ? $data->toArray() : [];
  99. $count = Special::setWhere($where)->where('id', 'not in', $special_source)->where('type', 'in', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_COLUMN, SPECIAL_OTHER])->count();
  100. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_STORE) {
  101. unset($where['special_type']);
  102. $where['store_name'] = $where['title'];
  103. $data = Special::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_LIVE, SPECIAL_COLUMN, SPECIAL_OTHER])->page((int)$where['page'], (int)$where['limit'])->select();
  104. $data = count($data) ? $data->toArray() : [];
  105. $count = Special::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_LIVE, SPECIAL_COLUMN, SPECIAL_OTHER])->count();
  106. } else {
  107. if ($where['pid'] > 0) {
  108. $where['special_type'] = 0;
  109. }
  110. $data = self::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  111. $data = count($data) ? $data->toArray() : [];
  112. $count = self::setWhere($where)->where('id', 'not in', $special_source)->count();
  113. }
  114. return compact('data', 'count');
  115. }
  116. /**
  117. * 删除任务
  118. * @param $id
  119. * @return bool|int
  120. * @throws \think\exception\DbException
  121. */
  122. public static function delTask($id)
  123. {
  124. $task = self::get($id);
  125. if (!$task) return self::setErrorInfo('删除的数据不存在');
  126. return $task->delete();
  127. }
  128. /**
  129. * 设置直播关联查询条件
  130. * @param $where
  131. * @return $this
  132. */
  133. public static function setLiveWhereTask($where)
  134. {
  135. $model = self::where('live_id', $where['live_id']);
  136. if ($where['title']) $model = $model->where('title', 'like', "%$where[title]%");
  137. if ($where['start_time'] && $where['end_time']) $model = $model->where('add_time', 'between', [strtotime($where['start_time']), strtotime($where['end_time'])]);
  138. return $model;
  139. }
  140. /**
  141. * 获取直播关联的任务
  142. * @param $where
  143. * @return array
  144. * @throws \think\Exception
  145. * @throws \think\db\exception\DataNotFoundException
  146. * @throws \think\db\exception\ModelNotFoundException
  147. * @throws \think\exception\DbException
  148. */
  149. public static function getRelationTask($where)
  150. {
  151. $data = self::setLiveWhereTask($where)->page((int)$where['page'], (int)$where['limit'])->order('sort desc,id desc')->select();
  152. $data = count($data) ? $data->toArray() : [];
  153. foreach ($data as &$item) {
  154. $special = SpecialCourse::where('a.id', $item['coures_id'])->alias('a')->join('special s', 's.id=a.special_id')->field('s.id,s.title')->find();
  155. if ($special)
  156. $item['special_title'] = $special['title'] . '&nbsp/&nbsp' . $special['id'];
  157. else
  158. $item['special_title'] = '';
  159. }
  160. $count = self::setLiveWhereTask($where)->count();
  161. return compact('data', 'count');
  162. }
  163. }