Cron.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace Main\Lib;
  3. use Dever;
  4. class Cron
  5. {
  6. public function unpay_api()
  7. {}
  8. public function activeEnd_api()
  9. {}
  10. #用户未支付电子刊情况下,未支付订单超过2小时后,发送一次唤回支付提醒
  11. public function unpay()
  12. {
  13. $time = 7200;
  14. $where['cdate'] = time() + $time;
  15. $where['note'] = 1;
  16. $where['type'] = '1,3';
  17. $data = Dever::db('journal/order')->getDataByTime($where);
  18. if ($data) {
  19. foreach ($data as $k => $v) {
  20. $user = Dever::db('passport/user')->one($v['uid']);
  21. if (!$user) {
  22. continue;
  23. }
  24. Dever::db('journal/order')->update(array('where_id' => $v['id'], 'note' => 2));
  25. $journal = Dever::db('journal/info')->one($v['product_id']);
  26. if (Dever::project('message')) {
  27. Dever::load('message/lib/data')->push(-1, $v['uid'], '支付提醒', '您订阅的'.$journal['name'].'尚未支付!', 11, $v['cate_id'], 1, Dever::load('act/lib/note')->push(4, $journal['id'], $journal['name']));
  28. }
  29. # 发送短消息
  30. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
  31. $send = array();
  32. $send['name'] = $journal['name'];
  33. //Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
  34. }
  35. # 发模板消息
  36. $wechat = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'type' => 1, 'system_id' => $v['cate_id']));
  37. if ($wechat && Dever::project('wechat_applet')) {
  38. $send['key'] = 'unbuy_journal';
  39. $send['project_id'] = $v['cate_id'];
  40. $send['touser'] = $wechat['openid'];
  41. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . '4,' . $v['product_id'];
  42. $send['data'] = array
  43. (
  44. 'keyword1' => array('value' => $journal['name']),
  45. 'keyword2' => array('value' => $v['cash']),
  46. 'keyword3' => array('value' => '您订阅的'.$journal['name'].'尚未支付!'),
  47. );
  48. $send['data'] = json_encode($send['data']);
  49. $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 2, $v['cate_id']);
  50. if ($send['form_id']) {
  51. Dever::load('wechat_applet/msg.send', $send);
  52. }
  53. }
  54. }
  55. }
  56. return 'ok';
  57. }
  58. #电子杂志活动结束前5个时,向己有电子刊阅读权限的用户发送活动结束提醒
  59. public function activeEnd()
  60. {
  61. $time = 5*3600;
  62. $where['end'] = time() + $time;
  63. $data = Dever::db('journal/active')->getDataByTime($where);
  64. $test = Dever::input('test');
  65. if ($test == 1) {
  66. print_r($data);die;
  67. }
  68. if ($data) {
  69. foreach ($data as $ks => $vs) {
  70. $journal = Dever::db('journal/info')->one($vs['info_id']);
  71. $subscribe = Dever::db('act/subscribe')->state(array('note' => 1, 'type' => 4, 'data_id' => $vs['info_id']));
  72. if ($subscribe) {
  73. foreach ($subscribe as $k => $v) {
  74. $user = Dever::db('passport/user')->one($v['uid']);
  75. if (!$user) {
  76. continue;
  77. }
  78. Dever::db('act/subscribe')->update(array('where_id' => $v['id'], 'note' => 2));
  79. if (Dever::project('message')) {
  80. Dever::load('message/lib/data')->push(-1, $v['uid'], '活动结束提醒', '您参与的'.$journal['name'].'积分排行榜活动还有5小时就要结束了,想要冲榜赢奖品的要抓紧机会呀〜', 11, $journal['cate_id'], 1, Dever::load('act/lib/note')->push(4, $journal['id'], $journal['name']));
  81. }
  82. # 发送短消息
  83. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
  84. $send = array();
  85. $send['name'] = $journal['name'];
  86. //Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
  87. }
  88. # 发模板消息
  89. $wechat = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'type' => 1, 'system_id' => $journal['cate_id']));
  90. if ($wechat && Dever::project('wechat_applet')) {
  91. $send['key'] = 'service_end_note';
  92. $send['project_id'] = $journal['cate_id'];
  93. $send['touser'] = $wechat['openid'];
  94. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . '4,' . $journal['id'];
  95. $send['data'] = array
  96. (
  97. 'keyword1' => array('value' => $journal['name']),
  98. 'keyword2' => array('value' => date('Y-m-d H:i', $vs['end'])),
  99. 'keyword3' => array('value' => '您参与的'.$journal['name'].'积分排行榜活动还有5小时就要结束了,想要冲榜赢奖品的要抓紧机会呀~'),
  100. );
  101. $send['data'] = json_encode($send['data']);
  102. $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 1, $journal['cate_id']);
  103. if (!$send['form_id']) {
  104. $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 2, $journal['cate_id']);
  105. }
  106. if ($send['form_id']) {
  107. Dever::load('wechat_applet/msg.send', $send);
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. return 'ok';
  115. }
  116. }