VideoGoods.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace app\Nutrition\controller;
  3. use library\Controller;
  4. use think\Db;
  5. use app\common\model\VideoCate as VCM;
  6. /**
  7. * 视频商品
  8. * Class VideoGoods
  9. * @package app\Nutrition\controller
  10. */
  11. class VideoGoods extends Controller
  12. {
  13. /**
  14. * 绑定数据表
  15. * @var string
  16. */
  17. protected $table = 'VideoGoods';
  18. /**
  19. * 列表
  20. * @auth true
  21. * @menu true
  22. * @throws \think\Exception
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\ModelNotFoundException
  25. * @throws \think\exception\DbException
  26. * @throws \think\exception\PDOException
  27. */
  28. public function index()
  29. {
  30. $lid = input('id');
  31. $search_name = input('search_name','');
  32. $video_info = Db::name('video_intro')->find($lid);
  33. $this->title = $video_info['title'];
  34. $this->lid = $lid;
  35. $where = [];
  36. $where[]= ['v.video_id','=',$lid];
  37. if($search_name) $where[] = ['g.name','like',"%".$search_name."%"];
  38. $list = $this->_query($this->table)->alias('v')
  39. ->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')
  40. ->where($where)
  41. ->join('StoreGoods g','v.goods_id = g.id','LEFT')
  42. ->order('v.sort desc ,v.id desc')
  43. ->page();
  44. }
  45. /**
  46. * 数据列表处理
  47. * @auth true
  48. * @menu true
  49. * @param array $data
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. protected function _index_page_filter(&$data)
  55. {
  56. foreach ($data as &$v){
  57. $v['goods_num'] = Db::name('VideoGoods')->where('video_id',$v['id'])->count();
  58. }
  59. }
  60. /**
  61. * 可添加商品列表
  62. * @auth true
  63. * @menu true
  64. * @param array $data
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @throws \think\exception\DbException
  68. */
  69. public function goods_list()
  70. {
  71. $lid = input('id');
  72. $live_info = Db::name('VideoIntro')->find($lid);
  73. $this->title = $live_info['title'];
  74. $this->lid = $lid;
  75. $name = input('name');
  76. $sel_ids = Db::name('VideoGoods')->where(['video_id'=>$lid])->column('goods_id');
  77. $where = [];
  78. $where[]= ['is_deleted','=',0];
  79. $where[]= ['status','=',1];
  80. if(!empty($sel_ids)) $where[] = ['id','not in',$sel_ids];
  81. if($name) $where[] = ['name','like','%'.$name.'%'];
  82. $list = $this->_query('StoreGoods')
  83. ->field('id,name,cover,low_price')
  84. ->where($where)
  85. ->order('sort desc ,id desc')->page();
  86. return $this->fetch('goods_list');
  87. }
  88. /**
  89. * ajax添加商品
  90. * @auth true
  91. * @menu true
  92. * @param array $data
  93. * @throws \think\db\exception\DataNotFoundException
  94. * @throws \think\db\exception\ModelNotFoundException
  95. * @throws \think\exception\DbException
  96. */
  97. public function ajax_add()
  98. {
  99. $sel_goods = input('post.ids');
  100. $video_id = input('post.video_id');
  101. foreach ($sel_goods as $goods_id){
  102. $int_data[]=[
  103. 'video_id' => $video_id,
  104. 'goods_id' => $goods_id,
  105. 'sort' => 0,
  106. 'create_at' => date("Y-m-d H:i:s")
  107. ];
  108. }
  109. Db::name('VideoGoods')->insertAll($int_data);
  110. return json_encode(['code'=>200]);
  111. }
  112. /**
  113. * 删除关联商品
  114. * @auth true
  115. * @menu true
  116. * @throws \think\Exception
  117. * @throws \think\db\exception\DataNotFoundException
  118. * @throws \think\db\exception\ModelNotFoundException
  119. * @throws \think\exception\DbException
  120. * @throws \think\exception\PDOException
  121. */
  122. public function del_goods()
  123. {
  124. $this->_delete($this->table);
  125. }
  126. /**
  127. * 表单数据处理
  128. * @auth true
  129. * @menu true
  130. * @param array $data
  131. */
  132. protected function _form_filter(&$data)
  133. {
  134. }
  135. protected function _form_result($result){
  136. }
  137. }