Note.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Note
  5. {
  6. # 获取message的push信息
  7. public function push($type, $id, $name, $link = '')
  8. {
  9. $param = array('type' => $type, 'id' => $id, 'name' => $name, 'link' => $link);
  10. $push = array(json_encode($param), 'jstyle://cn.jstyle.app/route?' . http_build_query($param));
  11. return $push;
  12. }
  13. # 获取当前用户是否预约
  14. public function get($uid, $id, $type)
  15. {
  16. $where['uid'] = $uid;
  17. $where['type'] = $type;
  18. $where['data_id'] = $id;
  19. $where['state'] = 1;
  20. $info = Dever::db('act/live_note')->one($where);
  21. if ($info && $info['state'] == 1) {
  22. return 1;
  23. } else {
  24. return 2;
  25. }
  26. }
  27. # 预约
  28. public function submit($uid, $id, $type, $formid = '', $system = 1)
  29. {
  30. if ($formid) {
  31. Dever::load('act/lib/form')->submit($uid, $formid, 1, $system);
  32. }
  33. $where['uid'] = $uid;
  34. $where['data_id'] = $id;
  35. $where['type'] = $type;
  36. $where['cate_id'] = $system;
  37. $info = Dever::db('act/live_note')->one($where);
  38. if (!$info) {
  39. if ($formid) {
  40. $where['formid'] = $formid;
  41. }
  42. Dever::db('act/live_note')->insert($where);
  43. } else {
  44. $update['cate_id'] = $system;
  45. $update['where_id'] = $info['id'];
  46. if ($formid) {
  47. $update['formid'] = $formid;
  48. }
  49. $update['cdate'] = time();
  50. if ($info['state'] == 1) {
  51. $update['state'] = 2;
  52. Dever::db('act/live_note')->update($update);
  53. } else {
  54. $update['state'] = 1;
  55. Dever::db('act/live_note')->update($update);
  56. }
  57. }
  58. return true;
  59. }
  60. # 提醒 后续实现 需要加入到cron里:act/lib/note.cron
  61. public function cron()
  62. {
  63. $data = Dever::db('act/live_note')->getAll();
  64. if ($data) {
  65. $time = time();
  66. $day = 7 * 86400;
  67. $date = 800;
  68. foreach ($data as $k => $v) {
  69. $table = Dever::config('base')->type_table[$v['type']];
  70. $info = Dever::db($table)->one($v['data_id']);
  71. if ($info && $v['type'] == 3 && isset($info['sdate']) && $info['sdate'] > 0 && $info['sdate'] > $time && $info['sdate'] - $time <= $date) {
  72. $user = Dever::db('passport/user')->one($v['uid']);
  73. if (!$user) {
  74. continue;
  75. }
  76. Dever::db('act/live_note')->update(array('where_id' => $v['id'], 'note' => 2));
  77. if (Dever::project('message')) {
  78. Dever::load('message/lib/data')->push(-1, $v['uid'], '直播提醒', $info['name'] . '直播即将开始,马上观看!', 11, $v['cate_id'], 1, Dever::load('act/lib/note')->push(3, $info['id'], $info['name']));
  79. }
  80. # 发送短消息
  81. if (isset($user['mobile']) && $user['mobile'] && Dever::project('sms')) {
  82. $send = array();
  83. $send['name'] = $info['name'];
  84. Dever::load('sms/api.send', 'note_live', $user['mobile'], $send);
  85. }
  86. //$formid = Dever::load('act/lib/form')->get($v['uid'], 1);
  87. $formid = $v['formid'];
  88. if ($formid) {
  89. # 发送模板消息
  90. $wechat = Dever::db('passport/wechat')->one(array('uid' => $v['uid'], 'type' => 1, 'system_id' => $v['cate_id']));
  91. if ($wechat && Dever::project('wechat_applet')) {
  92. $send['key'] = 'note_live';
  93. $send['project_id'] = $v['cate_id'];
  94. $send['touser'] = $wechat['openid'];
  95. $send['page'] = Dever::config('base')->applet_index . '?scene=' . Dever::login($v['uid']) . ',' . $v['type'] . ',' . $v['id'];
  96. $send['data'] = array
  97. (
  98. 'keyword1' => array('value' => $info['name']),
  99. 'keyword2' => array('value' => $info['name'] . '直播即将开始,马上观看!'),
  100. );
  101. $send['data'] = json_encode($send['data']);
  102. $send['form_id'] = $formid;
  103. Dever::load('wechat_applet/msg.send', $send);
  104. }
  105. }
  106. }
  107. }
  108. }
  109. return 'ok';
  110. }
  111. public function cron_api()
  112. {
  113. }
  114. }