WaterMaterialScience.php 13 KB

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