Cron.php 6.9 KB

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