find($lid); $this->title = $video_info['title']; $this->lid = $lid; $where = []; $where[]= ['v.video_id','=',$lid]; if($search_name) $where[] = ['g.name','like',"%".$search_name."%"]; $list = $this->_query($this->table)->alias('v') ->field('v.create_at,v.sort,v.id,v.goods_id,g.name as goods_name,g.cover,g.name,g.low_price,g.status,g.is_deleted') ->where($where) ->join('StoreGoods g','v.goods_id = g.id','LEFT') ->order('v.sort desc ,v.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) { foreach ($data as &$v){ $v['goods_num'] = Db::name('VideoGoods')->where('video_id',$v['id'])->count(); } } /** * 可添加商品列表 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function goods_list() { $lid = input('id'); $live_info = Db::name('VideoIntro')->find($lid); $this->title = $live_info['title']; $this->lid = $lid; $name = input('name'); $sel_ids = Db::name('VideoGoods')->where(['video_id'=>$lid])->column('goods_id'); $where = []; $where[]= ['is_deleted','=',0]; $where[]= ['status','=',1]; if(!empty($sel_ids)) $where[] = ['id','not in',$sel_ids]; if($name) $where[] = ['name','like','%'.$name.'%']; $list = $this->_query('StoreGoods') ->field('id,name,cover,low_price') ->where($where) ->order('sort desc ,id desc')->page(); return $this->fetch('goods_list'); } /** * ajax添加商品 * @auth true * @menu true * @param array $data * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function ajax_add() { $sel_goods = input('post.ids'); $video_id = input('post.video_id'); foreach ($sel_goods as $goods_id){ $int_data[]=[ 'video_id' => $video_id, 'goods_id' => $goods_id, 'sort' => 0, 'create_at' => date("Y-m-d H:i:s") ]; } Db::name('VideoGoods')->insertAll($int_data); return json_encode(['code'=>200]); } /** * 删除关联商品 * @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 del_goods() { $this->_delete($this->table); } /** * 表单数据处理 * @auth true * @menu true * @param array $data */ protected function _form_filter(&$data) { } protected function _form_result($result){ } }