SupplierGoods.php 4.9 KB

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