SupplierGoods.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <?php
  2. namespace app\operate\controller;
  3. use app\common\model\DatumIntro;
  4. use app\common\model\PlatformSwitch;
  5. use app\common\model\User;
  6. use library\Controller;
  7. use think\Db;
  8. /**
  9. * 供货商商品
  10. * Class SupplierGoods
  11. * @package app\mall\controller
  12. */
  13. class SupplierGoods extends Controller
  14. {
  15. /**
  16. * 绑定数据表
  17. * @var string
  18. */
  19. protected $table = 'SupplierGoods';
  20. /**
  21. * 供货商商品列表
  22. * @auth true
  23. * @menu true
  24. * @throws \think\Exception
  25. * @throws \think\db\exception\DataNotFoundException
  26. * @throws \think\db\exception\ModelNotFoundException
  27. * @throws \think\exception\DbException
  28. * @throws \think\exception\PDOException
  29. */
  30. public function index()
  31. {
  32. $this->title = '供货商商品列表';
  33. $supplier_id = input('get.supplier_id');
  34. $name = input('get.name');
  35. $company_id = input('get.company_id');
  36. $third_classify = input('get.third_classify');
  37. $this->supplier_id = $supplier_id;
  38. $this->supplier_list = \app\common\model\Supplier::getSupplierName(0);
  39. //$this->company_list = \app\common\model\Company::getCompanyName();
  40. $where = [];
  41. $where[] = ['a.is_deleted','=',0];
  42. if($supplier_id)$where[] = ['a.supplier_id','=',$supplier_id];
  43. if($company_id)$where[] = ['a.company_id','=',$company_id];
  44. if($third_classify)$where[] = ['a.third_classify','=',$third_classify];
  45. if($name)$where[] = ['a.name','like','%'.$name.'%'];
  46. $query = $this->_query($this->table)->where($where)->like('a.name')->alias('a')->field('a.*,b.title supplier_name ,c.title company_name');
  47. $query->leftJoin('Supplier b','b.id = a.supplier_id')->leftJoin('Company c','c.id = a.company_id');
  48. $query->order(' a.sort desc , a.id desc')->page();
  49. }
  50. /**
  51. * 数据列表处理
  52. * @auth true
  53. * @menu true
  54. * @param array $data
  55. * @throws \think\db\exception\DataNotFoundException
  56. * @throws \think\db\exception\ModelNotFoundException
  57. * @throws \think\exception\DbException
  58. */
  59. protected function _index_page_filter(&$data)
  60. {
  61. }
  62. /**
  63. * 添加供货商商品
  64. * @auth true
  65. * @menu true
  66. * @throws \think\Exception
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\ModelNotFoundException
  69. * @throws \think\exception\DbException
  70. * @throws \think\exception\PDOException
  71. */
  72. public function add()
  73. {
  74. $this->title = '添加供货商商品';
  75. $this->supplier_id = input('supplier_id');
  76. $this->_form($this->table, 'form');
  77. }
  78. /**
  79. * 编辑供货商商品
  80. * @auth true
  81. * @menu true
  82. * @throws \think\Exception
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\ModelNotFoundException
  85. * @throws \think\exception\DbException
  86. * @throws \think\exception\PDOException
  87. */
  88. public function edit()
  89. {
  90. $this->title = '编辑供货商商品';
  91. $this->supplier_id = input('supplier_id');
  92. $this->_form($this->table, 'form');
  93. }
  94. /**
  95. * 启用
  96. * @auth true
  97. * @menu true
  98. * @throws \think\Exception
  99. * @throws \think\exception\PDOException
  100. */
  101. public function enable()
  102. {
  103. \app\common\model\SupplierGoods::where('id',input('id'))->update(['status'=>1]);
  104. \app\common\model\SupplierGoods::esAdd(input('id'));
  105. $this->success('已上架!');
  106. }
  107. /**
  108. * 禁用
  109. * @auth true
  110. * @menu true
  111. * @throws \think\Exception
  112. * @throws \think\db\exception\DataNotFoundException
  113. * @throws \think\db\exception\ModelNotFoundException
  114. * @throws \think\exception\DbException
  115. * @throws \think\exception\PDOException
  116. */
  117. public function forbidden()
  118. {
  119. \app\common\model\SupplierGoods::where('id',input('id'))->update(['status'=>0]);
  120. \app\common\model\SupplierGoods::esAdd(input('id'));
  121. $this->success('已下架!');
  122. }
  123. /**
  124. * 删除
  125. * @auth true
  126. * @menu true
  127. * @throws \think\Exception
  128. * @throws \think\exception\PDOException
  129. */
  130. public function del()
  131. {
  132. \app\common\model\SupplierGoods::where('id',input('id'))->update(['is_deleted'=>1]);
  133. \app\common\model\SupplierGoods::esAdd(input('id'));
  134. $this->success('已删除!');
  135. }
  136. /**
  137. * 删除
  138. * @auth true
  139. * @throws \think\Exception
  140. * @throws \think\exception\PDOException
  141. */
  142. public function remove()
  143. {
  144. $ids = input('id');
  145. foreach (explode(',',$ids) as $id) {
  146. \app\common\model\SupplierGoods::where('id',$id)->update(['is_deleted'=>1]);
  147. \app\common\model\SupplierGoods::esAdd($id);
  148. }
  149. $this->success('已删除!');
  150. }
  151. /**
  152. * 表单数据处理
  153. * @auth true
  154. * @menu true
  155. * @param array $data
  156. */
  157. protected function _form_filter(&$data)
  158. {
  159. if($this->request->isGet())
  160. {
  161. $third_classify = input('third_classify');
  162. if($third_classify) {
  163. if($third_classify) $data['third_classify'] = $third_classify;
  164. $third_info = \app\common\model\SupplierCate::where('id',$third_classify)->find()->toArray();
  165. if($third_classify) $data['second_classify'] = $third_info['pid'];
  166. $data['first_classify'] = \app\common\model\SupplierCate::where('id',$data['second_classify'])->value('pid');
  167. }
  168. $supplier_id = input('supplier_id');
  169. if($supplier_id) $data['supplier_id'] = $supplier_id;
  170. }
  171. // 视频
  172. $this->video_list = \app\common\model\VideoIntro::with('videoArr')
  173. ->where(['is_deleted'=>0])->order('id desc')
  174. ->select()->toArray();
  175. // 文章列表
  176. $this->article_list = \app\common\model\ArticleIntro::with('itemChildren')
  177. ->field('id,title')
  178. ->where(['is_deleted'=>0])->order('id desc')
  179. ->select()->toArray();
  180. // 资料
  181. $this->datum_list = DatumIntro::with('urlArr')
  182. ->where(['is_deleted'=>0])->order('id desc')
  183. ->select()->toArray();
  184. $data['create_at'] = date('Y-m-d H:i:s');
  185. $this->supplier_list = \app\common\model\Supplier::getSupplierName(0);
  186. // $this->company_list = \app\common\model\Company::getCompanyName();
  187. $all_cate = \app\common\model\SupplierCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  188. $this->goods_cate = make_tree($all_cate);
  189. if($this->request->isPost()) {
  190. list($post) = [$this->request->post()];
  191. if(!$data['release_time']) $data['release_time'] = date("Y-m-d H:i:s");
  192. if(!empty($post['phone'])) {
  193. $user_id = User::where('phone|email',$post['phone'])->value('id');
  194. if(!$user_id) $this->error('账号未注册');
  195. $data['user_id'] = $user_id;
  196. }else{
  197. $data['user_id'] = '';
  198. }
  199. }
  200. }
  201. protected function _form_result($id)
  202. {
  203. if($this->request->action() == 'add'){
  204. $supplier_name = \app\common\model\Supplier::where('id',$this->request->post('supplier_id'))->value('title');
  205. if($supplier_name)PlatformSwitch::followMsg(5,$this->request->post('supplier_id'),$supplier_name,$this->request->post('title'),$id);
  206. }
  207. \app\common\model\SupplierGoods::esAdd($id);
  208. $this->success('操作成功', 'javascript:history.back()');
  209. }
  210. }