SpecialTask.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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\merchant\model\special;
  12. use traits\ModelTrait;
  13. use basic\ModelBasic;
  14. /**
  15. * Class SpecialTask 专题素材
  16. * @package app\merchant\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. //设置where条件
  26. public static function setWhere($where, $alirs = '', $model = null)
  27. {
  28. $model = $model === null ? new self() : $model;
  29. $model = $alirs !== '' ? $model->alias($alirs) : $model;
  30. $alirs = $alirs === '' ? $alirs : $alirs . '.';
  31. if (isset($where['is_show']) && $where['is_show'] !== '') $model = $model->where("{$alirs}is_show", $where['is_show']);
  32. if (isset($where['pid']) && $where['pid'] > 0) {
  33. $pids = SpecialTaskCategory::categoryId($where['pid']);
  34. array_push($pids, $where['pid']);
  35. if (count($pids) > 0) {
  36. $model = $model->where("{$alirs}pid", 'in', $pids);
  37. } else {
  38. $model = $model->where("{$alirs}pid", $where['pid']);
  39. }
  40. }
  41. if (isset($where['title']) && $where['title']) $model = $model->where("{$alirs}title", 'LIKE', "%$where[title]%");
  42. if (isset($where['mer_id']) && $where['mer_id']) $model = $model->where("{$alirs}mer_id", $where['mer_id']);
  43. if (isset($where['special_type']) && $where['special_type']) $model = $model->where("{$alirs}type", $where['special_type']);
  44. $model = $model->where("{$alirs}is_del", 0);
  45. if (isset($where['special_id']) && $where['special_id']) $model = $model->where("{$alirs}special_id", 'in', [0, $where['special_id']]);
  46. if ($where['order'])
  47. $model = $model->order($alirs . self::setOrder($where['order']));
  48. else
  49. $model = $model->order("{$alirs}sort desc,{$alirs}id desc");
  50. return $model;
  51. }
  52. public static function getTaskCount($special_id)
  53. {
  54. $ids = self::getDb('special_source')->where('special_id', $special_id)->column('source_id');
  55. return self::where('is_show', 1)->where('is_del', 0)->where('id', 'in', $ids)->count();
  56. }
  57. //查找素材列表
  58. public static function getTaskList($where)
  59. {
  60. $data = self::setWhere($where)->page((int)$where['page'], (int)$where['limit'])->select();
  61. $data = count($data) ? $data->toArray() : [];
  62. $count = self::setWhere($where)->count();
  63. return compact('data', 'count');
  64. }
  65. public static function getTaskList2($where, $special_source)
  66. {
  67. if (isset($where['special_type']) && $where['special_type'] == SPECIAL_COLUMN) {
  68. unset($where['special_type']);
  69. $where['store_name'] = $where['title'];
  70. if ($where['type'] == '') {
  71. $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();
  72. $data = count($data) ? $data->toArray() : [];
  73. $count = Special::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_OTHER])->count();
  74. } else {
  75. $data = Special::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  76. $data = count($data) ? $data->toArray() : [];
  77. $count = Special::setWhere($where)->where('id', 'not in', $special_source)->count();
  78. }
  79. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_LIVE) {
  80. unset($where['special_type']);
  81. $where['store_name'] = $where['title'];
  82. if ($where['type'] == '') {
  83. $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();
  84. $data = count($data) ? $data->toArray() : [];
  85. $count = Special::setWhere($where)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_COLUMN, SPECIAL_OTHER])->count();
  86. } else {
  87. $data = Special::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  88. $data = count($data) ? $data->toArray() : [];
  89. $count = Special::setWhere($where)->where('id', 'not in', $special_source)->count();
  90. }
  91. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_SEVEN) {
  92. unset($where['special_type']);
  93. $where['store_name'] = $where['title'];
  94. $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();
  95. $data = count($data) ? $data->toArray() : [];
  96. $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();
  97. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_STORE) {
  98. unset($where['special_type']);
  99. $where['store_name'] = $where['title'];
  100. $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();
  101. $data = count($data) ? $data->toArray() : [];
  102. $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();
  103. } else {
  104. if ($where['pid'] > 0) {
  105. $where['special_type'] = 0;
  106. }
  107. $data = self::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  108. $data = count($data) ? $data->toArray() : [];
  109. $count = self::setWhere($where)->where('id', 'not in', $special_source)->count();
  110. }
  111. return compact('data', 'count');
  112. }
  113. /**
  114. * 删除任务
  115. * @param $id
  116. * @return bool|int
  117. * @throws \think\exception\DbException
  118. */
  119. public static function delTask($id)
  120. {
  121. $task = self::get($id);
  122. if (!$task) return self::setErrorInfo('删除的数据不存在');
  123. return $task->delete();
  124. }
  125. /**
  126. * 设置直播关联查询条件
  127. * @param $where
  128. * @return $this
  129. */
  130. public static function setLiveWhereTask($where)
  131. {
  132. $model = self::where('live_id', $where['live_id']);
  133. if ($where['title']) $model = $model->where('title', 'like', "%$where[title]%");
  134. if ($where['start_time'] && $where['end_time']) $model = $model->where('add_time', 'between', [strtotime($where['start_time']), strtotime($where['end_time'])]);
  135. return $model;
  136. }
  137. }