WaterMaterialScience.php 10 KB

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