123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
- namespace Main\Lib;
- use Dever;
- class Cron
- {
- public function refund_api()
- {
- $order_id = Dever::input('order_id');
- if ($order_id) {
- $where['order_id'] = $order_id;
- }
- $where['product_id'] = 28;
- $where['status'] = 5;
- $where['refund_status'] = 1;
- $data = Dever::db('journal/order')->state($where);
- $test = Dever::input('test');
- if ($test == 1) {
- print_r($data);die;
- }
- if ($data) {
- foreach ($data as $k => $v) {
- $this->refundScore($v);
- }
- }
- }
- private function refundScore($data)
- {
- $score = 0;
- if ($data['cash'] == 6) {
- $score = 20;
- }
- if ($data['cash'] == 60) {
- $score = 20*10;
- }
- if ($data['cash'] == 588) {
- $score = 20*100;
- }
- if ($data['cash'] == 1728) {
- $score = 20*300;
- }
- if ($data['cash'] == 3348) {
- $score = 20*600;
- }
- if ($score > 0) {
- $where['uid'] = $v['uid'];
- $user = Dever::db('score/user')->one($where);
- if ($user) {
- $user_score = $user['score'] - $score;
- if ($user_score < 0) {
- $user_score = 0;
- }
- Dever::db('score/user')->update(array('where_id' => $user['id'], 'score' => $user_score));
- }
- $where['type'] = 4;
- $where['data_id'] = 28;
- $user = Dever::db('act/score')->one($where);
- if ($user) {
- $user_score = $user['score'] - $score;
- if ($user_score < 0) {
- $user_score = 0;
- }
- Dever::db('act/score')->update(array('where_id' => $user['id'], 'score' => $user_score));
- }
- Dever::db('journal/order')->update(array('where_id' => $data['id'], 'refund_status' => 2));
- }
- print_r($data);
- print_r($score);
- echo "\r\n";
- return $score;
- }
- public function pays_api()
- {
- $where['product_id'] = 28;
- $where['type'] = 3;
- $where['status'] = 1;
- $where['cron_status'] = 1;
- $data = Dever::db('journal/order')->state($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $this->getpays($v['order_id']);
- Dever::db('journal/order')->update(array('where_id' => $v['id'], 'cron_status' => 2));
- }
- }
- }
- private function getpays($order_id)
- {
- $url = 'http://mapi.jstyle.cn/pay/pay/?api.search&order_id='.$order_id.'&account_id=1';
- Dever::curl($url);
- }
- public function unpay_api()
- {}
- public function activeEnd_api()
- {}
- #用户未支付电子刊情况下,未支付订单超过2小时后,发送一次唤回支付提醒
- public function unpay()
- {
- $time = 7200;
- $where['cdate'] = time() + $time;
- $where['note'] = 1;
- $where['type'] = '1,3';
- $data = Dever::db('journal/order')->getDataByTime($where);
- if ($data) {
- foreach ($data as $k => $v) {
- $user = Dever::db('passport/user')->one($v['uid']);
- if (!$user) {
- continue;
- }
- Dever::db('journal/order')->update(array('where_id' => $v['id'], 'note' => 2));
- $journal = Dever::db('journal/info')->one($v['product_id']);
- if (Dever::project('message')) {
- 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']));
- }
-
- # 发送短消息
- if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
- $send = array();
- $send['name'] = $journal['name'];
- //Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
- }
- # 发模板消息
- $wechat = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'type' => 1, 'system_id' => $v['cate_id']));
- if ($wechat && Dever::project('wechat_applet')) {
- $send['key'] = 'unbuy_journal';
- $send['project_id'] = $v['cate_id'];
- $send['touser'] = $wechat['openid'];
- $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . '4,' . $v['product_id'];
- $send['data'] = array
- (
- 'keyword1' => array('value' => $journal['name']),
- 'keyword2' => array('value' => $v['cash']),
- 'keyword3' => array('value' => '您订阅的'.$journal['name'].'尚未支付!'),
- );
- $send['data'] = json_encode($send['data']);
- $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 2, $v['cate_id']);
- if ($send['form_id']) {
- Dever::load('wechat_applet/msg.send', $send);
- }
- }
- }
- }
- return 'ok';
- }
- #电子杂志活动结束前5个时,向己有电子刊阅读权限的用户发送活动结束提醒
- public function activeEnd()
- {
- $time = 5*3600;
- $where['ends'] = time();
- $where['end'] = $where['ends'] + $time;
- $data = Dever::db('journal/active')->getDataByTime($where);
- //echo Dever::sql();die;
- $test = Dever::input('test');
- if ($test == 1) {
- print_r($data);die;
- }
- if ($data) {
- foreach ($data as $ks => $vs) {
- $journal = Dever::db('journal/info')->one($vs['info_id']);
- $subscribe = Dever::db('act/subscribe')->state(array('note' => 1, 'type' => 4, 'data_id' => $vs['info_id']));
- if ($subscribe) {
- foreach ($subscribe as $k => $v) {
- $user = Dever::db('passport/user')->one($v['uid']);
- if ($user) {
- Dever::db('act/subscribe')->update(array('where_id' => $v['id'], 'note' => 2));
- if (Dever::project('message')) {
- 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']));
- }
-
- # 发送短消息
- if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
- $send = array();
- $send['name'] = $journal['name'];
- //Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
- }
- # 发模板消息
- $wechat = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'type' => 1, 'system_id' => $journal['cate_id']));
- if ($wechat && Dever::project('wechat_applet')) {
- $send['key'] = 'service_end_note';
- $send['project_id'] = $journal['cate_id'];
- $send['touser'] = $wechat['openid'];
- $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . '4,' . $journal['id'];
- $send['data'] = array
- (
- 'keyword1' => array('value' => $journal['name']),
- 'keyword2' => array('value' => date('Y-m-d H:i', $vs['end'])),
- 'keyword3' => array('value' => '您参与的'.$journal['name'].'积分排行榜活动还有5小时就要结束了,想要冲榜赢奖品的要抓紧机会呀~'),
- );
- $send['data'] = json_encode($send['data']);
- $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 1, $journal['cate_id']);
- if (!$send['form_id']) {
- $send['form_id'] = Dever::load('act/lib/form')->get($v['uid'], 2, $journal['cate_id']);
- }
- if ($send['form_id']) {
- Dever::load('wechat_applet/msg.send', $send);
- }
- }
- }
- }
- }
- }
- }
- return 'ok';
- }
- }
|