Cron.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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['ends'] = time();
  63. $where['end'] = $where['ends'] + $time;
  64. $data = Dever::db('journal/active')->getDataByTime($where);
  65. //echo Dever::sql();die;
  66. $test = Dever::input('test');
  67. if ($test == 1) {
  68. print_r($data);die;
  69. }
  70. if ($data) {
  71. foreach ($data as $ks => $vs) {
  72. $journal = Dever::db('journal/info')->one($vs['info_id']);
  73. $subscribe = Dever::db('act/subscribe')->state(array('note' => 1, 'type' => 4, 'data_id' => $vs['info_id']));
  74. if ($subscribe) {
  75. foreach ($subscribe as $k => $v) {
  76. $user = Dever::db('passport/user')->one($v['uid']);
  77. if (!$user) {
  78. continue 2;
  79. }
  80. Dever::db('act/subscribe')->update(array('where_id' => $v['id'], 'note' => 2));
  81. if (Dever::project('message')) {
  82. 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']));
  83. }
  84. # 发送短消息
  85. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
  86. $send = array();
  87. $send['name'] = $journal['name'];
  88. //Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
  89. }
  90. # 发模板消息
  91. $wechat = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'type' => 1, 'system_id' => $journal['cate_id']));
  92. if ($wechat && Dever::project('wechat_applet')) {
  93. $send['key'] = 'service_end_note';
  94. $send['project_id'] = $journal['cate_id'];
  95. $send['touser'] = $wechat['openid'];
  96. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . '4,' . $journal['id'];
  97. $send['data'] = array
  98. (
  99. 'keyword1' => array('value' => $journal['name']),
  100. 'keyword2' => array('value' => date('Y-m-d H:i', $vs['end'])),
  101. 'keyword3' => array('value' => '您参与的'.$journal['name'].'积分排行榜活动还有5小时就要结束了,想要冲榜赢奖品的要抓紧机会呀~'),
  102. );
  103. $send['data'] = json_encode($send['data']);
  104. $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 1, $journal['cate_id']);
  105. if (!$send['form_id']) {
  106. $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 2, $journal['cate_id']);
  107. }
  108. if ($send['form_id']) {
  109. Dever::load('wechat_applet/msg.send', $send);
  110. }
  111. }
  112. }
  113. }
  114. }
  115. }
  116. return 'ok';
  117. }
  118. }