Special.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  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 app\admin\model\live\LiveGoods;
  13. use app\admin\model\live\LiveStudio;
  14. use app\admin\model\order\StoreOrder;
  15. use app\admin\model\special\SpecialSource;
  16. use app\admin\model\special\Lecturer;
  17. use app\admin\model\system\RecommendRelation;
  18. use app\admin\model\system\WebRecommendRelation;
  19. use think\cache\driver\Redis;
  20. use traits\ModelTrait;
  21. use basic\ModelBasic;
  22. use think\Url;
  23. use app\admin\model\special\SpecialBuy;
  24. use app\wap\model\routine\RoutineTemplate;
  25. use app\admin\model\wechat\WechatUser;
  26. use app\admin\model\merchant\Merchant;
  27. use service\SystemConfigService;
  28. use service\WechatTemplateService;
  29. /**
  30. * Class Special 专题
  31. * @package app\admin\model\special
  32. */
  33. class Special extends ModelBasic
  34. {
  35. use ModelTrait;
  36. protected static function init()
  37. {
  38. self::afterUpdate(function () {
  39. $subjectUrl = getUrlToDomain();
  40. del_redis_hash($subjectUrl . "wap_index_has", "recommend_list");
  41. del_redis_hash($subjectUrl . "web_index_has", "recommend_list");
  42. });
  43. }
  44. public function profile()
  45. {
  46. return $this->hasOne('SpecialContent', 'special_id', 'id')->field('content');
  47. }
  48. public function singleProfile()
  49. {
  50. return $this->hasOne('SpecialContent', 'special_id', 'id')->field('is_try,try_content,try_time,link,videoId,file_name,file_type,content');
  51. }
  52. public static function PreWhere($alert = '')
  53. {
  54. $alert = $alert ? $alert . '.' : '';
  55. return self::where([$alert . 'is_show' => 1, $alert . 'is_del' => 0, $alert . 'status' => 1]);
  56. }
  57. //动态赋值
  58. public static function getPinkStrarTimeAttr($value)
  59. {
  60. return $value ? date('Y-m-d H:i:s', $value) : '';
  61. }
  62. public static function getPinkEndTimeAttr($value)
  63. {
  64. return $value ? date('Y-m-d H:i:s', $value) : '';
  65. }
  66. public static function getAddTimeAttr($value)
  67. {
  68. return date('Y-m-d H:i:s', $value);
  69. }
  70. public static function getBannerAttr($value)
  71. {
  72. return is_string($value) ? json_decode($value, true) : $value;
  73. }
  74. public static function getLabelAttr($value)
  75. {
  76. return is_string($value) ? json_decode($value, true) : $value;
  77. }
  78. //end
  79. //设置
  80. public static function getBannerKeyAttr($banner)
  81. {
  82. if (is_string($banner)) $banner = json_decode($banner, true);
  83. if ($banner === false) return [];
  84. $value = [];
  85. foreach ($banner as $item) {
  86. $value[] = [
  87. 'is_show' => false,
  88. 'pic' => $item
  89. ];
  90. }
  91. return $value;
  92. }
  93. //获取单个专题
  94. public static function getOne($id, $is_live = false)
  95. {
  96. $special = self::get($id);
  97. if (!$special) return false;
  98. if ($special->is_del) return false;
  99. $special->banner = self::getBannerKeyAttr($special->banner);
  100. $special->profile->content = htmlspecialchars_decode($special->profile->content);
  101. if ($is_live) {
  102. $liveInfo = LiveStudio::where('special_id', $special->id)->find();
  103. if (!$liveInfo) return self::setErrorInfo('暂未查到直播间');
  104. if ($liveInfo->is_del) return self::setErrorInfo('直播间已删除无法编辑');
  105. $liveInfo->live_duration = (strtotime($liveInfo->stop_play_time) - strtotime($liveInfo->start_play_time)) / 60;
  106. $liveInfo = $liveInfo->toArray();
  107. } else
  108. $liveInfo = [];
  109. return [$special->toArray(), $liveInfo];
  110. }
  111. //获取单个轻专题
  112. public static function getsingleOne($id)
  113. {
  114. $special = self::get($id);
  115. if (!$special) return false;
  116. if ($special->is_del) return false;
  117. $special->singleProfile->content = htmlspecialchars_decode($special->singleProfile->content);
  118. return $special->toArray();
  119. }
  120. //设置条件
  121. public static function setWhere($where, $alert = '', $model = null)
  122. {
  123. $model = $model === null ? new self() : $model;
  124. if ($alert) $model = $model->alias($alert);
  125. $alert = $alert ? $alert . '.' : '';
  126. if (isset($where['order']) && $where['order'])
  127. $model = $model->order($alert . self::setOrder($where['order']));
  128. else
  129. $model = $model->order($alert . 'sort desc,' . $alert . 'id desc');
  130. if (isset($where['subject_id']) && $where['subject_id']!= '') $model = $model->where($alert . 'subject_id', $where['subject_id']);
  131. if (isset($where['mer_id']) && $where['mer_id'] != '') $model = $model->where($alert . 'mer_id', $where['mer_id']);
  132. if (isset($where['store_name']) && $where['store_name'] != '') $model = $model->where($alert . 'title|' . $alert . 'abstract|' . $alert . 'phrase|' . $alert . 'id', "LIKE", "%$where[store_name]%");
  133. if (isset($where['is_show']) && $where['is_show'] != '') $model = $model->where($alert . 'is_show', $where['is_show']);
  134. if (isset($where['type']) && $where['type'] && $where['type'] < 7) {
  135. $model = $model->where($alert . 'type', $where['type']);
  136. } else if (isset($where['type']) && $where['type'] && $where['type'] == 7) {
  137. $where['is_light'] = 1;
  138. }
  139. if (isset($where['is_light']) && $where['is_light']) $model = $model->where($alert . 'is_light', $where['is_light']);
  140. if (isset($where['special_type']) && $where['special_type'] != '') {
  141. $model = $model->where($alert . 'type', $where['special_type']);
  142. }
  143. if (isset($where['admin_id']) && $where['admin_id']!= '') $model = $model->where($alert . 'admin_id', $where['admin_id']);
  144. if (isset($where['start_time']) && $where['start_time'] && isset($where['end_time']) && $where['end_time']) $model = $model->whereTime($alert . 'add_time', 'between', [strtotime($where['start_time']), strtotime($where['end_time'])]);
  145. return $model->where($alert . 'is_del', 0)->where($alert . 'status', 1);
  146. }
  147. public static function getRelationList($where, $special_source)
  148. {
  149. if (isset($where['special_type']) && $where['special_type'] == SPECIAL_COLUMN) {
  150. unset($where['special_type']);
  151. $where['store_name'] = $where['title'];
  152. if ($where['type'] == '') {
  153. $data = self::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();
  154. $data = count($data) ? $data->toArray() : [];
  155. $count = self::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_OTHER])->count();
  156. } else {
  157. $data = self::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  158. $data = count($data) ? $data->toArray() : [];
  159. $count = self::setWhere($where)->where('id', 'not in', $special_source)->count();
  160. }
  161. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_LIVE) {
  162. unset($where['special_type']);
  163. $where['store_name'] = $where['title'];
  164. if ($where['type'] == '') {
  165. $data = self::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();
  166. $data = count($data) ? $data->toArray() : [];
  167. $count = self::setWhere($where)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_COLUMN, SPECIAL_OTHER])->count();
  168. } else {
  169. $data = self::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  170. $data = count($data) ? $data->toArray() : [];
  171. $count = self::setWhere($where)->where('id', 'not in', $special_source)->count();
  172. }
  173. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_SEVEN) {
  174. unset($where['special_type']);
  175. $where['store_name'] = $where['title'];
  176. $data = self::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();
  177. $data = count($data) ? $data->toArray() : [];
  178. $count = self::setWhere($where)->where('id', 'not in', $special_source)->where('type', 'in', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_COLUMN, SPECIAL_OTHER])->count();
  179. } elseif (isset($where['special_type']) && $where['special_type'] == SPECIAL_STORE) {
  180. unset($where['special_type']);
  181. $where['store_name'] = $where['title'];
  182. $data = self::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();
  183. $data = count($data) ? $data->toArray() : [];
  184. $count = self::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_LIVE, SPECIAL_COLUMN, SPECIAL_OTHER])->count();
  185. } else {
  186. $where['store_name'] = $where['title'];
  187. $data = self::setWhere($where)->where('id', 'not in', $special_source)->page((int)$where['page'], (int)$where['limit'])->select();
  188. $data = count($data) ? $data->toArray() : [];
  189. $count = self::setWhere($where)->where('id', 'not in', $special_source)->count();
  190. }
  191. foreach ($data as $key => &$value) {
  192. if ($value['mer_id']) {
  193. $value['mer_name'] = Merchant::where('id', $value['mer_id'])->value('mer_name');
  194. } else {
  195. $value['mer_name'] = '总平台';
  196. }
  197. if ($value['lecturer_id']) {
  198. $value['lecturer_name'] = Lecturer::where('id', $value['lecturer_id'])->value('lecturer_name');
  199. } else {
  200. $value['lecturer_name'] = '总平台';
  201. }
  202. }
  203. return compact('data', 'count');
  204. }
  205. /**拼团专题列表
  206. * @param $where
  207. */
  208. public static function getPinkList($where)
  209. {
  210. $data = self::setWhere($where, 'A')->field('A.*,S.name as subject_name')
  211. ->join('__SPECIAL_SUBJECT__ S', 'S.id=A.subject_id', 'LEFT')
  212. ->page((int)$where['page'], (int)$where['limit'])->where('A.is_pink', 1)->select();
  213. $data = count($data) ? $data->toArray() : [];
  214. foreach ($data as &$item) {
  215. $item['recommend'] = RecommendRelation::where('a.link_id', $item['id'])->where('a.type', 'in', [0, 2, 8])->alias('a')
  216. ->join('__RECOMMEND__ r', 'a.recommend_id=r.id')->column('a.id,r.title');
  217. $item['pink_end_time'] = $item['pink_end_time'] ? strtotime($item['pink_end_time']) : 0;
  218. $item['sales'] = StoreOrder::where(['paid' => 1, 'cart_id' => $item['id'], 'refund_status' => 0])->count();
  219. $liveGoods = LiveGoods::getOne(['special_id' => $item['id'], 'is_delete' => 0]);
  220. if ($item['mer_id']) {
  221. $item['mer_name'] = Merchant::where('id', $item['mer_id'])->value('mer_name');
  222. } else {
  223. $item['mer_name'] = '总平台';
  224. }
  225. $item['is_live_goods'] = 0;
  226. $item['live_goods_id'] = 0;
  227. if ($liveGoods) {
  228. $item['live_goods_id'] = $liveGoods->id;
  229. if ($liveGoods->is_show == 1) {
  230. $item['is_live_goods'] = 1;
  231. }
  232. }
  233. //查看拼团状态,如果已结束关闭拼团
  234. if ($item['is_pink'] && $item['pink_end_time'] < time()) {
  235. self::update(['is_pink' => 0], ['id' => $item['id']]);
  236. $item['is_pink'] = 0;
  237. }
  238. if (!$item['is_pink']) {
  239. $item['pink_money'] = 0;
  240. }
  241. $item['stream_name'] = LiveStudio::where('special_id', $item['id'])->value('stream_name');
  242. $item['live_id'] = LiveStudio::where('special_id', $item['id'])->value('id');
  243. $item['is_play'] = 0;
  244. if ($item['live_id']) {
  245. $item['online_num'] = LiveStudio::where('id', $item['live_id'])->value('online_num');
  246. $item['is_play'] = LiveStudio::where('id', $item['live_id'])->value('is_play') ? 1 : 0;
  247. }
  248. $item['buy_user_num'] = StoreOrder::where(['paid' => 1, 'cart_id' => $item['id']])->count('id');
  249. $item['start_play_time'] = LiveStudio::where('special_id', $item['id'])->value('start_play_time');
  250. }
  251. $count = self::setWhere($where)->where('is_pink', 1)->count();
  252. return compact('data', 'count');
  253. }
  254. //查找专题列表
  255. public static function getSpecialList($where)
  256. {
  257. $data = self::setWhere($where, 'A')->field('A.*,S.name as subject_name')
  258. ->join('__SPECIAL_SUBJECT__ S', 'S.id=A.subject_id', 'LEFT')
  259. ->page((int)$where['page'], (int)$where['limit'])->select();
  260. $data = count($data) ? $data->toArray() : [];
  261. foreach ($data as &$item) {
  262. $item['recommend'] = RecommendRelation::where('a.link_id', $item['id'])->where('a.type', 'in', [0, 2, 8])->alias('a')
  263. ->join('__RECOMMEND__ r', 'a.recommend_id=r.id')->column('a.id,r.title');
  264. $item['web_recommend'] = WebRecommendRelation::where('a.link_id', $item['id'])->where('a.type', 'in', [0, 1])->alias('a')
  265. ->join('__WEB_RECOMMEND__ r', 'a.recommend_id=r.id')->column('a.id,r.title');
  266. $item['pink_end_time'] = $item['pink_end_time'] ? strtotime($item['pink_end_time']) : 0;
  267. $item['sales'] = StoreOrder::where(['paid' => 1, 'cart_id' => $item['id'], 'refund_status' => 0])->count();
  268. $liveGoods = LiveGoods::getOne(['special_id' => $item['id'], 'is_delete' => 0]);
  269. if (!$item['quantity']) {
  270. $quantity = SpecialSource::getSpecialSourceCount($item['id']);
  271. $item['quantity'] = $quantity;
  272. $dat['quantity'] = $quantity;
  273. self::edit($dat, $item['id'], 'id');
  274. }
  275. if ($item['quantity'] > 0 && $item['sum'] == 0 || $item['quantity'] > 0 && $item['sum'] > 0 && $item['quantity'] > $item['sum']) {
  276. $item['sum'] = $item['quantity'];
  277. $dat['sum'] = $item['quantity'];
  278. self::edit($dat, $item['id'], 'id');
  279. }
  280. if ($item['mer_id']) {
  281. $item['mer_name'] = Merchant::where('id', $item['mer_id'])->value('mer_name');
  282. } else {
  283. $item['mer_name'] = '总平台';
  284. }
  285. if ($item['lecturer_id']) {
  286. $item['lecturer_name'] = Lecturer::where('id', $item['lecturer_id'])->value('lecturer_name');
  287. } else {
  288. $item['lecturer_name'] = '总平台';
  289. }
  290. $item['is_live_goods'] = 0;
  291. $item['live_goods_id'] = 0;
  292. if ($liveGoods) {
  293. $item['live_goods_id'] = $liveGoods->id;
  294. if ($liveGoods->is_show == 1) {
  295. $item['is_live_goods'] = 1;
  296. }
  297. }
  298. //查看拼团状态,如果已结束关闭拼团
  299. if ($item['is_pink'] && $item['pink_end_time'] < time()) {
  300. self::update(['is_pink' => 0], ['id' => $item['id']]);
  301. $item['is_pink'] = 0;
  302. }
  303. if (!$item['is_pink']) {
  304. $item['pink_money'] = 0;
  305. }
  306. if ($where['type'] == 4) $item['stream_name'] = LiveStudio::where('special_id', $item['id'])->value('stream_name');
  307. if ($where['type'] == 100) $where['type'] = [1,2,3,4,5,6,7,8,9];
  308. $item['live_id'] = LiveStudio::where('special_id', $item['id'])->value('id');
  309. $item['is_play'] = 0;
  310. if ($item['live_id']) {
  311. $item['online_num'] = LiveStudio::where('id', $item['live_id'])->value('online_num');
  312. $item['is_play'] = LiveStudio::where('id', $item['live_id'])->value('is_play') ? 1 : 0;
  313. }
  314. $item['buy_user_num'] = StoreOrder::where(['paid' => 1, 'cart_id' => $item['id']])->count('id');
  315. $item['start_play_time'] = LiveStudio::where('special_id', $item['id'])->value('start_play_time');
  316. }
  317. $count = self::setWhere($where)->count();
  318. return compact('data', 'count');
  319. }
  320. /**审核条件筛选
  321. * @param $where
  322. * @param string $alert
  323. * @param null $model
  324. * @return Special
  325. */
  326. public static function setExamineWhere($where, $alert = '', $model = null)
  327. {
  328. $model = $model === null ? new self() : $model;
  329. if ($alert) $model = $model->alias($alert);
  330. $alert = $alert ? $alert . '.' : '';
  331. if (isset($where['order']) && $where['order'])
  332. $model = $model->order($alert . self::setOrder($where['order']));
  333. else
  334. $model = $model->order($alert . 'sort desc,' . $alert . 'id desc');
  335. if (isset($where['subject_id']) && $where['subject_id']) $model = $model->where($alert . 'subject_id', $where['subject_id']);
  336. if (isset($where['mer_id']) && $where['mer_id'] != '') $model = $model->where($alert . 'mer_id', $where['mer_id']);
  337. if (isset($where['store_name']) && $where['store_name'] != '') $model = $model->where($alert . 'title|' . $alert . 'abstract|' . $alert . 'phrase|' . $alert . 'id', "LIKE", "%$where[store_name]%");
  338. if (isset($where['type']) && $where['type'] && $where['type'] < 7) {
  339. $model = $model->where($alert . 'type', $where['type']);
  340. } else if (isset($where['type']) && $where['type'] && $where['type'] == 7) {
  341. $where['is_light'] = 1;
  342. }
  343. if (isset($where['status']) && $where['status'] != '') {
  344. $model = $model->where($alert . 'status', $where['status']);
  345. } else {
  346. $model->where($alert . 'status', 'in', [0, -1]);
  347. }
  348. if (isset($where['is_light']) && $where['is_light']) $model = $model->where($alert . 'is_light', $where['is_light']);
  349. if (isset($where['start_time']) && $where['start_time'] && isset($where['end_time']) && $where['end_time']) $model = $model->whereTime($alert . 'add_time', 'between', [strtotime($where['start_time']), strtotime($where['end_time'])]);
  350. return $model->where($alert . 'is_del', 0);
  351. }
  352. /**专题审核列表
  353. * @param $where
  354. * @return array
  355. * @throws \think\Exception
  356. * @throws \think\db\exception\DataNotFoundException
  357. * @throws \think\db\exception\ModelNotFoundException
  358. * @throws \think\exception\DbException
  359. */
  360. public static function getSpecialExamineList($where)
  361. {
  362. $data = self::setExamineWhere($where, 'A')->field('A.*,S.name as subject_name')
  363. ->join('__SPECIAL_SUBJECT__ S', 'S.id=A.subject_id', 'LEFT')
  364. ->page((int)$where['page'], (int)$where['limit'])->select();
  365. $data = count($data) ? $data->toArray() : [];
  366. foreach ($data as $key => &$value) {
  367. $value['fail_time'] = date('Y-m-d H:i:s', $value['fail_time']);
  368. if ($value['mer_id']) {
  369. $value['mer_name'] = Merchant::where('id', $value['mer_id'])->value('mer_name');
  370. } else {
  371. $value['mer_name'] = '总平台';
  372. }
  373. }
  374. $count = self::setExamineWhere($where)->count();
  375. return compact('data', 'count');
  376. }
  377. /**审核失败
  378. * @param $id
  379. * @param $fail_msg
  380. * @return bool
  381. * @throws \think\exception\DbException
  382. */
  383. public static function changeFail($id, $mer_id, $fail_message)
  384. {
  385. $fail_time = time();
  386. $status = -1;
  387. $uid = Merchant::where('id', $mer_id)->value('uid');
  388. try {
  389. $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
  390. if ($wechat_notification_message == 1) {
  391. WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($uid), WechatTemplateService::EXAMINE_RESULT, [
  392. 'first' => '尊敬的讲师,您添加的专题审核结果已出。',
  393. 'keyword1' => '审核失败',
  394. 'keyword2' => date('Y-m-d H:i:s', time()),
  395. 'remark' => '失败原因:' . $fail_message
  396. ], '');
  397. } else {
  398. $dat['phrase5']['value'] = '专题审核失败';
  399. $dat['time24']['value'] = date('Y-m-d H:i:s', time());
  400. $dat['thing4']['value'] = '专题失败原因:' . $fail_message;
  401. RoutineTemplate::sendExamineResult($dat, $uid, '');
  402. }
  403. } catch (\Exception $e) {
  404. }
  405. return self::edit(compact('fail_time', 'fail_message', 'status'), $id);
  406. }
  407. /**审核成功
  408. * @param $id
  409. * @return bool
  410. */
  411. public static function changeSuccess($id, $mer_id)
  412. {
  413. $success_time = time();
  414. $status = 1;
  415. $uid = Merchant::where('id', $mer_id)->value('uid');
  416. try {
  417. $wechat_notification_message = SystemConfigService::get('wechat_notification_message');
  418. if ($wechat_notification_message == 1) {
  419. WechatTemplateService::sendTemplate(WechatUser::uidToOpenid($uid), WechatTemplateService::EXAMINE_RESULT, [
  420. 'first' => '尊敬的讲师,您添加的专题审核结果已出。',
  421. 'keyword1' => '审核成功',
  422. 'keyword2' => date('Y-m-d H:i:s', time()),
  423. 'remark' => '感恩您的努力付出,谢谢!'
  424. ], '');
  425. } else {
  426. $dat['phrase5']['value'] = '专题审核成功';
  427. $dat['time24']['value'] = date('Y-m-d H:i:s', time());
  428. $dat['thing4']['value'] = '您添加的专题审核结果已出!';
  429. RoutineTemplate::sendExamineResult($dat, $uid, '');
  430. }
  431. } catch (\Exception $e) {
  432. }
  433. return self::edit(compact('status', 'success_time'), $id);
  434. }
  435. /**获取试题关联的专题
  436. * @param $relation_ids
  437. * @return array
  438. * @throws \think\Exception
  439. * @throws \think\db\exception\DataNotFoundException
  440. * @throws \think\db\exception\ModelNotFoundException
  441. * @throws \think\exception\DbException
  442. */
  443. public static function getKnowledgePoints($relation_ids)
  444. {
  445. $data = self::PreWhere()->where('id', 'in', $relation_ids)->select();
  446. $data = count($data) > 0 ? $data->toArray() : [];
  447. $count = self::PreWhere()->where('id', 'in', $relation_ids)->count();
  448. return compact('data', 'count');
  449. }
  450. public static function getUserWhere($where)
  451. {
  452. return self::alias('s')->join('SpecialBuy b', 's.id=b.special_id')
  453. ->where(['b.uid' => $where['uid'], 's.is_del' => 0, 'b.is_del' => 0, 'b.type' => 3])
  454. ->field('s.title,s.type,s.id,s.image');
  455. }
  456. /**已获得专题
  457. * @param $where
  458. * @return array
  459. * @throws \think\Exception
  460. */
  461. public static function getUserSpecialList($where)
  462. {
  463. $data = self::getUserWhere($where)->page($where['page'], $where['limit'])->select();
  464. $count = self::getUserWhere($where)->count();
  465. return compact('data', 'count');
  466. }
  467. public static function getUserSpecialLists($where, $special_source, $type)
  468. {
  469. if ($type == 0) {
  470. $data = self::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();
  471. $data = count($data) ? $data->toArray() : [];
  472. $count = self::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_IMAGE_TEXT, SPECIAL_AUDIO, SPECIAL_VIDEO, SPECIAL_COLUMN, SPECIAL_OTHER])->count();
  473. } elseif ($type == 1) {
  474. $data = self::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_LIVE])->page((int)$where['page'], (int)$where['limit'])->select();
  475. $data = count($data) ? $data->toArray() : [];
  476. $count = self::setWhere($where)->where('id', 'not in', $special_source)->whereIn('type', [SPECIAL_LIVE])->count();
  477. }
  478. return compact('data', 'count');
  479. }
  480. public static function updateSpecialSource()
  481. {
  482. $list = SpecialSource::where('type', 0)->select();
  483. foreach ($list as $key => $item) {
  484. $type = self::where('id', $item['special_id'])->value('type');
  485. SpecialSource::where('id', $item['id'])->update(['type' => $type]);
  486. }
  487. return true;
  488. }
  489. }