123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- <?php
- namespace app\store\controller;
- use library\Controller;
- use library\helper\PageHelper;
- use think\Db;
- /**
- * 直播管理
- * Class Live
- * @package app\store\controller
- */
- class Live extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'StoreLive';
- public function initialize(){
- $date_str = date("Y-m-d H:i:s");
- // 将活动改为进行中状态
- Db::table('store_live')->where([['start_at','< time',$date_str],['status','=',2]])->update(['status'=>1]);
- }
- /**
- * 直播列表
- * @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 = '直播列表';
- $query = $this->_query($this->table)->where('is_deleted',0)->like('name');
- $query->dateBetween('create_at')->order('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)
- {
- }
- /**
- * 添加直播
- * @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 add()
- {
- $this->title = '添加直播';
- $this->_form($this->table, 'form');
- }
- /**
- * 编辑直播
- * @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
- */
- function edit()
- {
- $this->title = '编辑直播';
- $this->_form($this->table, 'form');
- }
- /**
- * 表单数据处理
- * @auth true
- * @menu true
- * @param array $data
- */
- protected function _form_filter(&$data)
- {
- if($this->request->isGet()){
- if($this->request->action() == 'edit') {
- if($data['detail']) $data['detail'] = json_decode($data['detail'],true);
- }
- }
- // 添加或编辑直播
- if ($this->request->isPost()) {
- }
- }
- /**
- * 表单结果处理
- * @param boolean $result
- */
- protected function _form_result($result)
- {
- }
- /**
- * @auth true
- * @menu true
- * 直播上架
- */
- public function up()
- {
- $this->_save($this->table, ['status' => '1']);
- }
- /**
- * @auth true
- * @menu true
- * 直播下架
- */
- public function down()
- {
- $this->_save($this->table, ['status' => '0']);
- }
- /**
- * @auth true
- * @menu true
- * 直播下架
- */
- public function del()
- {
- $this->_save($this->table, ['is_deleted' => '1']);
- }
- /**
- * @auth true
- * @menu true
- * 删除直播商品
- */
- public function del_goods()
- {
- $id = input('id');
- Db::table('store_live_goods')->where('id',$id)->delete();
- return json_encode(['info'=>'删除成功']);
- }
- /**
- * @auth true
- * @menu true
- * 直播下架
- */
- public function close()
- {
- $this->_save($this->table, ['status' => '3','end_at'=>date('Y-m-d H:i:s')]);
- }
- public function upload(){
- if(!in_array($_FILES["file"]["type"],['image/png','image/jpeg','image/jpeg'])) echo '图片类型不支持';
- if($_FILES["file"]["size"] > 50000000) echo '图片大小最大50M';
- if ($_FILES["file"]["error"] > 0) echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
- // $dir = env('root_path') . 'public/static/pic';
- $dir = $_SERVER['DOCUMENT_ROOT']. '/static/pic';
- /* var_dump($dir);
- if(!is_dir($dir)) {
- var_dump(mkdir($dir));
- }*/
- move_uploaded_file($_FILES["file"]["tmp_name"], $dir."/" . $_FILES["file"]["name"]);
- echo $dir."/" . $_FILES["file"]["name"];
- }
- /**
- * @auth true
- * @menu true
- * 直播商品
- */
- public function live_goods()
- {
- $lid = input('id');
- $cate_id = input('cate_id',0);
- $search_name = input('search_name','');
- $live_info = Db::table('store_live')->find($lid);
- $this->title = $live_info['name'];
- $goods_cate = Db::table('store_live_cate')
- ->field('id,title')
- ->where('status',1)
- ->where('is_deleted',0)
- ->order('sort desc , id desc')
- ->select();
- $this->goods_cate = array_column($goods_cate,null,'id');
- $this->lid = $lid;
- $where = [];
- $where[]= ['l.live_id','=',$lid];
- if($search_name) $where[] = ['g.name','like',"%".$search_name."%"];
- if($cate_id) $where[] = ['l.cate_id','=',$cate_id];
- $this->assign('cate_id',$cate_id);
- $list = $this->_query('StoreLiveGoods')
- ->alias('l')
- ->field('l.*,name as goods_name,cover,title')
- ->where($where)
- ->join('live_goods_list g','l.goods_id = g.id','LEFT')
- ->join('store_live_cate c','c.id = l.cate_id','LEFT')
- ->order('l.sort desc ,l.id desc')->page();
- }
- /**
- * @auth true
- * @menu true
- * 已添加直播商品列表
- */
- public function add_goods()
- {
- $lid = input('id');
- $cate_id = input('cate_id',0);
- $live_info = Db::table('store_live')->find($lid);
- $this->title = $live_info['name'];
- $goods_cate = Db::table('store_live_cate')
- ->field('id,title')
- ->where('status',1)
- ->where('is_deleted',0)
- ->order('sort desc , id desc')
- ->select();
- $this->goods_cate = array_column($goods_cate,null,'id');
- $this->lid = $lid;
- $sel_goods = Db::table('store_live_goods')->field('goods_id')->where(['live_id'=>$lid])->select();
- $sel_ids = array_column($sel_goods,'goods_id');
- $where = [];
- $where[]= ['is_deleted','=',0];
- $where[]= ['status','=',1];
- if(!empty($sel_ids)) $where[] = ['id','not in',$sel_ids];
- if($cate_id) $where[] = ['cate_id','=',$cate_id];
- $this->assign('cate_id',$cate_id);
- $list = $this->_query('LiveGoodsList')
- ->where($where)
- ->order('sort desc ,id desc')->page();
- return $this->fetch('add_goods');
- }
- /**
- * @auth true
- * @menu true
- * 添加直播商品
- */
- public function ajax_add()
- {
- $sel_goods = input('post.ids');
- $live_id = input('post.live_id');
- $good_arr = Db::table('live_goods_list')
- ->field('id,cate_id,sort')
- ->where(['id'=>$sel_goods])
- ->select();
- $cal_data = array_column($good_arr,null,'id');
- $int_data = [];
- foreach ($sel_goods as $goods_id){
- $int_data[]=[
- 'live_id' => $live_id,
- 'goods_id' => $goods_id,
- 'cate_id' => $cal_data[$goods_id]['cate_id'],
- 'sort' => $cal_data[$goods_id]['sort'],
- 'create_at' => date("Y-m-d H:i:s")
- ];
- }
- Db::table('store_live_goods')->insertAll($int_data);
- return json_encode(['code'=>200]);
- }
- }
|