LiveAppointment.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace app\store\controller;
  3. use library\Controller;
  4. use think\Db;
  5. /**
  6. * 直播预约
  7. * Class LiveAppointment
  8. * @package app\store\controller
  9. */
  10. class LiveAppointment extends Controller
  11. {
  12. /**
  13. * 绑定数据表
  14. * @var string
  15. */
  16. protected $table = 'LiveGoodsApp';
  17. /**
  18. * 预约列表
  19. * @auth true
  20. * @menu true
  21. * @throws \think\Exception
  22. * @throws \think\db\exception\DataNotFoundException
  23. * @throws \think\db\exception\ModelNotFoundException
  24. * @throws \think\exception\DbException
  25. * @throws \think\exception\PDOException
  26. */
  27. public function index()
  28. {
  29. $this->title = '预约列表';
  30. $live_id = input('id');
  31. $goods_id = input('goods_id',0);
  32. $where= [];
  33. if($this->request->request('live_name')) $where[]= ['l.name','=',$this->request->request('live_name')];
  34. if($this->request->request('live_time')){
  35. $live_time = $this->request->request('live_time');
  36. $where[]= ['start_at','between time',[$live_time.' 00:00:00',$live_time.' 23:59:59']];
  37. }
  38. if($live_id) $where[] = ['live_id','=',$live_id];
  39. if($goods_id) $where[] = ['goods_id','=',$goods_id];
  40. $this->goods_id = $goods_id;
  41. $this->live_id = $live_id;
  42. $this->live_status = Db::table('store_live')->where('id',$live_id)->value('status');
  43. //直播商品
  44. $all_goods = Db::table('store_live_goods')
  45. ->alias('l')
  46. ->field('l.goods_id,g.name')
  47. ->join('live_goods_list g',' g.id = l.goods_id ','LEFT')
  48. ->order('l.sort desc ,l.id desc')
  49. ->where(['live_id'=>$live_id])
  50. ->select();
  51. $live_goods = ['0'=>'全部'];
  52. array_map(function ($v)use (&$live_goods){
  53. $live_goods[$v['goods_id']] = $v['name'];
  54. },$all_goods);
  55. $this->live_goods = $live_goods;
  56. $query = $this->_query($this->table)->alias('a')
  57. ->field('a.*,m.name as user_name,l.name as live_name,g.name as goods_name,g.cover,l.start_at')
  58. ->join('store_live l',' l.id = a.live_id ','LEFT')
  59. ->join('store_member m',' m.id = a.user_id ','LEFT')
  60. ->join('live_goods_list g',' g.id = a.goods_id ','LEFT')
  61. ->like('a.name');
  62. if(!empty($where)) $query->where($where);
  63. $query->order('a.id desc')->page();
  64. }
  65. /**
  66. * 数据列表处理
  67. * @auth true
  68. * @menu true
  69. * @param array $data
  70. * @throws \think\db\exception\DataNotFoundException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. * @throws \think\exception\DbException
  73. */
  74. protected function _index_page_filter(&$data)
  75. {
  76. }
  77. public function send_msg()
  78. {
  79. $live_id = input('live_id');
  80. $goods_id = input('goods_id');
  81. $user_app = Db::table('live_goods_app')
  82. ->alias('a')
  83. ->field('a.id,a.user_id, m.openid,m.name')
  84. ->join('store_member m' , 'a.user_id = m.id','LEFT')
  85. ->where(['a.live_id'=>$live_id,'a.goods_id'=>$goods_id,'is_remind'=>0])
  86. ->select();
  87. if(empty($user_app)){
  88. echo json_encode(['code'=>201,'msg'=>'暂无需要提醒的预约!']);die();
  89. }
  90. $good_info = Db::table('live_goods_list')->find($goods_id);
  91. $st_time = Db::table('store_live')->where('id',$live_id)->value('start_at');
  92. // 发消息
  93. $jump_url = Db::table('platform_set')->where(['name'=>'push_link'])->value('content');
  94. $access_token = get_access_token();
  95. foreach ($user_app as $uv) {
  96. $data=[
  97. '姐妹们,你预约的商品马上开播咯!',
  98. $uv['name'],
  99. $good_info['name'],
  100. $st_time,
  101. '快来【樊樊直播间】抢购吧!Get超多直播福利!',
  102. ];
  103. $send_res = send_message($access_token,$uv['openid'],$jump_url,$data);
  104. }
  105. // 更新提醒状态
  106. Db::table('live_goods_app')->where(['live_id'=>$live_id,'goods_id'=>$goods_id,'is_remind'=>0])->update(['is_remind'=>1]);
  107. echo json_encode(['code'=>200,'msg'=>'发送成功']);
  108. }
  109. }