Cron.php 7.1 KB

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