WaterMaterialScience.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/11
  6. */
  7. namespace app\admin\controller\water;
  8. use app\admin\controller\AuthController;
  9. use crmeb\services\{ExpressService,
  10. JsonService,
  11. JsonService as Json,
  12. MiniProgramService,
  13. WechatService,
  14. FormBuilder as Form,
  15. CacheService,
  16. UtilService as Util};
  17. use think\facade\Route as Url;
  18. use think\facade\Validate;
  19. Use app\admin\model\water\WaterMaterialScience as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class WaterMaterialScience extends AuthController
  26. {
  27. /**
  28. * @return mixed
  29. */
  30. public function roof()
  31. {
  32. $this->assign('role', 'roof');
  33. return $this->fetch();
  34. }
  35. public function side_plate()
  36. {
  37. $this->assign('role', 'side_plate');
  38. return $this->fetch();
  39. }
  40. public function lacing()
  41. {
  42. $this->assign('role', 'lacing');
  43. return $this->fetch();
  44. }
  45. public function floor()
  46. {
  47. $this->assign('role', 'floor');
  48. return $this->fetch();
  49. }
  50. public function column()
  51. {
  52. $this->assign('role', 'column');
  53. return $this->fetch();
  54. }
  55. public function fula()
  56. {
  57. $this->assign('role', 'fula');
  58. return $this->fetch();
  59. }
  60. public function warm()
  61. {
  62. $this->assign('role', 'warm');
  63. return $this->fetch();
  64. }
  65. public function channel()
  66. {
  67. $this->assign('role', 'channel');
  68. return $this->fetch();
  69. }
  70. public function escalator()
  71. {
  72. $this->assign('role', 'escalator');
  73. return $this->fetch();
  74. }
  75. public function list()
  76. {
  77. $where = Util::getMore([
  78. ['page', 1],
  79. ['limit', 20],
  80. ['name', ''],
  81. ['role', '']
  82. ]);
  83. return Json::successlayui(model::list($where));
  84. }
  85. /**
  86. * 显示创建资源表单页.
  87. *
  88. * @return \think\Response
  89. */
  90. public function create($id = 0, $role = 0)
  91. {
  92. if ($role == 'roof'){
  93. $type = 1;
  94. }elseif ($role == 'side_plate'){
  95. $type = 2;
  96. }elseif ($role == 'floor'){
  97. $type = 4;
  98. }else{
  99. return Json::fail('参数错误');
  100. }
  101. $f = [];
  102. $f[] = Form::input('name', '名称')->col(12);
  103. $f[] = Form::hidden('type', $type);
  104. $f[] = Form::select('th_id', '选择厚度', '')->options(
  105. array_merge([['value' => 0, 'label' => '请选择厚度']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  106. )->filterable(true);
  107. $f[] = Form::select('cate_id', '选择分类', '')->options(
  108. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', $type)->field('id as value,name as label')->select()->toArray())
  109. )->filterable(true);
  110. $f[] = Form::input('weight', '重量(kg)');
  111. $f[] = Form::input('unit_price', '单价');
  112. $f[] = Form::input('company', '单位');
  113. $f[] = Form::input('long', '长');
  114. $f[] = Form::input('wide', '宽');
  115. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  116. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  117. $this->assign(compact('form'));
  118. return $this->fetch('public/form-builder');
  119. }
  120. /**
  121. * 显示创建资源表单页.
  122. *
  123. * @return \think\Response
  124. */
  125. public function creates($id = 0, $role = 0)
  126. {
  127. if ($role == 'column'){
  128. $type = 5;
  129. }elseif ($role == 'fula'){
  130. $type = 6;
  131. }elseif ($role == 'lacing'){
  132. $type = 3;
  133. }else{
  134. return Json::fail('参数错误');
  135. }
  136. $f = [];
  137. $f[] = Form::input('name', '名称')->col(12);
  138. $f[] = Form::hidden('type', $type);
  139. $f[] = Form::select('th_id', '选择厚度', '')->options(
  140. array_merge([['value' => 0, 'label' => '请选择厚度']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  141. )->filterable(true);
  142. $f[] = Form::select('cate_id', '选择分类', '')->options(
  143. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', $type)->field('id as value,name as label')->select()->toArray())
  144. )->filterable(true);
  145. $f[] = Form::input('weight', '重量(kg)');
  146. $f[] = Form::input('unit_price', '单价');
  147. $f[] = Form::input('company', '单位');
  148. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  149. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  150. $this->assign(compact('form'));
  151. return $this->fetch('public/form-builder');
  152. }
  153. /**
  154. * 显示创建资源表单页.
  155. *
  156. * @return \think\Response
  157. */
  158. public function create_warm($id = 0, $role = 0)
  159. {
  160. if ($role == 'warm'){
  161. $type = 7;
  162. }else{
  163. return Json::fail('参数错误');
  164. }
  165. $f = [];
  166. $f[] = Form::input('name', '名称')->col(12);
  167. $f[] = Form::hidden('type', $type);
  168. $f[] = Form::select('cate_id', '选择分类', '')->options(
  169. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', $type)->field('id as value,name as label')->select()->toArray())
  170. )->filterable(true);
  171. $f[] = Form::input('weight', '重量(kg)');
  172. $f[] = Form::input('unit_price', '单价');
  173. $f[] = Form::input('company', '单位');
  174. $f[] = Form::input('long', '长');
  175. $f[] = Form::input('wide', '宽');
  176. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  177. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  178. $this->assign(compact('form'));
  179. return $this->fetch('public/form-builder');
  180. }
  181. /**
  182. * 显示创建资源表单页.
  183. *
  184. * @return \think\Response
  185. */
  186. public function create_channel($id = 0, $role = 0)
  187. {
  188. if ($role == 'escalator'){
  189. $type = 9;
  190. }elseif ($role == 'channel'){
  191. $type = 8;
  192. }else{
  193. return Json::fail('参数错误');
  194. }
  195. $f = [];
  196. $f[] = Form::input('name', '名称')->col(12);
  197. $f[] = Form::hidden('type', $type);
  198. $f[] = Form::select('cate_id', '选择分类', '')->options(
  199. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', $type)->field('id as value,name as label')->select()->toArray())
  200. )->filterable(true);
  201. $f[] = Form::input('weight', '重量(kg)');
  202. $f[] = Form::input('unit_price', '单价');
  203. $f[] = Form::input('company', '单位');
  204. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  205. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  206. $this->assign(compact('form'));
  207. return $this->fetch('public/form-builder');
  208. }
  209. public function save()
  210. {
  211. $model = new model;
  212. $data = Util::postMore([
  213. 'name',
  214. 'type',
  215. 'th_id',
  216. 'weight',
  217. 'unit_price',
  218. 'company',
  219. 'long',
  220. 'wide',
  221. 'is_gc',
  222. 'cate_id',
  223. ]);
  224. $validate = Validate::rule('name', 'require')->rule([
  225. 'name' => 'require',
  226. 'type' => 'require',
  227. 'weight' => 'require',
  228. 'unit_price' => 'require',
  229. 'company' => 'require',
  230. 'cate_id' => 'require',
  231. ]);
  232. $validate->message([
  233. 'name.require' => '名称不能为空',
  234. 'type.require' => '请选择分类',
  235. 'weight.require' => '请填写重量',
  236. 'unit_price.require' => '请填写单价',
  237. 'company.require' => '请填写单位',
  238. 'cate_id.require' => '请选择分类',
  239. ]);
  240. if (!$validate->check($data)) {
  241. return Json::fail($validate->getError());
  242. }
  243. $res = $model->save($data);
  244. if ($res) return Json::successful('添加成功');
  245. return Json::fail('添加失败');
  246. }
  247. /**
  248. * 显示创建资源表单页.
  249. *
  250. * @return \think\Response
  251. */
  252. public function edit($id = 0)
  253. {
  254. $data = model::find($id);
  255. $f = [];
  256. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  257. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  258. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  259. )->filterable(true);
  260. $f[] = Form::select('cate_id', '选择分类', (string)$data['cate_id'])->options(
  261. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', $data['type'])->field('id as value,name as label')->select()->toArray())
  262. )->filterable(true);
  263. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  264. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  265. $f[] = Form::input('company', '单位', $data['company']);
  266. $f[] = Form::input('long', '长', $data['long']);
  267. $f[] = Form::input('wide', '宽', $data['wide']);
  268. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  269. $f[] = Form::hidden('id', $id);
  270. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  271. $this->assign(compact('form'));
  272. return $this->fetch('public/form-builder');
  273. }
  274. /**
  275. * 显示创建资源表单页.
  276. *
  277. * @return \think\Response
  278. */
  279. public function edits($id = 0)
  280. {
  281. $data = model::find($id);
  282. $f = [];
  283. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  284. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  285. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  286. )->filterable(true);
  287. $f[] = Form::select('cate_id', '选择分类', (string)$data['cate_id'])->options(
  288. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', $data['type'])->field('id as value,name as label')->select()->toArray())
  289. )->filterable(true);
  290. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  291. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  292. $f[] = Form::input('company', '单位', $data['company']);
  293. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  294. $f[] = Form::hidden('id', $id);
  295. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  296. $this->assign(compact('form'));
  297. return $this->fetch('public/form-builder');
  298. }
  299. /**
  300. * 显示创建资源表单页.
  301. *
  302. * @return \think\Response
  303. */
  304. public function edit_warm($id = 0)
  305. {
  306. $data = model::find($id);
  307. $f = [];
  308. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  309. $f[] = Form::select('cate_id', '选择分类', (string)$data['cate_id'])->options(
  310. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', $data['type'])->field('id as value,name as label')->select()->toArray())
  311. )->filterable(true);
  312. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  313. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  314. $f[] = Form::input('company', '单位', $data['company']);
  315. $f[] = Form::input('long', '长', $data['long']);
  316. $f[] = Form::input('wide', '宽', $data['wide']);
  317. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  318. $f[] = Form::hidden('id', $id);
  319. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  320. $this->assign(compact('form'));
  321. return $this->fetch('public/form-builder');
  322. }
  323. /**
  324. * 显示创建资源表单页.
  325. *
  326. * @return \think\Response
  327. */
  328. public function edit_channel($id = 0)
  329. {
  330. $data = model::find($id);
  331. $f = [];
  332. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  333. $f[] = Form::select('cate_id', '选择分类', (string)$data['cate_id'])->options(
  334. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', $data['type'])->field('id as value,name as label')->select()->toArray())
  335. )->filterable(true);
  336. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  337. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  338. $f[] = Form::input('company', '单位', $data['company']);
  339. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  340. $f[] = Form::hidden('id', $id);
  341. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  342. $this->assign(compact('form'));
  343. return $this->fetch('public/form-builder');
  344. }
  345. /**
  346. * 修改
  347. * @return void
  348. * @throws \think\db\exception\DataNotFoundException
  349. * @throws \think\db\exception\DbException
  350. * @throws \think\db\exception\ModelNotFoundException
  351. */
  352. public function update()
  353. {
  354. $model = new model;
  355. $data = Util::postMore([
  356. 'name',
  357. 'th_id',
  358. 'weight',
  359. 'unit_price',
  360. 'company',
  361. 'long',
  362. 'wide',
  363. 'id',
  364. 'is_gc',
  365. 'cate_id'
  366. ]);
  367. $validate = Validate::rule('name', 'require')->rule([
  368. 'name' => 'require',
  369. 'weight' => 'require',
  370. 'unit_price' => 'require',
  371. 'company' => 'require',
  372. 'cate_id' => 'require',
  373. ]);
  374. $validate->message([
  375. 'name.require' => '名称不能为空',
  376. 'type.require' => '请选择分类',
  377. 'weight.require' => '请填写重量',
  378. 'unit_price.require' => '请填写单价',
  379. 'company.require' => '请填写单位',
  380. 'cate_id.require' => '请选择分类',
  381. ]);
  382. $details = $model->find($data['id']);
  383. $details['name'] = $data['name'];
  384. $details['th_id'] = $data['th_id'];
  385. $details['weight'] = $data['weight'];
  386. $details['unit_price'] = $data['unit_price'];
  387. $details['company'] = $data['company'];
  388. $details['is_gc'] = $data['is_gc'];
  389. $details['long'] = $data['long'];
  390. $details['wide'] = $data['wide'];
  391. $details['cate_id'] = $data['cate_id'];
  392. $res = $details->save();
  393. if ($res) return Json::successful('修改成功');
  394. return Json::fail('修改失败');
  395. }
  396. /**
  397. * 删除
  398. * @param $id
  399. * @return void
  400. * @throws \Exception
  401. */
  402. public function delete($id)
  403. {
  404. if (!$id) Json::fail('删除失败');
  405. $model = new model;
  406. $res = model::destroy($id);
  407. if ($res){
  408. return Json::success('删除成功!');
  409. }else{
  410. return Json::fail($model->getErrorInfo());
  411. }
  412. }
  413. }