123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace app\Nutrition\controller;
- use library\Controller;
- use think\Db;
- /**
- * 资讯商品
- * Class InformationGoods
- * @package app\Nutrition\controller
- */
- class InformationGoods extends Controller
- {
- /**
- * 绑定数据表
- * @var string
- */
- protected $table = 'InformationGoods';
- /**
- * 列表
- * @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()
- {
- $lid = input('id');
- $search_name = input('search_name','');
- $information_info = Db::name('information_article')->find($lid);
- $this->title = $information_info['title'];
- $this->lid = $lid;
- $where = [];
- $where[]= ['v.news_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('InformationGoods')->where('news_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('InformationArticle')->find($lid);
- $this->title = $live_info['title'];
- $this->lid = $lid;
- $name = input('name');
- $sel_ids = Db::name('InformationGoods')->where(['news_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');
- $news_id = input('post.news_id');
- foreach ($sel_goods as $goods_id){
- $int_data[]=[
- 'news_id' => $news_id,
- 'goods_id' => $goods_id,
- 'sort' => 0,
- 'create_at' => date("Y-m-d H:i:s")
- ];
- }
- Db::name('InformationGoods')->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){
- }
- }
|