Minutes.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. namespace app\crontab\controller;
  3. use app\common\logic\Queue;
  4. use app\common\logic\Ticket;
  5. use app\common\model\TicketOrder;
  6. use think\facade\Cache;
  7. use think\facade\Db;
  8. /**
  9. * ============================================================================
  10. * DSMall多用户商城
  11. * ============================================================================
  12. * 版权所有 2014-2028 长沙德尚网络科技有限公司,并保留所有权利。
  13. * 网站地址: http://www.csdeshang.com
  14. * ----------------------------------------------------------------------------
  15. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
  16. * 不允许对程序代码以任何形式任何目的的再发布。
  17. * ============================================================================
  18. * 定时器
  19. */
  20. class Minutes extends BaseCron
  21. {
  22. const ORDER_CANCEL_TIME = 600;
  23. /**
  24. * 默认方法
  25. */
  26. public function index()
  27. {
  28. /*$this->_cron_queue();
  29. $this->_cron_common();
  30. $this->_cron_mail_send();
  31. $this->_cron_pintuan();
  32. $this->_cron_bonus();
  33. $this->_cron_pbargain();
  34. $this->_cron_presell();
  35. $this->_cron_sms();*/
  36. $this->_order_timeout_cancel();
  37. $this->_ticket_timeout_cancel();
  38. $this->_order_timeout_no_translate();
  39. }
  40. /**
  41. * 短信的处理
  42. */
  43. private function _cron_sms()
  44. {
  45. $smslog_model = model('smslog');
  46. $condition = [];
  47. $condition[] = ['smslog_state', '=', 0];
  48. $smslog_list = $smslog_model->getSmsList($condition, '', 100, 'smslog_id asc');
  49. $sms = new \sendmsg\Sms();
  50. foreach ($smslog_list as $val) {
  51. $smslog_param = json_decode($val['smslog_msg'], true);
  52. $smslog_msg = $smslog_param['message'];
  53. $send_result = $sms->send($val['smslog_phone'], $smslog_param);
  54. if ($send_result['code'] == true) {
  55. $smslog_state = 1;
  56. } else {
  57. $smslog_state = 2;
  58. }
  59. $condition = [];
  60. $condition[] = ['smslog_id', '=', $val['smslog_id']];
  61. $update = [
  62. 'smslog_state' => $smslog_state,
  63. 'smslog_msg' => $smslog_msg,
  64. 'smslog_smstime' => TIMESTAMP,
  65. ];
  66. $smslog_model->editSms($update, $condition);
  67. }
  68. }
  69. /**
  70. * 预售活动的状态的处理
  71. */
  72. private function _cron_presell()
  73. {
  74. $presell_model = model('presell');
  75. //自动开始时间到期的店铺预售活动
  76. $condition = [];
  77. $condition[] = ['presell_state', '=', 1];
  78. $condition[] = ['presell_start_time', '<', TIMESTAMP];
  79. $presell_model->editPresell(['presell_state' => 2], $condition);
  80. //自动结束时间过期的店铺预售活动
  81. $condition = [];
  82. $condition[] = ['presell_end_time', '<', TIMESTAMP];
  83. $presell_model->endPresell($condition);
  84. //预售结束后72小时未付尾款取消订单
  85. $order_model = model('order');
  86. $logic_order = model('order', 'logic');
  87. $condition = [];
  88. $condition[] = ['presell_deposit_amount', '>', 0];
  89. $condition[] = ['presell_end_time', '<', TIMESTAMP - 72 * 3600];
  90. $condition[] = ['order_state', 'in', [ORDER_STATE_NEW, ORDER_STATE_DEPOSIT, ORDER_STATE_REST]];
  91. $order_list = $order_model->getOrderList($condition, 100);
  92. foreach ($order_list as $order_info) {
  93. $logic_order->changeOrderStateCancel($order_info, 'system', '预售结束后72小时未付尾款取消订单');
  94. }
  95. }
  96. /**
  97. * 砍价活动的状态的处理
  98. */
  99. private function _cron_pbargain()
  100. {
  101. $pbargain_model = model('pbargain');
  102. //自动开始时间到期的店铺砍价活动
  103. $condition = [];
  104. $condition[] = ['bargain_state', '=', 1];
  105. $condition[] = ['bargain_begintime', '<', TIMESTAMP];
  106. $pbargain_model->editBargain(['bargain_state' => 2], $condition);
  107. //自动结束时间过期的店铺砍价活动
  108. $condition = [];
  109. $condition[] = ['bargain_endtime', '<', TIMESTAMP];
  110. $pbargain_model->endBargain($condition);
  111. //自动结束砍价失败的用户砍价活动
  112. $pbargainorder_model = model('pbargainorder');
  113. $condition = 'bargainorder_state=1 AND bargainorder_endtime<' . TIMESTAMP . ' AND bargainorder_times<bargain_total';
  114. $pbargainorder_model->editPbargainorder($condition, ['bargainorder_state' => 3]);
  115. }
  116. /**
  117. * 邮件信息发送队列的处理
  118. */
  119. private function _cron_queue()
  120. {
  121. //获取当前存储的数量
  122. $QueueClientNum = Cache::get('QueueClientNum');
  123. var_dump('-----------队列执行开始-------------');
  124. var_dump('数量:' . $QueueClientNum);
  125. $QueueLogic = new Queue();
  126. for ($i = 1; $i <= $QueueClientNum; $i++) {
  127. $info = Cache::pull('QueueClient_' . $i);#获取缓存
  128. if (empty($info)) {
  129. continue;
  130. }
  131. $info = unserialize($info);
  132. $key = key($info);
  133. $value = current($info);
  134. $QueueLogic->$key($value);
  135. }
  136. var_dump('-----------队列结束-------------');
  137. Cache::set('QueueClientNum', NULL);
  138. }
  139. /**
  140. * 拼团相关处理
  141. */
  142. private function _cron_pintuan()
  143. {
  144. $ppintuan_model = model('ppintuan');
  145. $ppintuangroup_model = model('ppintuangroup');
  146. $ppintuanorder_model = model('ppintuanorder');
  147. //自动关闭时间过期的店铺拼团活动
  148. $condition = [];
  149. $condition[] = ['pintuan_end_time', '<', TIMESTAMP];
  150. $ppintuan_model->endPintuan($condition);
  151. //查看正在进行开团的列表.
  152. $condition = [];
  153. $condition[] = ['pintuangroup_state', '=', 1];
  154. $pintuangroup_list = $ppintuangroup_model->getPpintuangroupList($condition);
  155. $success_ids = [];#拼团开团成功的拼团开团ID
  156. $fail_ids = [];#拼团开团失败的拼团开团ID
  157. foreach ($pintuangroup_list as $key => $pintuangroup) {
  158. //判断当前参团是否已过期
  159. if (TIMESTAMP >= $pintuangroup['pintuangroup_starttime'] + $pintuangroup['pintuangroup_limit_hour'] * 3600) {
  160. //当已参团人数 大于 当前开团的 参团人数
  161. if ($pintuangroup['pintuangroup_joined'] >= $pintuangroup['pintuangroup_limit_number']) {
  162. //满足开团人数,查看对应的订单是否付款,未付款则拼团失败,订单取消,订单款项退回.
  163. $condition = [];
  164. $condition[] = ['ppintuanorder.pintuangroup_id', '=', $pintuangroup['pintuangroup_id']];
  165. if (!$pintuangroup['pintuangroup_is_virtual']) {
  166. $condition[] = ['order.order_state', '=', 20];
  167. $count = Db::name('ppintuanorder')->alias('ppintuanorder')->join('order order', 'order.order_id=ppintuanorder.order_id')->where($condition)->count();
  168. } else {
  169. $condition[] = ['vrorder.order_state', '=', 20];
  170. $count = Db::name('ppintuanorder')->alias('ppintuanorder')->join('vrorder vrorder', 'vrorder.order_id=ppintuanorder.order_id')->where($condition)->count();
  171. }
  172. if ($count == $pintuangroup['pintuangroup_joined']) {
  173. //表示全部付款,拼团成功
  174. $success_ids[] = $pintuangroup['pintuangroup_id'];
  175. } else {
  176. $fail_ids[] = $pintuangroup['pintuangroup_id'];
  177. }
  178. } else {
  179. //未满足开团人数
  180. $fail_ids[] = $pintuangroup['pintuangroup_id'];
  181. }
  182. }
  183. }
  184. $condition = [];
  185. //在拼团失败的所有订单,已经付款的订单列表,取消订单,并且退款,未付款的订单自动取消订单
  186. $condition[] = ['ppintuanorder.pintuangroup_id', 'in', implode(',', $fail_ids)];
  187. $condition[] = ['ppintuanorder.pintuanorder_type', '=', 0];
  188. $condition[] = ['order.order_state', '=', 20];
  189. $ppintuanorder_list = Db::name('ppintuanorder')->field('order.*')->alias('ppintuanorder')->join('order order', 'order.order_id=ppintuanorder.order_id')->where($condition)->select()->toArray();
  190. //针对已付款,拼团没成功的订单,进行取消订单以及退款操作
  191. $order_model = model('order');
  192. $logic_order = model('order', 'logic');
  193. foreach ($ppintuanorder_list as $key => $order_info) {
  194. try {
  195. Db::startTrans();
  196. $logic_order->changeOrderStateCancel($order_info, 'system', '系统', '拼团未成功系统自动关闭订单', true, false, true);
  197. } catch (\Exception $e) {
  198. Db::rollback();
  199. continue;
  200. }
  201. Db::commit();
  202. }
  203. $condition = [];
  204. $condition[] = ['ppintuanorder.pintuangroup_id', 'in', implode(',', $fail_ids)];
  205. $condition[] = ['ppintuanorder.pintuanorder_type', '=', 1];
  206. $condition[] = ['vrorder.order_state', '=', 20];
  207. $ppintuanorder_list = Db::name('ppintuanorder')->field('vrorder.*')->alias('ppintuanorder')->join('vrorder vrorder', 'vrorder.order_id=ppintuanorder.order_id')->where($condition)->select()->toArray();
  208. $logic_vrorder = model('vrorder', 'logic');
  209. foreach ($ppintuanorder_list as $key => $order_info) {
  210. $logic_vrorder->changeOrderStateCancel($order_info, 'system', '系统', '拼团未成功系统自动关闭订单', false);
  211. }
  212. //失败修改拼团相关数据库信息
  213. $condition = [];
  214. $condition[] = ['pintuangroup_id', 'in', implode(',', $fail_ids)];
  215. $ppintuangroup_model->failPpintuangroup($condition);
  216. //成功修改拼团相关数据库信息
  217. $condition = [];
  218. $condition[] = ['pintuangroup_is_virtual', '=', 0];
  219. $condition[] = ['pintuangroup_id', 'in', implode(',', $success_ids)];
  220. $condition2 = [];
  221. $condition2[] = ['pintuangroup_id', 'in', implode(',', $success_ids)];
  222. $ppintuangroup_model->successPpintuangroup($condition, $condition2);
  223. //给成功拼团的虚拟订单发送兑换码
  224. $vrorder_model = model('vrorder');
  225. $condition = [];
  226. $condition[] = ['order_promotion_type', '=', 2];
  227. $condition[] = ['promotions_id', 'in', implode(',', $success_ids)];
  228. $vrorder_list = $vrorder_model->getVrorderList($condition, 1000);
  229. foreach ($vrorder_list as $vrorder) {
  230. $vrorder_model->addVrorderCode($vrorder);
  231. $condition = [];
  232. $condition[] = ['pintuangroup_id', '=', $vrorder['promotions_id']];
  233. $ppintuangroup_model->successPpintuangroup($condition, $condition);
  234. }
  235. }
  236. /**
  237. * 处理过期红包
  238. */
  239. private function _cron_bonus()
  240. {
  241. $condition = [];
  242. $condition[] = ['bonus_endtime', '<', TIMESTAMP];
  243. $condition[] = ['bonus_state', '=', 1];
  244. $data = [
  245. 'bonus_state' => 2,
  246. ];
  247. model('bonus')->editBonus($condition, $data);
  248. }
  249. /**
  250. * 发送邮件消息
  251. */
  252. private function _cron_mail_send()
  253. {
  254. //每次发送数量
  255. $_num = 50;
  256. $storemsgcron_model = model('mailcron');
  257. $cron_array = $storemsgcron_model->getMailCronList([], $_num);
  258. if (!empty($cron_array)) {
  259. $email = new \sendmsg\Email();
  260. $mail_array = [];
  261. foreach ($cron_array as $val) {
  262. $return = $email->send_sys_email($val['mailcron_address'], $val['mailcron_subject'], $val['mailcron_contnet']);
  263. if ($return) {
  264. // 记录需要删除的id
  265. $mail_array[] = $val['mailcron_id'];
  266. }
  267. }
  268. // 删除已发送的记录
  269. $storemsgcron_model->delMailCron([['mailcron_id', 'in', $mail_array]]);
  270. }
  271. }
  272. /**
  273. * 执行通用任务
  274. */
  275. private function _cron_common()
  276. {
  277. //查找待执行任务
  278. $cron_model = model('cron');
  279. $cron = $cron_model->getCronList([['exetime', '<=', TIMESTAMP]]);
  280. if (!is_array($cron)) return;
  281. $cron_array = [];
  282. $cronid = [];
  283. foreach ($cron as $v) {
  284. $cron_array[$v['type']][$v['exeid']] = $v;
  285. }
  286. foreach ($cron_array as $k => $v) {
  287. // 如果方法不存是,直接删除id
  288. if (!method_exists($this, '_cron_' . $k)) {
  289. $tmp = current($v);
  290. $cronid[] = $tmp['id'];
  291. continue;
  292. }
  293. $result = call_user_func_array([$this, '_cron_' . $k], [$v]);
  294. if (is_array($result)) {
  295. $cronid = array_merge($cronid, $result);
  296. }
  297. }
  298. //删除执行完成的cron信息
  299. if (!empty($cronid) && is_array($cronid)) {
  300. $cron_model->delCron([['id', 'in', $cronid]]);
  301. }
  302. }
  303. /**
  304. * 上架
  305. *
  306. * @param array $cron
  307. */
  308. private function _cron_1($cron = [])
  309. {
  310. $condition = [['goods_commonid', 'in', array_keys($cron)]];
  311. $update = model('goods')->editProducesOnline($condition);
  312. if ($update) {
  313. //返回执行成功的cronid
  314. $cronid = [];
  315. foreach ($cron as $v) {
  316. $cronid[] = $v['id'];
  317. }
  318. } else {
  319. return false;
  320. }
  321. return $cronid;
  322. }
  323. /**
  324. * 根据商品id更新商品促销价格
  325. *
  326. * @param array $cron
  327. */
  328. private function _cron_2($cron = [])
  329. {
  330. $condition = [['goods_id', 'in', array_keys($cron)]];
  331. $update = model('goods')->editGoodsPromotionPrice($condition);
  332. if ($update) {
  333. //返回执行成功的cronid
  334. $cronid = [];
  335. foreach ($cron as $v) {
  336. $cronid[] = $v['id'];
  337. }
  338. } else {
  339. return false;
  340. }
  341. return $cronid;
  342. }
  343. /**
  344. * 优惠套装过期
  345. *
  346. * @param array $cron
  347. */
  348. private function _cron_3($cron = [])
  349. {
  350. $pbundling_model = model('pbundling');
  351. if (intval(config('ds_config.promotion_bundling_price')) != 0) {
  352. //如果没有购买过套餐,则将之前添加的优惠组合关闭
  353. Db::name('pbundling')->alias('pbundling')->join('pbundlingquota pbundlingquota', 'pbundling.store_id = pbundlingquota.store_id', 'LEFT')->where('pbundlingquota.store_id', null)->update(['bl_state' => $pbundling_model::STATE0]);
  354. }
  355. $condition = [['store_id', 'in', array_keys($cron)]];
  356. $update = $pbundling_model->editBundlingQuotaClose($condition);
  357. if ($update) {
  358. //返回执行成功的cronid
  359. $cronid = [];
  360. foreach ($cron as $v) {
  361. $cronid[] = $v['id'];
  362. }
  363. } else {
  364. return false;
  365. }
  366. return $cronid;
  367. }
  368. /**
  369. * 推荐展位过期
  370. *
  371. * @param array $cron
  372. */
  373. private function _cron_4($cron = [])
  374. {
  375. $pbooth_model = model('pbooth');
  376. if (intval(config('ds_config.promotion_bundling_price')) != 0) {
  377. //如果没有购买过套餐,则将之前添加的优惠组合关闭
  378. Db::name('pboothgoods')->alias('pboothgoods')->join('pboothquota pboothquota', 'pboothgoods.store_id = pboothquota.store_id', 'LEFT')->where('pboothquota.store_id', null)->update(['boothgoods_state' => $pbooth_model::STATE0]);
  379. }
  380. $condition = [['store_id', 'in', array_keys($cron)]];
  381. $update = $pbooth_model->editBoothClose($condition);
  382. if ($update) {
  383. //返回执行成功的cronid
  384. $cronid = [];
  385. foreach ($cron as $v) {
  386. $cronid[] = $v['id'];
  387. }
  388. } else {
  389. return false;
  390. }
  391. return $cronid;
  392. }
  393. /**
  394. * 抢购开始更新商品促销价格
  395. *
  396. * @param array $cron
  397. */
  398. private function _cron_5($cron = [])
  399. {
  400. $condition = [];
  401. $condition[] = ['goods_commonid', 'in', array_keys($cron)];
  402. $condition[] = ['groupbuy_starttime', '<', TIMESTAMP];
  403. $condition[] = ['groupbuy_endtime', '>', TIMESTAMP];
  404. $groupbuy = model('groupbuy')->getGroupbuyList($condition);
  405. foreach ($groupbuy as $val) {
  406. model('goods')->editGoods(['goods_promotion_price' => $val['groupbuy_price'], 'goods_promotion_type' => 1], ['goods_commonid' => $val['goods_commonid']]);
  407. }
  408. //返回执行成功的cronid
  409. $cronid = [];
  410. foreach ($cron as $v) {
  411. $cronid[] = $v['id'];
  412. }
  413. return $cronid;
  414. }
  415. /**
  416. * 抢购过期
  417. *
  418. * @param array $cron
  419. */
  420. private function _cron_6($cron = [])
  421. {
  422. $condition = [['goods_commonid', 'in', array_keys($cron)]];
  423. //抢购活动过期
  424. $update = model('groupbuy')->editExpireGroupbuy($condition);
  425. if ($update) {
  426. //返回执行成功的cronid
  427. $cronid = [];
  428. foreach ($cron as $v) {
  429. $cronid[] = $v['id'];
  430. }
  431. } else {
  432. return false;
  433. }
  434. return $cronid;
  435. }
  436. /**
  437. * 限时折扣过期
  438. *
  439. * @param array $cron
  440. */
  441. private function _cron_7($cron = [])
  442. {
  443. $condition = [['xianshi_id', 'in', array_keys($cron)]];
  444. //限时折扣过期
  445. $update = model('pxianshi')->editExpireXianshi($condition);
  446. if ($update) {
  447. //返回执行成功的cronid
  448. $cronid = [];
  449. foreach ($cron as $v) {
  450. $cronid[] = $v['id'];
  451. }
  452. } else {
  453. return false;
  454. }
  455. return $cronid;
  456. }
  457. /**
  458. * 批发过期
  459. *
  460. * @param array $cron
  461. */
  462. private function _cron_8($cron = [])
  463. {
  464. $condition = [['wholesale_id', 'in', array_keys($cron)]];
  465. //限时折扣过期
  466. $update = model('wholesale')->editExpireWholesale($condition);
  467. if ($update) {
  468. //返回执行成功的cronid
  469. $cronid = [];
  470. foreach ($cron as $v) {
  471. $cronid[] = $v['id'];
  472. }
  473. } else {
  474. return false;
  475. }
  476. return $cronid;
  477. }
  478. /**
  479. * 未付款订单超期自动关闭
  480. */
  481. private function _order_timeout_cancel()
  482. {
  483. //实物订单超期未支付系统自动关闭
  484. $_break = false;
  485. $chain_order_model = model('chain_order');
  486. $order_model = model('order');
  487. $logic_order = model('order', 'logic');
  488. $condition = [];
  489. $condition[] = ['order_state', '=', ORDER_STATE_NEW];
  490. $condition[] = ['add_time', '<', TIMESTAMP - self::ORDER_CANCEL_TIME];
  491. //分批,每批处理100个订单,最多处理5W个订单
  492. for ($i = 0; $i < 500; $i++) {
  493. if ($_break) {
  494. break;
  495. }
  496. $order_list = $order_model->getOrderList($condition, '', '*', '', 100);
  497. if (empty($order_list))
  498. break;
  499. foreach ($order_list as $order_info) {
  500. try {
  501. Db::startTrans();
  502. $member = Db::name('member')->where('member_id', $order_info['buyer_id'])->find();
  503. $logic_order->changeOrderStateCancel($order_info, 'system', '系统', '超期未支付系统自动关闭订单', true, false);
  504. $logic_order->orderCancelBack($order_info, $member);
  505. } catch (\Exception $e) {
  506. Db::rollback();
  507. $this->log('实物订单超期未支付关闭失败SN:' . $order_info['order_sn']);
  508. $_break = true;
  509. break;
  510. }
  511. Db::commit();
  512. $chain_order_model->editChainOrderCancel($order_info['order_id']);
  513. }
  514. }
  515. //虚拟订单超期未支付系统自动关闭
  516. $_break = false;
  517. $vrorder_model = model('vrorder');
  518. $logic_vrorder = model('vrorder', 'logic');
  519. $condition = [];
  520. $condition[] = ['order_state', '=', ORDER_STATE_NEW];
  521. $condition[] = ['add_time', '<', TIMESTAMP - self::ORDER_CANCEL_TIME];
  522. //分批,每批处理100个订单,最多处理5W个订单
  523. for ($i = 0; $i < 500; $i++) {
  524. if ($_break) {
  525. break;
  526. }
  527. $order_list = $vrorder_model->getVrorderList($condition, '', '*', '', 100);
  528. if (empty($order_list))
  529. break;
  530. foreach ($order_list as $order_info) {
  531. $member = Db::name('member')->where('member_id', $order_info['buyer_id'])->find();
  532. $result = $logic_vrorder->changeOrderStateCancel($order_info, 'system', '超期未支付系统自动关闭订单', false);
  533. $logic_vrorder->orderCancelBack($order_info, $member);
  534. }
  535. if (!$result['code']) {
  536. $this->log('虚拟订单超期未支付关闭失败SN:' . $order_info['order_sn']);
  537. $_break = true;
  538. break;
  539. }
  540. }
  541. }
  542. /**
  543. * 电影票超时取消
  544. */
  545. private function _ticket_timeout_cancel()
  546. {
  547. $ticket_model = new TicketOrder();
  548. $logic_ticket = new Ticket();
  549. $condition = [];
  550. $condition[] = ['order_state', '=', ORDER_STATE_NEW];
  551. $condition[] = ['add_time', '<', TIMESTAMP - self::ORDER_CANCEL_TIME];
  552. $order_list = $ticket_model->where($condition)->select();
  553. if (!$order_list->isEmpty()) {
  554. foreach ($order_list as $order_info) {
  555. $logic_ticket->changeOrderStateCancel($order_info);
  556. }
  557. }
  558. }
  559. /**
  560. * 实物订单已付款24小时未发货,增加短信提醒
  561. */
  562. private function _order_timeout_no_translate()
  563. {
  564. //获取超时订单
  565. $out_time = TIMESTAMP - (60 * 60 * 24);
  566. $order_list = Db::name('order')
  567. ->where('order_state', 20)
  568. ->where('payment_time', '<', $out_time)
  569. ->where('timeout_no_translate_message', 0)
  570. ->select();
  571. //获取店铺信息
  572. $store_ids = [];
  573. foreach ($order_list as $v) {
  574. $store_ids[] = $v['store_id'];
  575. }
  576. $store_list = Db::name('store')->where('store_id', 'in', $store_ids)->column('store_phone', 'store_id');
  577. //发送短信
  578. $smslog_model = model('smslog');
  579. $storemsg_model = model('storemsg');
  580. foreach ($order_list as $v) {
  581. $store_phone = $store_list[$v['store_id']];
  582. if (!empty($store_phone)) {
  583. $smslog_model->sendSms($store_phone, ['message' => '福利商城有订单已超过24小时未发货,订单号:' . $v['order_sn'] . '请及时发货']);
  584. }
  585. Db::name('order')->where('order_id', $v['order_id'])->update(['timeout_no_translate_message' => 1]);
  586. $storemsg_model->addStoremsg([
  587. 'storemt_code' => 'timeout_no_translate',
  588. 'store_id' => $v['store_id'],
  589. 'storemsg_content' => '福利商城有订单已超过24小时未发货,订单号:' . $v['order_sn'] . '请及时发货',
  590. ]);
  591. }
  592. }
  593. }
  594. ?>