LiveAppointment.php 4.7 KB

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