WaterMaterialScience.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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 list()
  71. {
  72. $where = Util::getMore([
  73. ['page', 1],
  74. ['limit', 20],
  75. ['name', ''],
  76. ['role', '']
  77. ]);
  78. return Json::successlayui(model::list($where));
  79. }
  80. /**
  81. * 显示创建资源表单页.
  82. *
  83. * @return \think\Response
  84. */
  85. public function create($id = 0)
  86. {
  87. $f = [];
  88. $f[] = Form::input('name', '名称')->col(12);
  89. $f[] = Form::select('type', '选择分类', '')->options([
  90. ['value' => 0, 'label' => '请选择分类'],
  91. ['value' => 1, 'label' => '顶板'],
  92. ['value' => 2, 'label' => '侧板'],
  93. ['value' => 3, 'label' => '拉筋'],
  94. ['value' => 4, 'label' => '底板'],
  95. ])->filterable(true);
  96. $f[] = Form::select('th_id', '选择厚度', '')->options(
  97. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  98. )->filterable(true);
  99. $f[] = Form::input('weight', '重量(kg)');
  100. $f[] = Form::input('unit_price', '单价');
  101. $f[] = Form::input('company', '单位');
  102. $f[] = Form::input('long', '长');
  103. $f[] = Form::input('wide', '宽');
  104. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  105. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  106. $this->assign(compact('form'));
  107. return $this->fetch('public/form-builder');
  108. }
  109. /**
  110. * 显示创建资源表单页.
  111. *
  112. * @return \think\Response
  113. */
  114. public function creates($id = 0)
  115. {
  116. $f = [];
  117. $f[] = Form::input('name', '名称')->col(12);
  118. $f[] = Form::select('type', '选择分类', '')->options([
  119. ['value' => 0, 'label' => '请选择分类'],
  120. ['value' => 5, 'label' => '立柱'],
  121. ['value' => 6, 'label' => '辅拉'],
  122. ])->filterable(true);
  123. $f[] = Form::select('th_id', '选择厚度', '')->options(
  124. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  125. )->filterable(true);
  126. $f[] = Form::input('weight', '重量(kg)');
  127. $f[] = Form::input('unit_price', '单价');
  128. $f[] = Form::input('company', '单位');
  129. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  130. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  131. $this->assign(compact('form'));
  132. return $this->fetch('public/form-builder');
  133. }
  134. /**
  135. * 显示创建资源表单页.
  136. *
  137. * @return \think\Response
  138. */
  139. public function create_warm($id = 0)
  140. {
  141. $f = [];
  142. $f[] = Form::input('name', '名称')->col(12);
  143. $f[] = Form::select('type', '选择分类', '')->options([
  144. ['value' => 7, 'label' => '保温'],
  145. ])->filterable(true);
  146. $f[] = Form::input('weight', '重量(kg)');
  147. $f[] = Form::input('unit_price', '单价');
  148. $f[] = Form::input('company', '单位');
  149. $f[] = Form::input('long', '长');
  150. $f[] = Form::input('wide', '宽');
  151. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  152. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  153. $this->assign(compact('form'));
  154. return $this->fetch('public/form-builder');
  155. }
  156. /**
  157. * 显示创建资源表单页.
  158. *
  159. * @return \think\Response
  160. */
  161. public function create_channel($id = 0)
  162. {
  163. $f = [];
  164. $f[] = Form::input('name', '名称')->col(12);
  165. $f[] = Form::select('type', '选择分类', '')->options([
  166. ['value' => 8, 'label' => '槽钢'],
  167. ])->filterable(true);
  168. $f[] = Form::input('weight', '重量(kg)');
  169. $f[] = Form::input('unit_price', '单价');
  170. $f[] = Form::input('company', '单位');
  171. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  172. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  173. $this->assign(compact('form'));
  174. return $this->fetch('public/form-builder');
  175. }
  176. public function save()
  177. {
  178. $model = new model;
  179. $data = Util::postMore([
  180. 'name',
  181. 'type',
  182. 'th_id',
  183. 'weight',
  184. 'unit_price',
  185. 'company',
  186. 'long',
  187. 'wide',
  188. 'is_gc'
  189. ]);
  190. $validate = Validate::rule('name', 'require')->rule([
  191. 'name' => 'require',
  192. 'type' => 'require',
  193. 'weight' => 'require',
  194. 'unit_price' => 'require',
  195. 'company' => 'require',
  196. ]);
  197. $validate->message([
  198. 'name.require' => '名称不能为空',
  199. 'type.require' => '请选择分类',
  200. 'weight.require' => '请填写重量',
  201. 'unit_price.require' => '请填写单价',
  202. 'company.require' => '请填写单位',
  203. ]);
  204. if (!$validate->check($data)) {
  205. return Json::fail($validate->getError());
  206. }
  207. $res = $model->save($data);
  208. if ($res) return Json::successful('添加成功');
  209. return Json::fail('添加失败');
  210. }
  211. /**
  212. * 显示创建资源表单页.
  213. *
  214. * @return \think\Response
  215. */
  216. public function edit($id = 0)
  217. {
  218. $data = model::find($id);
  219. $f = [];
  220. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  221. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  222. ['value' => 0, 'label' => '请选择分类'],
  223. ['value' => 1, 'label' => '顶板'],
  224. ['value' => 2, 'label' => '侧板'],
  225. ['value' => 3, 'label' => '拉筋'],
  226. ['value' => 4, 'label' => '底板'],
  227. ['value' => 5, 'label' => '立柱'],
  228. ['value' => 6, 'label' => '辅拉'],
  229. ['value' => 7, 'label' => '保温'],
  230. ['value' => 8, 'label' => '槽钢'],
  231. ])->filterable(true);
  232. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  233. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  234. )->filterable(true);
  235. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  236. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  237. $f[] = Form::input('company', '单位', $data['company']);
  238. $f[] = Form::input('long', '长', $data['long']);
  239. $f[] = Form::input('wide', '宽', $data['wide']);
  240. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  241. $f[] = Form::hidden('id', $id);
  242. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  243. $this->assign(compact('form'));
  244. return $this->fetch('public/form-builder');
  245. }
  246. /**
  247. * 显示创建资源表单页.
  248. *
  249. * @return \think\Response
  250. */
  251. public function edits($id = 0)
  252. {
  253. $data = model::find($id);
  254. $f = [];
  255. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  256. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  257. ['value' => 0, 'label' => '请选择分类'],
  258. ['value' => 1, 'label' => '顶板'],
  259. ['value' => 2, 'label' => '侧板'],
  260. ['value' => 3, 'label' => '拉筋'],
  261. ['value' => 4, 'label' => '底板'],
  262. ['value' => 5, 'label' => '立柱'],
  263. ['value' => 6, 'label' => '辅拉'],
  264. ['value' => 7, 'label' => '保温'],
  265. ['value' => 8, 'label' => '槽钢'],
  266. ])->filterable(true);
  267. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  268. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  269. )->filterable(true);
  270. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  271. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  272. $f[] = Form::input('company', '单位', $data['company']);
  273. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  274. $f[] = Form::hidden('id', $id);
  275. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  276. $this->assign(compact('form'));
  277. return $this->fetch('public/form-builder');
  278. }
  279. /**
  280. * 显示创建资源表单页.
  281. *
  282. * @return \think\Response
  283. */
  284. public function edit_warm($id = 0)
  285. {
  286. $data = model::find($id);
  287. $f = [];
  288. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  289. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  290. ['value' => 7, 'label' => '保温'],
  291. ])->filterable(true);
  292. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  293. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  294. $f[] = Form::input('company', '单位', $data['company']);
  295. $f[] = Form::input('long', '长', $data['long']);
  296. $f[] = Form::input('wide', '宽', $data['wide']);
  297. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  298. $f[] = Form::hidden('id', $id);
  299. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  300. $this->assign(compact('form'));
  301. return $this->fetch('public/form-builder');
  302. }
  303. /**
  304. * 显示创建资源表单页.
  305. *
  306. * @return \think\Response
  307. */
  308. public function edit_channel($id = 0)
  309. {
  310. $data = model::find($id);
  311. $f = [];
  312. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  313. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  314. ['value' => 8, 'label' => '槽钢'],
  315. ])->filterable(true);
  316. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  317. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  318. $f[] = Form::input('company', '单位', $data['company']);
  319. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  320. $f[] = Form::hidden('id', $id);
  321. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  322. $this->assign(compact('form'));
  323. return $this->fetch('public/form-builder');
  324. }
  325. /**
  326. * 修改
  327. * @return void
  328. * @throws \think\db\exception\DataNotFoundException
  329. * @throws \think\db\exception\DbException
  330. * @throws \think\db\exception\ModelNotFoundException
  331. */
  332. public function update()
  333. {
  334. $model = new model;
  335. $data = Util::postMore([
  336. 'name',
  337. 'type',
  338. 'th_id',
  339. 'weight',
  340. 'unit_price',
  341. 'company',
  342. 'long',
  343. 'wide',
  344. 'id',
  345. 'is_gc'
  346. ]);
  347. $validate = Validate::rule('name', 'require')->rule([
  348. 'name' => 'require',
  349. 'type' => 'require',
  350. 'weight' => 'require',
  351. 'unit_price' => 'require',
  352. 'company' => 'require',
  353. ]);
  354. $validate->message([
  355. 'name.require' => '名称不能为空',
  356. 'type.require' => '请选择分类',
  357. 'weight.require' => '请填写重量',
  358. 'unit_price.require' => '请填写单价',
  359. 'company.require' => '请填写单位',
  360. ]);
  361. $details = $model->find($data['id']);
  362. $details['name'] = $data['name'];
  363. $details['type'] = $data['type'];
  364. $details['th_id'] = $data['th_id'];
  365. $details['weight'] = $data['weight'];
  366. $details['unit_price'] = $data['unit_price'];
  367. $details['company'] = $data['company'];
  368. $details['is_gc'] = $data['is_gc'];
  369. $details['long'] = $data['long'];
  370. $details['wide'] = $data['wide'];
  371. $res = $details->save();
  372. if ($res) return Json::successful('修改成功');
  373. return Json::fail('修改失败');
  374. }
  375. /**
  376. * 删除
  377. * @param $id
  378. * @return void
  379. * @throws \Exception
  380. */
  381. public function delete($id)
  382. {
  383. if (!$id) Json::fail('删除失败');
  384. $model = new model;
  385. $res = model::destroy($id);
  386. if ($res){
  387. return Json::success('删除成功!');
  388. }else{
  389. return Json::fail($model->getErrorInfo());
  390. }
  391. }
  392. }