WaterMaterialScience.php 7.6 KB

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