Note.php 4.3 KB

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