SupplierGoods.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. $company_id = input('get.company_id');
  35. $third_classify = input('get.third_classify');
  36. $this->supplier_id = $supplier_id;
  37. $this->supplier_list = \app\common\model\Supplier::getSupplierName(0);
  38. //$this->company_list = \app\common\model\Company::getCompanyName();
  39. $where = [];
  40. $where[] = ['a.is_deleted','=',0];
  41. if($supplier_id)$where[] = ['a.supplier_id','=',$supplier_id];
  42. if($company_id)$where[] = ['a.company_id','=',$company_id];
  43. if($third_classify)$where[] = ['a.third_classify','=',$third_classify];
  44. $query = $this->_query($this->table)->where($where)->like('a.name')->alias('a')->field('a.*,b.title supplier_name ,c.title company_name');
  45. $query->leftJoin('Supplier b','b.id = a.supplier_id')->leftJoin('Company c','c.id = a.company_id');
  46. $query->order(' a.sort desc , a.id desc')->page();
  47. }
  48. /**
  49. * 数据列表处理
  50. * @auth true
  51. * @menu true
  52. * @param array $data
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\ModelNotFoundException
  55. * @throws \think\exception\DbException
  56. */
  57. protected function _index_page_filter(&$data)
  58. {
  59. }
  60. /**
  61. * 添加供货商商品
  62. * @auth true
  63. * @menu true
  64. * @throws \think\Exception
  65. * @throws \think\db\exception\DataNotFoundException
  66. * @throws \think\db\exception\ModelNotFoundException
  67. * @throws \think\exception\DbException
  68. * @throws \think\exception\PDOException
  69. */
  70. public function add()
  71. {
  72. $this->title = '添加供货商商品';
  73. $this->supplier_id = input('supplier_id');
  74. $this->_form($this->table, 'form');
  75. }
  76. /**
  77. * 编辑供货商商品
  78. * @auth true
  79. * @menu true
  80. * @throws \think\Exception
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. * @throws \think\exception\DbException
  84. * @throws \think\exception\PDOException
  85. */
  86. public function edit()
  87. {
  88. $this->title = '编辑供货商商品';
  89. $this->supplier_id = input('supplier_id');
  90. $this->_form($this->table, 'form');
  91. }
  92. /**
  93. * 启用
  94. * @auth true
  95. * @menu true
  96. * @throws \think\Exception
  97. * @throws \think\exception\PDOException
  98. */
  99. public function enable()
  100. {
  101. $this->_save($this->table, ['status' => 1]);
  102. $this->success('已上架!');
  103. }
  104. /**
  105. * 禁用
  106. * @auth true
  107. * @menu true
  108. * @throws \think\Exception
  109. * @throws \think\db\exception\DataNotFoundException
  110. * @throws \think\db\exception\ModelNotFoundException
  111. * @throws \think\exception\DbException
  112. * @throws \think\exception\PDOException
  113. */
  114. public function forbidden()
  115. {
  116. $this->_save($this->table, ['status' => 0]);
  117. $this->success('已下架!');
  118. }
  119. /**
  120. * 删除
  121. * @auth true
  122. * @menu true
  123. * @throws \think\Exception
  124. * @throws \think\exception\PDOException
  125. */
  126. public function del()
  127. {
  128. $this->_save($this->table, ['is_deleted' => 1]);
  129. }
  130. /**
  131. * 表单数据处理
  132. * @auth true
  133. * @menu true
  134. * @param array $data
  135. */
  136. protected function _form_filter(&$data)
  137. {
  138. if($this->request->isGet())
  139. {
  140. $third_classify = input('third_classify');
  141. if($third_classify) {
  142. if($third_classify) $data['third_classify'] = $third_classify;
  143. $third_info = \app\common\model\SupplierCate::where('id',$third_classify)->find()->toArray();
  144. if($third_classify) $data['second_classify'] = $third_info['pid'];
  145. $data['first_classify'] = \app\common\model\SupplierCate::where('id',$data['second_classify'])->value('pid');
  146. }
  147. $supplier_id = input('supplier_id');
  148. if($supplier_id) $data['supplier_id'] = $supplier_id;
  149. }
  150. // 视频
  151. $this->video_list = \app\common\model\VideoIntro::with('videoArr')
  152. ->where(['is_deleted'=>0])->order('id desc')
  153. ->select()->toArray();
  154. // 文章列表
  155. $this->article_list = \app\common\model\ArticleIntro::with('itemChildren')
  156. ->field('id,title')
  157. ->where(['is_deleted'=>0])->order('id desc')
  158. ->select()->toArray();
  159. // 资料
  160. $this->datum_list = DatumIntro::with('urlArr')
  161. ->where(['is_deleted'=>0])->order('id desc')
  162. ->select()->toArray();
  163. $data['create_at'] = date('Y-m-d H:i:s');
  164. $this->supplier_list = \app\common\model\Supplier::getSupplierName(0);
  165. // $this->company_list = \app\common\model\Company::getCompanyName();
  166. $all_cate = \app\common\model\SupplierCate::where(['is_deleted'=>0])->order('sort desc ,id desc')->select();
  167. $this->goods_cate = make_tree($all_cate);
  168. if($this->request->isPost()) {
  169. list($post) = [$this->request->post()];
  170. if(!$data['release_time']) $data['release_time'] = date("Y-m-d H:i:s");
  171. if(!empty($post['phone'])) {
  172. $user_id = User::where('phone|email',$post['phone'])->value('id');
  173. if(!$user_id) $this->error('账号未注册');
  174. $data['user_id'] = $user_id;
  175. }else{
  176. $data['user_id'] = '';
  177. }
  178. }
  179. }
  180. protected function _form_result($id)
  181. {
  182. if($this->request->action() == 'add'){
  183. $supplier_name = \app\common\model\Supplier::where('id',$this->request->post('supplier_id'))->value('title');
  184. if($supplier_name)PlatformSwitch::followMsg(5,$this->request->post('supplier_id'),$supplier_name,$this->request->post('title'),$id);
  185. }
  186. $this->success('操作成功', 'javascript:history.back()');
  187. }
  188. }