Cron.php 9.2 KB

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