123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace app\store\controller;
- use library\Controller;
- use think\Db;
- /**
- * 直播预约
- * Class LiveAppointment
- * @package app\store\controller
- */
- class LiveAppointment extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'LiveGoodsApp';
- /**
- * 预约列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->title = '预约列表';
- $live_id = input('id');
- $goods_id = input('goods_id',0);
- $search_name = input('search_name','');
- $where= [];
- if($this->request->request('live_name')) $where[]= ['l.name','=',$this->request->request('live_name')];
- if($this->request->request('live_time')){
- $live_time = $this->request->request('live_time');
- $where[]= ['start_at','between time',[$live_time.' 00:00:00',$live_time.' 23:59:59']];
- }
- if($live_id) $where[] = ['live_id','=',$live_id];
- if($goods_id) $where[] = ['goods_id','=',$goods_id];
- if($search_name) $where[] = ['g.name','like',"%".$search_name."%"];
- $this->goods_id = $goods_id;
- $this->live_id = $live_id;
- $this->live_status = Db::table('store_live')->where('id',$live_id)->value('status');
- // 预约总数量
- $app_nums = Db::table('live_goods_app')->where(['live_id'=>$live_id])->count();
- //直播商品
- $all_goods = Db::table('store_live_goods')
- ->alias('l')
- ->field('l.goods_id,g.name')
- ->join('live_goods_list g',' g.id = l.goods_id ','LEFT')
- ->order('l.sort desc ,l.id desc')
- ->where(['live_id'=>$live_id])
- ->select();
- $live_goods = ['0'=>'全部'];
- array_map(function ($v)use (&$live_goods,$live_id,$app_nums){
- $goods_app = Db::table('live_goods_app')
- ->where(['live_id'=>$live_id,'goods_id'=>$v['goods_id']])
- ->count();
- $rete = $app_nums > 0 && $goods_app > 0 ? bcdiv($goods_app,$app_nums,4) * 100 : 0;
- $live_goods[$v['goods_id']] = $v['name']. ' ---- ' . $rete .'%';
- },$all_goods);
- $this->live_goods = $live_goods;
- $query = $this->_query($this->table)->alias('a')
- ->field('a.*,m.name as user_name,l.name as live_name,g.name as goods_name,g.cover,l.start_at')
- ->join('store_live l',' l.id = a.live_id ','LEFT')
- ->join('store_member m',' m.id = a.user_id ','LEFT')
- ->join('live_goods_list g',' g.id = a.goods_id ','LEFT')
- ->like('a.name');
- if(!empty($where)) $query->where($where);
- $query->order('a.id desc')->page();
- }
- /**
- * 数据列表处理
- * @auth true
- * @menu true
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(&$data)
- {
- }
- public function send_msg()
- {
- $live_id = input('live_id');
- $goods_id = input('goods_id');
- $user_app = Db::table('live_goods_app')
- ->alias('a')
- ->field('a.id,a.user_id, m.openid,m.name')
- ->join('store_member m' , 'a.user_id = m.id','LEFT')
- ->where(['a.live_id'=>$live_id,'a.goods_id'=>$goods_id,'is_remind'=>0])
- ->select();
- if(empty($user_app)){
- echo json_encode(['code'=>201,'msg'=>'暂无需要提醒的预约!']);die();
- }
- $good_info = Db::table('live_goods_list')->find($goods_id);
- $st_time = Db::table('store_live')->where('id',$live_id)->value('start_at');
- // 发消息
- $jump_url = Db::table('platform_set')->where(['name'=>'push_link'])->value('content');
- $access_token = get_access_token();
- foreach ($user_app as $uv) {
- $data=[
- '姐妹们,你预约的商品马上开播咯!',
- $uv['name'],
- $good_info['name'],
- $st_time,
- '快来【樊樊直播间】抢购吧!Get超多直播福利!',
- ];
- $send_res = send_message($access_token,$uv['openid'],$jump_url,$data);
- }
- // 更新提醒状态
- Db::table('live_goods_app')->where(['live_id'=>$live_id,'goods_id'=>$goods_id,'is_remind'=>0])->update(['is_remind'=>1]);
- echo json_encode(['code'=>200,'msg'=>'发送成功']);
- }
- }
|