WaterMaterialScience.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 list()
  61. {
  62. $where = Util::getMore([
  63. ['page', 1],
  64. ['limit', 20],
  65. ['name', ''],
  66. ['role', '']
  67. ]);
  68. return Json::successlayui(model::list($where));
  69. }
  70. /**
  71. * 显示创建资源表单页.
  72. *
  73. * @return \think\Response
  74. */
  75. public function create($id = 0)
  76. {
  77. $f = [];
  78. $f[] = Form::input('name', '名称')->col(12);
  79. $f[] = Form::select('type', '选择分类', '')->options([
  80. ['value' => 0, 'label' => '请选择分类'],
  81. ['value' => 1, 'label' => '顶板'],
  82. ['value' => 2, 'label' => '侧板'],
  83. ['value' => 3, 'label' => '拉筋'],
  84. ['value' => 4, 'label' => '底板'],
  85. ['value' => 5, 'label' => '立柱'],
  86. ['value' => 6, 'label' => '辅拉'],
  87. ])->filterable(true);
  88. $f[] = Form::select('th_id', '选择厚度', '')->options(
  89. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  90. )->filterable(true);
  91. $f[] = Form::input('weight', '重量(kg)');
  92. $f[] = Form::input('unit_price', '单价');
  93. $f[] = Form::input('company', '单位');
  94. $f[] = Form::input('long', '长');
  95. $f[] = Form::input('wide', '宽');
  96. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  97. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  98. $this->assign(compact('form'));
  99. return $this->fetch('public/form-builder');
  100. }
  101. /**
  102. * 显示创建资源表单页.
  103. *
  104. * @return \think\Response
  105. */
  106. public function creates($id = 0)
  107. {
  108. $f = [];
  109. $f[] = Form::input('name', '名称')->col(12);
  110. $f[] = Form::select('type', '选择分类', '')->options([
  111. ['value' => 0, 'label' => '请选择分类'],
  112. ['value' => 1, 'label' => '顶板'],
  113. ['value' => 2, 'label' => '侧板'],
  114. ['value' => 3, 'label' => '拉筋'],
  115. ['value' => 4, 'label' => '底板'],
  116. ['value' => 5, 'label' => '立柱'],
  117. ['value' => 6, 'label' => '辅拉'],
  118. ])->filterable(true);
  119. $f[] = Form::select('th_id', '选择厚度', '')->options(
  120. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  121. )->filterable(true);
  122. $f[] = Form::input('weight', '重量(kg)');
  123. $f[] = Form::input('unit_price', '单价');
  124. $f[] = Form::input('company', '单位');
  125. $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  126. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  127. $this->assign(compact('form'));
  128. return $this->fetch('public/form-builder');
  129. }
  130. public function save()
  131. {
  132. $model = new model;
  133. $data = Util::postMore([
  134. 'name',
  135. 'type',
  136. 'th_id',
  137. 'weight',
  138. 'unit_price',
  139. 'company',
  140. 'long',
  141. 'wide',
  142. 'is_gc'
  143. ]);
  144. $validate = Validate::rule('name', 'require')->rule([
  145. 'name' => 'require',
  146. 'type' => 'require',
  147. 'th_id' => 'require',
  148. 'weight' => 'require',
  149. 'unit_price' => 'require',
  150. 'company' => 'require',
  151. ]);
  152. $validate->message([
  153. 'name.require' => '名称不能为空',
  154. 'type.require' => '请选择分类',
  155. 'th_id.require' => '请选择厚度',
  156. 'weight.require' => '请填写重量',
  157. 'unit_price.require' => '请填写单价',
  158. 'company.require' => '请填写单位',
  159. ]);
  160. if (!$validate->check($data)) {
  161. return Json::fail($validate->getError());
  162. }
  163. $res = $model->save($data);
  164. if ($res) return Json::successful('添加成功');
  165. return Json::fail('添加失败');
  166. }
  167. /**
  168. * 显示创建资源表单页.
  169. *
  170. * @return \think\Response
  171. */
  172. public function edit($id = 0)
  173. {
  174. $data = model::find($id);
  175. $f = [];
  176. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  177. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  178. ['value' => 0, 'label' => '请选择分类'],
  179. ['value' => 1, 'label' => '顶板'],
  180. ['value' => 2, 'label' => '侧板'],
  181. ['value' => 3, 'label' => '拉筋'],
  182. ['value' => 4, 'label' => '底板'],
  183. ['value' => 5, 'label' => '立柱'],
  184. ['value' => 6, 'label' => '辅拉'],
  185. ])->filterable(true);
  186. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  187. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  188. )->filterable(true);
  189. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  190. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  191. $f[] = Form::input('company', '单位', $data['company']);
  192. $f[] = Form::input('long', '长', $data['long']);
  193. $f[] = Form::input('wide', '宽', $data['wide']);
  194. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  195. $f[] = Form::hidden('id', $id);
  196. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  197. $this->assign(compact('form'));
  198. return $this->fetch('public/form-builder');
  199. }
  200. /**
  201. * 显示创建资源表单页.
  202. *
  203. * @return \think\Response
  204. */
  205. public function edits($id = 0)
  206. {
  207. $data = model::find($id);
  208. $f = [];
  209. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  210. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  211. ['value' => 0, 'label' => '请选择分类'],
  212. ['value' => 1, 'label' => '顶板'],
  213. ['value' => 2, 'label' => '侧板'],
  214. ['value' => 3, 'label' => '拉筋'],
  215. ['value' => 4, 'label' => '底板'],
  216. ['value' => 5, 'label' => '立柱'],
  217. ['value' => 6, 'label' => '辅拉'],
  218. ])->filterable(true);
  219. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  220. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  221. )->filterable(true);
  222. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  223. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  224. $f[] = Form::input('company', '单位', $data['company']);
  225. $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
  226. $f[] = Form::hidden('id', $id);
  227. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  228. $this->assign(compact('form'));
  229. return $this->fetch('public/form-builder');
  230. }
  231. /**
  232. * 修改
  233. * @return void
  234. * @throws \think\db\exception\DataNotFoundException
  235. * @throws \think\db\exception\DbException
  236. * @throws \think\db\exception\ModelNotFoundException
  237. */
  238. public function update()
  239. {
  240. $model = new model;
  241. $data = Util::postMore([
  242. 'name',
  243. 'type',
  244. 'th_id',
  245. 'weight',
  246. 'unit_price',
  247. 'company',
  248. 'long',
  249. 'wide',
  250. 'id',
  251. 'is_gc'
  252. ]);
  253. $validate = Validate::rule('name', 'require')->rule([
  254. 'name' => 'require',
  255. 'type' => 'require',
  256. 'th_id' => 'require',
  257. 'weight' => 'require',
  258. 'unit_price' => 'require',
  259. 'company' => 'require',
  260. ]);
  261. $validate->message([
  262. 'name.require' => '名称不能为空',
  263. 'type.require' => '请选择分类',
  264. 'th_id.require' => '请选择厚度',
  265. 'weight.require' => '请填写重量',
  266. 'unit_price.require' => '请填写单价',
  267. 'company.require' => '请填写单位',
  268. ]);
  269. $details = $model->find($data['id']);
  270. $details['name'] = $data['name'];
  271. $details['type'] = $data['type'];
  272. $details['th_id'] = $data['th_id'];
  273. $details['weight'] = $data['weight'];
  274. $details['unit_price'] = $data['unit_price'];
  275. $details['company'] = $data['company'];
  276. $details['is_gc'] = $data['is_gc'];
  277. $res = $details->save();
  278. if ($res) return Json::successful('修改成功');
  279. return Json::fail('修改失败');
  280. }
  281. /**
  282. * 删除
  283. * @param $id
  284. * @return void
  285. * @throws \Exception
  286. */
  287. public function delete($id)
  288. {
  289. if (!$id) Json::fail('删除失败');
  290. $model = new model;
  291. $res = model::destroy($id);
  292. if ($res){
  293. return Json::success('删除成功!');
  294. }else{
  295. return Json::fail($model->getErrorInfo());
  296. }
  297. }
  298. }