SupplierGoods.php 6.3 KB

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