123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace Act\Lib;
- use Dever;
- class Note
- {
- # 获取当前用户是否预约
- public function get($uid, $id, $type)
- {
- $where['uid'] = $uid;
- $where['type'] = $type;
- $where['data_id'] = $id;
- $where['state'] = 1;
- $info = Dever::db('act/live_note')->one($where);
- if ($info && $info['state'] == 1) {
- return 1;
- } else {
- return 2;
- }
- }
- # 预约
- public function submit($uid, $id, $type, $formid = '', $system = 1)
- {
- if ($formid) {
- Dever::load('act/lib/form')->submit($uid, $formid, 1, $system);
- }
- $where['uid'] = $uid;
- $where['data_id'] = $id;
- $where['type'] = $type;
- $where['cate_id'] = $system;
- $info = Dever::db('act/live_note')->one($where);
- if (!$info) {
- if ($formid) {
- $where['formid'] = $formid;
- }
-
- Dever::db('act/live_note')->insert($where);
- } else {
- $update['cate_id'] = $system;
- $update['where_id'] = $info['id'];
- if ($formid) {
- $update['formid'] = $formid;
- }
- $update['cdate'] = time();
- if ($info['state'] == 1) {
- $update['state'] = 2;
- Dever::db('act/live_note')->update($update);
- } else {
- $update['state'] = 1;
- Dever::db('act/live_note')->update($update);
- }
- }
- return true;
- }
- # 提醒 后续实现 需要加入到cron里:act/lib/note.cron
- public function cron()
- {
- $data = Dever::db('act/live_note')->getAll();
- if ($data) {
- $time = time();
- $day = 7 * 86400;
- $date = 300;
- foreach ($data as $k => $v) {
- $table = Dever::config('base')->type_table[$v['type']];
- $info = Dever::db($table)->one($v['id']);
- if ($info && $v['type'] == 3 && isset($info['sdate']) && $info['sdate'] > 0 && $info['sdate'] > $time && $info['sdate'] - $time <= $date) {
- $user = Dever::db('passport/user')->one($v['uid']);
- if (!$user) {
- continue;
- }
- Dever::db('act/live_note')->update(array('where_id' => $v['id'], 'note' => 2));
- if (Dever::project('message')) {
- Dever::load('message/lib/data')->push(-1, $v['uid'], '直播提醒', $info['name'] . '直播即将开始,马上观看!', 11, $v['cate_id']);
- }
-
- # 发送短消息
- if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
- $send = array();
- $send['name'] = $info['name'];
- Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
- }
- //$formid = Dever::load('act/lib/form')->get($v['uid'], 1);
- $formid = $v['formid'];
- if ($formid) {
- # 发送模板消息
- $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'] = 'note_live';
- $send['project_id'] = $v['cate_id'];
- $send['touser'] = $wechat['openid'];
- $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . $v['type'] . ',' . $v['id'];
- $send['data'] = array
- (
- 'keyword1' => array('value' => $info['name']),
- 'keyword2' => array('value' => $info['name'] . '直播即将开始,马上观看!'),
- );
- $send['data'] = json_encode($send['data']);
- $send['form_id'] = $formid;
- Dever::load('wechat_applet/msg.send', $send);
- }
- }
- }
- }
- }
- return 'ok';
- }
- public function cron_api()
- {
-
- }
- }
|