Task.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. <?php
  2. namespace app\api\controller;
  3. use AlibabaCloud\Client\Exception\ClientException;
  4. use AlibabaCloud\Client\Exception\ServerException;
  5. use app\common\model\ActivityApply;
  6. use app\common\model\ActivityApplyItem;
  7. use app\common\model\ActivityPrice;
  8. use app\common\model\ArticleItem;
  9. use app\common\model\DatumUrl;
  10. use app\common\model\ForumReply;
  11. use app\common\model\GoodsOrder;
  12. use app\common\model\GoodsOrderItem;
  13. use app\common\model\LabelMessage;
  14. use app\common\model\StoreGoodsItem;
  15. use app\common\model\TopSearch;
  16. use app\common\model\User;
  17. use app\common\model\UserFacility;
  18. use app\common\model\UserForum;
  19. use app\common\model\UserMessage;
  20. use app\common\model\UserSearch;
  21. use app\common\model\UserTag;
  22. use app\common\model\VideoUrl;
  23. use app\common\service\UserSynth;
  24. use think\Db;
  25. /**
  26. * @title 定时任务
  27. * Class Task
  28. * @controller Task
  29. * @group base
  30. */
  31. class Task extends Base
  32. {
  33. /**
  34. * @title 标签推送[根据标签id]
  35. * @desc 标签推送
  36. * @author qc
  37. * @url /api/Task/taskUserMessage
  38. */
  39. public function taskUserMessage(){
  40. $list = UserMessage::field('id,user_id,content')->where('jg_type',1)->where('jg_status',0)->limit(0,50)->order('id')->select();
  41. foreach ($list as $v) {
  42. UserMessage::where(['id'=>$v['id']])->update(['jg_status'=>1]);
  43. UserMessage::Jpush($v['user_id'],$v['content']);
  44. }
  45. }
  46. /**
  47. * @title 同步回答量
  48. * @desc 同步回答量
  49. * @author qc
  50. * @url /api/Task/forum_num
  51. */
  52. public function forum_num(){
  53. $forum = UserForum::where('is_deleted',0)->field('id')->select();
  54. foreach ($forum as $k => $v){
  55. $apply = ForumReply::where('forum_id',$v['id'])->where('is_deleted',0)->count();
  56. if($apply){
  57. UserForum::where('id',$v['id'])->update(['r_num'=>$apply]);
  58. }else{
  59. UserForum::where('id',$v['id'])->update(['r_num'=>0]);
  60. }
  61. }
  62. $this->success('执行完成');
  63. }
  64. /**
  65. * @title 标签推送[根据标签id]
  66. * @desc 标签推送
  67. * @author qc
  68. * @url /api/Task/taskLabelMessage
  69. */
  70. //按照标签推送
  71. public function taskLabelMessage()
  72. {
  73. $list = LabelMessage::where('jg_status',0)->where('is_deleted',0)->select()->toArray();
  74. foreach ($list as $v) {
  75. //定时判断
  76. if($v['is_regular'] == 0){
  77. $date = date('Y-m-d H:i');
  78. $push_time = date('Y-m-d H:i',strtotime($v['push_time']));
  79. if($date < $push_time){
  80. continue;
  81. }
  82. }
  83. //定时判断end
  84. LabelMessage::where(['id'=>$v['id']])->update(['jg_status'=>1]);
  85. $ext = [];
  86. $ext['title'] = $v['title'];
  87. $channel = ['xiaomi'=>"108240",'huawei'=>'IM','oppo'=>'news']; //公信
  88. //$channel = ['xiaomi'=>"108237",'huawei'=>'IM','oppo'=>'message']; //私信
  89. // 全部推送
  90. if(!$v['label']) {
  91. $user_arr = User::where('status',1)->where('is_deleted',0)->column('id');
  92. // return json($user_arr);
  93. foreach ($user_arr as $user_id) {
  94. if($v['type'] == 2){
  95. $res = UserMessage::Jpush($user_id,$v['content'],'','','','',$channel,$ext);
  96. }else if($v['type'] == 3) {
  97. // $ext = [];
  98. // $ext['title'] = $v['title'];
  99. // $channel = ['xiaomi'=>"108240",'huawei'=>'IM','oppo'=>'news'];
  100. if(in_array($v['module'],['video','article','datum'])) {
  101. $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],'',$v['first_id'],$v['second_id'],$channel,$ext);
  102. }else{
  103. // if($v['module'] == 'supplier'){
  104. // //供应商产品
  105. // $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],5,$v['first_id'],'',$channel,$ext);
  106. // }
  107. // if($v['module'] == 'activity'){
  108. // //活动
  109. // $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],3,$v['first_id'],$channel,$ext);
  110. // }
  111. // if($v['module'] == 'forum'){
  112. // //问答
  113. // $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],6,$v['first_id'],$channel,$ext);
  114. // }
  115. // if($v['module'] == 'press'){
  116. // //新闻 暂时没有对应type
  117. // $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],5,$v['first_id'],$channel,$ext);
  118. // }
  119. // if($v['module'] == 'recruit'){
  120. // //招聘 暂时没有对应type
  121. // $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],5,$v['first_id'],$channel,$ext);
  122. // }
  123. $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],'',$v['first_id'],$v['second_id'],$channel,$ext);
  124. }
  125. }
  126. // return json($res);
  127. // $arr = [
  128. // 'user_id' => $user_id,
  129. // 'type' => 4,
  130. // 'log' => json_encode($res),
  131. // ];
  132. // Db::name('client_log')->insert($arr);
  133. }
  134. }else{
  135. // 搜索内容推送
  136. if($v['type'] == 4){
  137. $label = Db::name('user_label')->group('user_id')->where('label','in',$v['label'])->column('user_id');
  138. $user_arr = $label;
  139. }else{
  140. $label_arr = explode(',',$v['label']);
  141. $where_str = '';
  142. $search_arr=[];
  143. $tag_arr = [];
  144. foreach ($label_arr as $t){
  145. $search_arr[] = " title like '".'%'.$t."%'" .' ';
  146. $tag_arr[] = $t;
  147. }
  148. if(!empty($search_arr)) $where_str = implode(' OR ',$search_arr);
  149. // $user_arr = UserSearch::where($where_str)->column('user_id');
  150. //// return json($user_arr);
  151. $user_arr = [];
  152. $user = User::where('label','<>',null)->where('label','<>','||')->where('is_deleted',0)->field('id,label')->select();
  153. $tags = UserTag::where('title','in',$tag_arr)->column('id');
  154. foreach ($user as $key => $val){
  155. $label = explode('|',$val['label']);
  156. foreach ($label as $val1){
  157. if (array_search($val1, $tags) !== false) {
  158. // echo '存在';
  159. $user_arr[] = $val['id'];
  160. } else {
  161. // echo '不存在';
  162. }
  163. }
  164. }
  165. $user_arr = array_unique($user_arr);
  166. }
  167. foreach (array_unique($user_arr) as $user_id) {
  168. if($v['type'] == 2){
  169. // $ext = [];
  170. // $ext['title'] = $v['title'];
  171. // $channel = ['xiaomi'=>"108240",'huawei'=>'IM','oppo'=>'news'];
  172. // $res = UserMessage::Jpush($user_id,$v['content']);
  173. $res = UserMessage::Jpush($user_id,$v['content'],'','','','',$channel,$ext);
  174. }else if($v['type'] == 3 || $v['type'] == 4) {
  175. // $ext = [];
  176. // $ext['title'] = $v['title'];
  177. // $channel = ['xiaomi'=>"108240",'huawei'=>'IM','oppo'=>'news'];
  178. if(in_array($v['module'],['video','article','datum'])) {
  179. $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],'',$v['first_id'],$v['second_id'],$channel,$ext);
  180. }else{
  181. $res = UserMessage::Jpush($user_id,$v['content'],$v['module'],'',$v['first_id'],'',$channel,$ext);
  182. }
  183. }
  184. }
  185. }
  186. }
  187. }
  188. /**
  189. * @title 半年清理一次设备号
  190. * @desc
  191. * @author qc
  192. * @url /api/Task/removeFacility
  193. */
  194. public function removeFacility(){
  195. UserFacility::where(['set_time','< time',date('Y-m-d H:i:s',strtotime('-180 days'))])->update(['facility'=>'','set_time'=>date('Y-m-d H:i:s')]);
  196. }
  197. /**
  198. * @title 定时取消活动订单
  199. * @desc
  200. * @author qc
  201. * @url /api/Task/cancelApplyOrder
  202. */
  203. public function cancelApplyOrder()
  204. {
  205. $list = ActivityApply::with(['itemList'])
  206. ->where([['create_at','< time',date('Y-m-d H:i:s',strtotime('-5 minutes'))],['pay_type','<>',9],['pay_state','=',0],['cancel_state','=',0]])
  207. ->select()->toArray();
  208. foreach ($list as $v) {
  209. Db::startTrans();
  210. try {
  211. ActivityApply::where('id',$v['id'])->update(['cancel_state'=>1]);
  212. $act_title = \app\common\model\Activity::where('id',$v['act_id'])->value('title');
  213. $info_url = 'https://'.$_SERVER['HTTP_HOST'].'/dist/#/activity_order_info?id='.$v['id'];
  214. $message = '您报名的《'.$act_title."》活动订单,由于超时未支付,已为您取消";//,点击<a href=\"$info_url\">查看详情</a>";
  215. UserMessage::sendUserMessage($v['user_id'],'apply',4,0,0,$v['id'],$message,$v['id']);
  216. foreach ($v['item_list'] as $it) {
  217. ActivityPrice::where('id',$it['price_id'])->setInc('stock',$it['num']);
  218. }
  219. Db::commit();
  220. }catch (\Exception $e) {
  221. Db::rollback();
  222. }
  223. }
  224. }
  225. /**
  226. * @title 定时取消商城订单
  227. * @desc
  228. * @author qc
  229. * @url /api/Task/cancelGoodsOrder
  230. */
  231. public function cancelGoodsOrder()
  232. {
  233. $list = GoodsOrder::with(['orderItem'])
  234. ->where([['create_at','< time',date('Y-m-d H:i:s',strtotime('-1 day'))],['status','=',0],['pay_state','=',0],['cancel_state','=',0]])
  235. ->select()->toArray();
  236. // return json($list);
  237. $num = 0;
  238. foreach ($list as $v) {
  239. $order_id = $v['id'];
  240. Db::startTrans();
  241. try {
  242. $detail = $v;
  243. if($detail['status'] != 0) $this->exception('订单状态有误');
  244. // 取消订单状态
  245. GoodsOrder::update(['status'=>9,'cancel_state'=>1],['id'=>$order_id]);
  246. // 订单处理
  247. foreach ($detail['order_item'] as $item_info) {
  248. // 更改订单详情状态
  249. GoodsOrderItem::update(['status'=>9],['id'=>$item_info['id']]);
  250. StoreGoodsItem::stockChange($item_info['spec_id'],$item_info['goods_id'],$item_info['num']);
  251. }
  252. Db::commit();
  253. }catch (\Exception $e){
  254. $this->ret_msg = $e->getMessage();
  255. $this->is_commit = false;
  256. Db::rollback();
  257. }
  258. $num++;
  259. }
  260. $this->success('取消'.$num.'条订单');
  261. }
  262. /**
  263. * @title 定时自动收货
  264. * @desc
  265. * @author qc
  266. * @url /api/Task/confirmGoodsOrder
  267. */
  268. public function confirmGoodsOrder(){
  269. //express_send_at 发货时间
  270. //['express_send_at','< time',date('Y-m-d H:i:s',strtotime('-2 days'))]
  271. $list = GoodsOrder::where([['pay_state','=',1],['status','=',2]])
  272. ->select()->toArray();
  273. foreach ($list as $detail) {
  274. $data = get_delivery($detail['express_send_no']);
  275. Db::startTrans();
  276. if($data['issign'] == 1){
  277. $express_send_date = end($data['list']);
  278. $express_send_date = $express_send_date['time'];
  279. if($express_send_date < date('Y-m-d H:i:s',strtotime('-2 days'))){
  280. try {
  281. $order_id = $detail['id'];
  282. // $detail = GoodsOrder::where('id',$order_id)->find()->toArray();
  283. if($detail['status'] == 0) $this->error('订单未支付');
  284. if($detail['status'] == 1) $this->error('订单未发货');
  285. if($detail['status'] == 3) $this->error('订单已收货');
  286. GoodsOrder::update(['status'=>3,'express_state'=>2],['id'=>$order_id]);
  287. GoodsOrderItem::update(['status'=>3,'express_state'=>2],['order_id'=>$order_id]);
  288. UserMessage::create(['user_id'=>$detail['user_id'],'type_id'=>3,'relation_id'=>$order_id,'content'=>'订单收货成功']);
  289. Db::commit();
  290. }catch (\Exception $e) {
  291. Db::rollback();
  292. }
  293. }
  294. }
  295. }
  296. $this->success('执行成功');
  297. }
  298. /**
  299. * @title 活动报名定时提醒
  300. * @desc
  301. * @author qc
  302. * @url /api/Task/activityReminder
  303. */
  304. public function activityReminder()
  305. {
  306. $where = [];
  307. $where[] = ['task_send','=',0];
  308. $where[] = ['start_time','> time',date('Y-m-d H:i:s',strtotime('-24 hours'))];
  309. $where[] = ['status','=',1];
  310. $where[] = ['is_deleted','=',0];
  311. $list = \app\common\model\Activity::where($where)->select()->toArray();
  312. foreach ($list as $act_info)
  313. {
  314. \app\common\model\Activity::where(['id'=>$act_info['id']])->update(['task_send'=>1]);
  315. $ticket_list = ActivityApplyItem::where(['act_id'=>$act_info['id'],'sh_status'=>1,'is_hx'=>0])->select();
  316. foreach ($ticket_list as $v) {
  317. // 短信通知
  318. if($v['phone_pre'] == '86' && $v['phone']) UserSynth::phoneMessageSend($v['phone'],0,['ActivityName'=>$act_info['title'], 'time'=>$act_info['start_time'], 'adress'=>$act_info['address']]);
  319. }
  320. }
  321. }
  322. /**
  323. * @title 热搜定时
  324. * @desc
  325. * @author qc
  326. * @url /api/Task/topSearchTask
  327. */
  328. public function topSearchTask()
  329. {
  330. $where[] = ['hot_time','< time',date('Y-m-d H:i:s',strtotime('-7 days'))];
  331. // 视频
  332. $list = VideoUrl::where($where)->column('id');
  333. array_walk($list,function ($v){
  334. VideoUrl::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  335. TopSearch::saveData($v,'video');
  336. });
  337. // 图文
  338. $list = ArticleItem::where($where)->column('id');
  339. array_walk($list,function ($v){
  340. ArticleItem::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  341. TopSearch::saveData($v,'article');
  342. });
  343. // 资料
  344. $list = DatumUrl::where($where)->column('id');
  345. array_walk($list,function ($v){
  346. DatumUrl::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  347. TopSearch::saveData($v,'datum');
  348. });
  349. // 活动
  350. $list = \app\common\model\Activity::where($where)->column('id');
  351. array_walk($list,function ($v){
  352. \app\common\model\Activity::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  353. TopSearch::saveData($v,'activity');
  354. });
  355. // 需求
  356. $list = \app\common\model\PlatformDemand::where($where)->column('id');
  357. array_walk($list,function ($v){
  358. \app\common\model\PlatformDemand::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  359. TopSearch::saveData($v,'demand');
  360. });
  361. // 新闻
  362. $list = \app\common\model\Press::where($where)->column('id');
  363. array_walk($list,function ($v){
  364. \app\common\model\Press::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  365. TopSearch::saveData($v,'press');
  366. });
  367. // 问答
  368. $list = \app\common\model\UserForum::where($where)->column('id');
  369. array_walk($list,function ($v){
  370. \app\common\model\UserForum::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  371. TopSearch::saveData($v,'forum');
  372. });
  373. // 招聘
  374. $list = \app\common\model\Recruit::where($where)->column('id');
  375. array_walk($list,function ($v){
  376. \app\common\model\Recruit::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  377. TopSearch::saveData($v,'recruit');
  378. });
  379. // 供应商
  380. $list = \app\common\model\SupplierGoods::where($where)->column('id');
  381. array_walk($list,function ($v){
  382. \app\common\model\SupplierGoods::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  383. TopSearch::saveData($v,'supplier_goods');
  384. });
  385. // 商品
  386. $list = \app\common\model\StoreGoods::where($where)->column('id');
  387. array_walk($list,function ($v){
  388. \app\common\model\StoreGoods::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  389. TopSearch::saveData($v,'goods');
  390. });
  391. $this->success('执行成功');
  392. }
  393. function getDaysFromDate($date) {
  394. $startDate = new \DateTime($date);
  395. $endDate = new \DateTime('now');
  396. $interval = $startDate->diff($endDate);
  397. return $interval->days;
  398. }
  399. /**
  400. * @title 热搜定时1
  401. * @desc
  402. * @author qc
  403. * @url /api/Task/emptyTopSearchTask
  404. */
  405. public function emptyTopSearchTask1()
  406. {
  407. //热搜规则
  408. //根据后台输入的热搜阅读量排序
  409. //每10分钟前端更新一次
  410. //后台热搜阅读量每天晚上的23:59点,清楚7天前的那一天所有新增的内容的热搜阅读量
  411. //如:
  412. //2023年11月5日,新增了2篇文章,1个视频(不关心是几点新增的)
  413. //2023年11月12日,晚上23:59,将新增的2篇文章跟1个视频的热搜阅读清0
  414. //热搜阅读量可以手动更改,每次有用户点击时,热搜阅读量也增加1
  415. //top_search hot_num
  416. $start_time = date('Y-m-d 00:00:00',strtotime('-7 days'));
  417. $end_time = date('Y-m-d 23:59:59',strtotime('-7 days'));
  418. // return $start_time.'---'.$end_time;
  419. $where[] = ['release_time','> time',$start_time];
  420. $where[] = ['release_time','< time',$end_time];
  421. // $list = TopSearch::where($where)->column('id');
  422. // return json($list);
  423. // TopSearch::where($where)->update(['hot_num'=>0]);
  424. // foreach ($list as $k => $v){
  425. // TopSearch::where('id',$v)->update(['hot_num'=>0]);
  426. // }
  427. //清除热搜实例
  428. // $clean_days = sysconf('clean_days'); //清除热搜天数
  429. //
  430. // $list = \app\common\model\Press::where('release_time','<>','')->field('id,release_time')->order('release_time desc')->select();
  431. // $arr = [];
  432. // foreach ($list as $k => $v){
  433. // $specifiedDate = $v['release_time'];
  434. // $days = $this->getDaysFromDate($specifiedDate);
  435. // $c = $days % $clean_days;
  436. // if($c == 0){
  437. // \app\common\model\Press::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  438. // TopSearch::saveData($v,'press');
  439. // }
  440. // //echo "从 $specifiedDate 到今天的天数是: $days 天";
  441. // }
  442. // return json($list);
  443. //清除热搜实例end
  444. // 使用示例
  445. $list = VideoUrl::where($where)->column('id');
  446. array_walk($list,function ($v){
  447. VideoUrl::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  448. TopSearch::saveData($v,'video');
  449. });
  450. // 图文
  451. $list = ArticleItem::where($where)->column('id');
  452. array_walk($list,function ($v){
  453. ArticleItem::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  454. TopSearch::saveData($v,'article');
  455. });
  456. // 资料
  457. $list = DatumUrl::where($where)->column('id');
  458. array_walk($list,function ($v){
  459. DatumUrl::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  460. TopSearch::saveData($v,'datum');
  461. });
  462. // 活动
  463. $list = \app\common\model\Activity::where($where)->column('id');
  464. array_walk($list,function ($v){
  465. \app\common\model\Activity::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  466. TopSearch::saveData($v,'activity');
  467. });
  468. // 需求
  469. $list = \app\common\model\PlatformDemand::where($where)->column('id');
  470. array_walk($list,function ($v){
  471. \app\common\model\PlatformDemand::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  472. TopSearch::saveData($v,'demand');
  473. });
  474. // 新闻
  475. $list = \app\common\model\Press::where($where)->column('id');
  476. array_walk($list,function ($v){
  477. \app\common\model\Press::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  478. TopSearch::saveData($v,'press');
  479. });
  480. // 问答
  481. $list = \app\common\model\UserForum::where($where)->column('id');
  482. array_walk($list,function ($v){
  483. \app\common\model\UserForum::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  484. TopSearch::saveData($v,'forum');
  485. });
  486. // 招聘
  487. $list = \app\common\model\Recruit::where($where)->column('id');
  488. array_walk($list,function ($v){
  489. \app\common\model\Recruit::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  490. TopSearch::saveData($v,'recruit');
  491. });
  492. // 供应商
  493. $list = \app\common\model\SupplierGoods::where($where)->column('id');
  494. array_walk($list,function ($v){
  495. \app\common\model\SupplierGoods::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  496. TopSearch::saveData($v,'supplier_goods');
  497. });
  498. // 商品
  499. $list = \app\common\model\StoreGoods::where($where)->column('id');
  500. array_walk($list,function ($v){
  501. \app\common\model\StoreGoods::where('id',$v)->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  502. TopSearch::saveData($v,'goods');
  503. });
  504. $this->success('执行成功');
  505. }
  506. public function emptyTopSearchTask(){
  507. //热搜规则
  508. //根据后台输入的热搜阅读量排序
  509. //每10分钟前端更新一次
  510. //后台热搜阅读量每天晚上的23:59点,清楚7天前的那一天所有新增的内容的热搜阅读量
  511. //如:
  512. //2023年11月5日,新增了2篇文章,1个视频(不关心是几点新增的)
  513. //2023年11月12日,晚上23:59,将新增的2篇文章跟1个视频的热搜阅读清0
  514. //热搜阅读量可以手动更改,每次有用户点击时,热搜阅读量也增加1
  515. //top_search hot_num
  516. $start_time = date('Y-m-d 00:00:00');
  517. $start_time1 = date('Y-m-d 00:00:00',strtotime('-1 days'));
  518. // $end_time = date('Y-m-d 23:59:59',strtotime('-7 days'));
  519. // return $start_time.'---'.$end_time;
  520. // $where[] = ['release_time','> time',$start_time];
  521. // $where[] = ['release_time','< time',$end_time];
  522. // $list = TopSearch::where($where)->column('id');
  523. // return json($list);
  524. // TopSearch::where($where)->update(['hot_num'=>0]);
  525. // foreach ($list as $k => $v){
  526. // TopSearch::where('id',$v)->update(['hot_num'=>0]);
  527. // }
  528. $where = [];
  529. // $where = ['release_time','<>',''];
  530. $clean_days = sysconf('clean_days'); //清除热搜天数
  531. //清除热搜实例
  532. //
  533. //
  534. // $list = \app\common\model\Press::where('release_time','<>','')->field('id,release_time')->order('release_time desc')->select();
  535. // $arr = [];
  536. // foreach ($list as $k => $v){
  537. // $specifiedDate = $v['release_time'];
  538. // $days = $this->getDaysFromDate($specifiedDate);
  539. // $c = $days % $clean_days;
  540. // if($c == 0){
  541. // $arr[] = $v;
  542. // \app\common\model\Press::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  543. // TopSearch::saveData($v['id'],'press');
  544. // }
  545. // //echo "从 $specifiedDate 到今天的天数是: $days 天";
  546. // }
  547. // return json($arr);
  548. //清除热搜实例end
  549. $where = [];
  550. if($clean_days > 1){
  551. $where[] = ['release_time','< time',$start_time];
  552. $where[] = ['release_time','< time',$start_time1];
  553. }
  554. // 使用示例
  555. //视频
  556. $list = VideoUrl::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  557. foreach ($list as $k => $v){
  558. if($clean_days <= 1){
  559. VideoUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  560. TopSearch::saveData($v['id'],'video');
  561. }else{
  562. $specifiedDate = $v['release_time'];
  563. $days = $this->getDaysFromDate($specifiedDate);
  564. $c = $days % $clean_days;
  565. if($c == 0){
  566. VideoUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  567. TopSearch::saveData($v['id'],'video');
  568. }
  569. }
  570. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  571. }
  572. // 图文
  573. $list = ArticleItem::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  574. foreach ($list as $k => $v){
  575. if($clean_days <= 1){
  576. ArticleItem::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  577. TopSearch::saveData($v['id'],'article');
  578. }else{
  579. $specifiedDate = $v['release_time'];
  580. $days = $this->getDaysFromDate($specifiedDate);
  581. $c = $days % $clean_days;
  582. if($c == 0){
  583. ArticleItem::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  584. TopSearch::saveData($v['id'],'article');
  585. }
  586. }
  587. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  588. }
  589. // 资料
  590. $list = DatumUrl::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  591. foreach ($list as $k => $v){
  592. if($clean_days <= 1){
  593. DatumUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  594. TopSearch::saveData($v['id'],'datum');
  595. }else{
  596. $specifiedDate = $v['release_time'];
  597. $days = $this->getDaysFromDate($specifiedDate);
  598. $c = $days % $clean_days;
  599. if($c == 0){
  600. DatumUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  601. TopSearch::saveData($v['id'],'datum');
  602. }
  603. }
  604. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  605. }
  606. // 活动
  607. $list = \app\common\model\Activity::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  608. foreach ($list as $k => $v){
  609. if($clean_days <= 1){
  610. \app\common\model\Activity::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_nm'=>0]);
  611. TopSearch::saveData($v['id'],'activity');
  612. }else{
  613. $specifiedDate = $v['release_time'];
  614. $days = $this->getDaysFromDate($specifiedDate);
  615. $c = $days % $clean_days;
  616. if($c == 0){
  617. \app\common\model\Activity::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_nm'=>0]);
  618. TopSearch::saveData($v['id'],'activity');
  619. }
  620. }
  621. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  622. }
  623. // 需求
  624. $list = \app\common\model\PlatformDemand::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  625. foreach ($list as $k => $v){
  626. if($clean_days <= 1){
  627. \app\common\model\PlatformDemand::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  628. TopSearch::saveData($v['id'],'demand');
  629. }else{
  630. $specifiedDate = $v['release_time'];
  631. $days = $this->getDaysFromDate($specifiedDate);
  632. $c = $days % $clean_days;
  633. if($c == 0){
  634. \app\common\model\PlatformDemand::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  635. TopSearch::saveData($v['id'],'demand');
  636. }
  637. }
  638. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  639. }
  640. // 新闻
  641. $list = \app\common\model\Press::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  642. foreach ($list as $k => $v){
  643. if($clean_days <= 1){
  644. \app\common\model\Press::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  645. TopSearch::saveData($v['id'],'press');
  646. }else{
  647. $specifiedDate = $v['release_time'];
  648. $days = $this->getDaysFromDate($specifiedDate);
  649. $c = $days % $clean_days;
  650. if($c == 0){
  651. \app\common\model\Press::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  652. TopSearch::saveData($v['id'],'press');
  653. }
  654. }
  655. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  656. }
  657. // 问答
  658. $list = \app\common\model\UserForum::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  659. foreach ($list as $k => $v){
  660. if($clean_days <= 1){
  661. \app\common\model\UserForum::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  662. TopSearch::saveData($v['id'],'forum');
  663. }else{
  664. $specifiedDate = $v['release_time'];
  665. $days = $this->getDaysFromDate($specifiedDate);
  666. $c = $days % $clean_days;
  667. if($c == 0){
  668. \app\common\model\UserForum::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  669. TopSearch::saveData($v['id'],'forum');
  670. }
  671. }
  672. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  673. }
  674. // 招聘
  675. $list = \app\common\model\Recruit::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  676. foreach ($list as $k => $v){
  677. if($clean_days <= 1){
  678. \app\common\model\Recruit::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  679. TopSearch::saveData($v['id'],'recruit');
  680. }else{
  681. $specifiedDate = $v['release_time'];
  682. $days = $this->getDaysFromDate($specifiedDate);
  683. $c = $days % $clean_days;
  684. if($c == 0){
  685. \app\common\model\Recruit::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  686. TopSearch::saveData($v['id'],'recruit');
  687. }
  688. }
  689. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  690. }
  691. // 供应商
  692. $list = \app\common\model\SupplierGoods::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  693. foreach ($list as $k => $v){
  694. if($clean_days <= 1){
  695. \app\common\model\SupplierGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  696. TopSearch::saveData($v['id'],'supplier_goods');
  697. }else{
  698. $specifiedDate = $v['release_time'];
  699. $days = $this->getDaysFromDate($specifiedDate);
  700. $c = $days % $clean_days;
  701. if($c == 0){
  702. \app\common\model\SupplierGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  703. TopSearch::saveData($v['id'],'supplier_goods');
  704. }
  705. }
  706. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  707. }
  708. // 商品
  709. $list = \app\common\model\StoreGoods::where('release_time','<>','')->where($where)->field('id,release_time')->order('release_time desc')->select();
  710. foreach ($list as $k => $v){
  711. if($clean_days <= 1){
  712. \app\common\model\StoreGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  713. TopSearch::saveData($v['id'],'goods');
  714. }else{
  715. $specifiedDate = $v['release_time'];
  716. $days = $this->getDaysFromDate($specifiedDate);
  717. $c = $days % $clean_days;
  718. if($c == 0){
  719. \app\common\model\StoreGoods::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>0]);
  720. TopSearch::saveData($v['id'],'goods');
  721. }
  722. }
  723. //echo "从 $specifiedDate 到今天的天数是: $days 天";
  724. }
  725. $this->success('执行成功');
  726. }
  727. /**
  728. * @title 定时取消商城订单
  729. * @desc
  730. * @author qc
  731. * @url /api/Task/cancelStoreGoods
  732. */
  733. public function cancelStoreGoods()
  734. {
  735. $list = GoodsOrder::with(['orderItem','orderRefund'])
  736. ->where([['pay_state','=',0],['status','=',0],['create_at','< time',date('Y-m-d H:i:s',strtotime('-1 days'))]])
  737. ->select()->toArray();
  738. foreach ($list as $detail) {
  739. // 取消订单状态
  740. GoodsOrder::update(['status'=>9,'cancel_state'=>1],['id'=>$detail['id']]);
  741. // 订单处理
  742. foreach ($detail['order_item'] as $item_info) {
  743. // 更改订单详情状态
  744. GoodsOrderItem::update(['status'=>9],['id'=>$item_info['id']]);
  745. StoreGoodsItem::stockChange($item_info['spec_id'],$item_info['goods_id'],$item_info['num']);
  746. }
  747. }
  748. $this->success('执行成功');
  749. }
  750. /**
  751. * @title 定时增加热搜量
  752. * @desc
  753. * @author qc
  754. * @url /api/Task/regular_hot_num
  755. */
  756. public function regular_hot_num(){
  757. $date = date("Y-m-d H:i:s");
  758. //资料
  759. $list = DatumUrl::where('regular_hot_end_time','> time',$date)->select();
  760. foreach ($list as $k => $v){
  761. if($v['regular_hot_start_time'] < $v['regular_hot_end_time'] && $v['hot_target_num'] > $v['hot_num']){
  762. // $startdate = strtotime($v['regular_hot_start_time']);
  763. // $enddate = strtotime($v['regular_hot_end_time']);
  764. // $diff_seconds = ($enddate-$startdate)/60;
  765. // $min_num = ceil($diff_seconds/10);
  766. // $hot_num = $v['hot_target_num'] - $v['hot_num'];
  767. // $num = ceil($hot_num/$min_num);
  768. $t_num = $v['hot_num'] + $v['regular_num'];
  769. \app\common\model\DatumUrl::where('id',$v['id'])->update(['hot_time'=>date('Y-m-d H:i:s'),'hot_num'=>$t_num]);
  770. TopSearch::saveData($v['id'],'datum');
  771. }
  772. }
  773. $this->success('执行成功');
  774. }
  775. /**
  776. * @title 发送邮箱验证码
  777. * @desc 发送邮箱验证码
  778. * @author qc
  779. * @url /api/Task/detectionEmail
  780. * @method POST
  781. * @tag 邮箱验证码
  782. * @param name:email type:int require:1 default:-- desc:邮箱
  783. * @return name:code type:string default:-- desc:验证码
  784. */
  785. public function detectionEmail(){
  786. $Expedite = new Expedite();
  787. $esms = $Expedite->emailSms('2014945457@qq.com');
  788. return json_encode($esms,true);
  789. }
  790. /**
  791. * @title 发送邮箱验证码
  792. * @desc 发送邮箱验证码
  793. * @author qc
  794. * @url /api/Task/emailSms
  795. * @method POST
  796. * @tag 邮箱验证码
  797. * @param name:email type:int require:1 default:-- desc:邮箱
  798. * @return name:code type:string default:-- desc:验证码
  799. */
  800. function emailSms($email = ''){
  801. //$email = input('post.email');
  802. $user_info = User::where('email',$email)->where('is_deleted',0)->field('id,status')->find();
  803. if($user_info && $user_info['status'] == 0)$this ->error('用户被禁用,请联系官方');
  804. $code = rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9);
  805. require_once env('root_path').'/vendor/aliyunmail/aliyun-php-sdk-core/Config.php';
  806. $iClientProfile = \DefaultProfile::getProfile("cn-hangzhou", "LTAI5tJ5p12drZegeWVG33xZ", "82UWAiY5e5wH8tSkRvMtqVoGO0h8SB");
  807. $client = new \DefaultAcsClient($iClientProfile);
  808. $request = new Dm\SingleSendMailRequest();
  809. // D:\project\gyx\gaoyixia\vendor\aliyunmail\aliyun-php-sdk-dm\Dm\Request\V20151123\SingleSendMailRequest.php
  810. $request->setAccountName("gyx@yzm.gyxqcdz.com");
  811. $request->setFromAlias("[验证码]");
  812. $request->setAddressType(1);
  813. $request->setTagName("zonghuzhuche");
  814. $request->setReplyToAddress("true");
  815. $request->setToAddress($email);
  816. $request->setSubject("验证码");
  817. $img= "http://gaoyixia.hdlkeji.com/code/33.png";
  818. $img ="<img src='$img'/>";
  819. $html_body = '您的验证码'.$code.'有效时间5分钟';
  820. $request->setHtmlBody($html_body);
  821. try {
  822. $send_res = $client->getAcsResponse($request);
  823. $sms_data = array(
  824. 'phone'=>$email,
  825. 'code'=>$code,
  826. 'result'=>'OK'
  827. );
  828. Db::name('store_member_sms')->insert($sms_data);
  829. $this->success('发送成功');
  830. } catch (ClientException $e) {
  831. $this->error($e->getErrorMessage());
  832. // print_r($e->getErrorCode());
  833. // print_r($e->getErrorMessage());
  834. } catch (ServerException $e) {
  835. $this->error($e->getErrorMessage());
  836. // print_r($e->getErrorCode());
  837. // print_r($e->getErrorMessage());
  838. }
  839. }
  840. }