Note.php 4.0 KB

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