LiveAppointment.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. //直播商品
  43. $all_goods = Db::table('store_live_goods')
  44. ->alias('l')
  45. ->field('l.goods_id,g.name')
  46. ->join('live_goods_list g',' g.id = l.goods_id ','LEFT')
  47. ->order('l.sort desc ,l.id desc')
  48. ->where(['live_id'=>$live_id])
  49. ->select();
  50. $live_goods = ['0'=>'全部'];
  51. array_map(function ($v)use (&$live_goods){
  52. $live_goods[$v['goods_id']] = $v['name'];
  53. },$all_goods);
  54. $this->live_goods = $live_goods;
  55. $query = $this->_query($this->table)->alias('a')
  56. ->field('a.*,m.name as user_name,l.name as live_name,g.name as goods_name,g.cover,l.start_at')
  57. ->join('store_live l',' l.id = a.live_id ','LEFT')
  58. ->join('store_member m',' m.id = a.user_id ','LEFT')
  59. ->join('live_goods_list g',' g.id = a.goods_id ','LEFT')
  60. ->like('a.name');
  61. if(!empty($where)) $query->where($where);
  62. $query->order('a.id desc')->page();
  63. }
  64. /**
  65. * 数据列表处理
  66. * @auth true
  67. * @menu true
  68. * @param array $data
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. * @throws \think\exception\DbException
  72. */
  73. protected function _index_page_filter(&$data)
  74. {
  75. }
  76. public function send_msg()
  77. {
  78. $live_id = input('live_id');
  79. $goods_id = input('goods_id');
  80. $user_app = Db::table('live_goods_app')
  81. ->alias('a')
  82. ->field('a.id,a.user_id, m.openid,m.name')
  83. ->join('store_member m' , 'a.user_id = m.id','LEFT')
  84. ->where(['a.live_id'=>$live_id,'a.goods_id'=>$goods_id,'is_remind'=>0])
  85. ->select();
  86. if(empty($user_app)){
  87. echo json_encode(['code'=>201,'msg'=>'暂无需要提醒的预约!']);die();
  88. }
  89. $good_info = Db::table('live_goods_list')->find($goods_id);
  90. $st_time = Db::table('store_live')->where('id',$live_id)->value('start_at');
  91. // 发消息
  92. $jump_url = Db::table('platform_set')->where(['name'=>'push_link'])->value('content');
  93. $access_token = get_access_token();
  94. foreach ($user_app as $uv) {
  95. $data=[
  96. '姐妹们,你预约的商品马上开播咯!',
  97. $uv['name'],
  98. $good_info['name'],
  99. $st_time,
  100. '快来【樊樊直播间】抢购吧!Get超多直播福利!',
  101. ];
  102. $send_res = send_message($access_token,$uv['openid'],$jump_url,$data);
  103. }
  104. // 更新提醒状态
  105. Db::table('live_goods_app')->where(['live_id'=>$live_id,'goods_id'=>$goods_id,'is_remind'=>0])->update(['is_remind'=>1]);
  106. echo json_encode(['code'=>200,'msg'=>'发送成功']);
  107. }
  108. }