WaterDefault.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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\WaterDefault as model;
  20. /**
  21. * 订单管理控制器 同一个订单表放在一个控制器
  22. * Class StoreOrder
  23. * @package app\admin\controller\store
  24. */
  25. class WaterDefault extends AuthController
  26. {
  27. /**
  28. * @return mixed
  29. */
  30. public function index()
  31. {
  32. return $this->fetch();
  33. }
  34. public function list()
  35. {
  36. $where = Util::getMore([
  37. ['page', 1],
  38. ['limit', 20],
  39. ['name', ''],
  40. ['card', ''],
  41. ['order_id', ''],
  42. ]);
  43. return Json::successlayui(model::list($where));
  44. }
  45. /**
  46. * 显示创建资源表单页.
  47. *
  48. * @return \think\Response
  49. */
  50. public function create($id = 0)
  51. {
  52. $f = [];
  53. $f[] = Form::input('high', '高度')->col(12);
  54. $f[] = Form::select('roof', '顶板', 0)->options(
  55. array_merge([['value' => 0, 'label' => '选择顶板厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 1)->field('id as value,name as label')->select()->toArray())
  56. )->filterable(true);
  57. $f[] = Form::select('floor', '底板', 0)->options(
  58. array_merge([['value' => 0, 'label' => '选择底板厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 4)->field('id as value,name as label')->select()->toArray())
  59. )->filterable(true);
  60. $f[] = Form::select('column', '立柱', 0)->options(
  61. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 5)->field('id as value,name as label')->select()->toArray())
  62. )->filterable(true);
  63. $f[] = Form::select('side_plate1', '侧板1', 0)->options(
  64. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 2)->field('id as value,name as label')->select()->toArray())
  65. )->filterable(true);
  66. $f[] = Form::select('side_plate2', '侧板2', 0)->options(
  67. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 2)->field('id as value,name as label')->select()->toArray())
  68. )->filterable(true);
  69. $f[] = Form::select('side_plate3', '侧板3', 0)->options(
  70. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 2)->field('id as value,name as label')->select()->toArray())
  71. )->filterable(true);
  72. $f[] = Form::select('side_plate4', '侧板4', 0)->options(
  73. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 2)->field('id as value,name as label')->select()->toArray())
  74. )->filterable(true);
  75. $f[] = Form::select('side_plate5', '侧板5', 0)->options(
  76. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 2)->field('id as value,name as label')->select()->toArray())
  77. )->filterable(true);
  78. $f[] = Form::select('lacing1', '拉筋1', 0)->options(
  79. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 3)->field('id as value,name as label')->select()->toArray())
  80. )->filterable(true);
  81. $f[] = Form::select('lacing2', '拉筋2', 0)->options(
  82. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 3)->field('id as value,name as label')->select()->toArray())
  83. )->filterable(true);
  84. $f[] = Form::select('lacing3', '拉筋3', 0)->options(
  85. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 3)->field('id as value,name as label')->select()->toArray())
  86. )->filterable(true);
  87. $f[] = Form::select('lacing4', '拉筋4', 0)->options(
  88. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 3)->field('id as value,name as label')->select()->toArray())
  89. )->filterable(true);
  90. $f[] = Form::select('lacing5', '拉筋5', 0)->options(
  91. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 3)->field('id as value,name as label')->select()->toArray())
  92. )->filterable(true);
  93. $f[] = Form::select('fula1', '辅拉1', 0)->options(
  94. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 6)->field('id as value,name as label')->select()->toArray())
  95. )->filterable(true);
  96. $f[] = Form::select('fula2', '辅拉2', 0)->options(
  97. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 6)->field('id as value,name as label')->select()->toArray())
  98. )->filterable(true);
  99. $f[] = Form::select('fula3', '辅拉3', 0)->options(
  100. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 6)->field('id as value,name as label')->select()->toArray())
  101. )->filterable(true);
  102. $f[] = Form::select('fula4', '辅拉4', 0)->options(
  103. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 6)->field('id as value,name as label')->select()->toArray())
  104. )->filterable(true);
  105. $f[] = Form::select('fula5', '辅拉5', 0)->options(
  106. array_merge([['value' => 0, 'label' => '选择立柱厚度']], \app\admin\model\water\WaterCate::order('id DESC')->where('type', 6)->field('id as value,name as label')->select()->toArray())
  107. )->filterable(true);
  108. $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
  109. $this->assign(compact('form'));
  110. return $this->fetch('public/form-builder');
  111. }
  112. public function save()
  113. {
  114. $model = new model;
  115. $data = Util::postMore([
  116. 'high',
  117. 'roof',
  118. 'floor',
  119. 'column',
  120. 'side_plate1',
  121. 'side_plate2',
  122. 'side_plate3',
  123. 'side_plate4',
  124. 'side_plate5',
  125. 'lacing1',
  126. 'lacing2',
  127. 'lacing3',
  128. 'lacing4',
  129. 'lacing5',
  130. 'fula1',
  131. 'fula2',
  132. 'fula3',
  133. 'fula4',
  134. 'fula5',
  135. ]);
  136. $validate = Validate::rule([
  137. 'high' => 'require',
  138. 'roof' => 'require',
  139. 'floor' => 'require',
  140. 'column' => 'require',
  141. 'side_plate1' => 'require',
  142. 'lacing1' => 'require',
  143. 'fula1' => 'require',
  144. ]);
  145. $validate->message([
  146. 'high.require' => '高度不能为空',
  147. 'roof.require' => '请选择顶板',
  148. 'floor.require' => '请选择底板',
  149. 'column.require' => '请填写立柱',
  150. 'side_plate1.require' => '最少填写侧板1',
  151. 'lacing1.require' => '最少填写拉筋1',
  152. 'fula1.require' => '最少填写辅拉1',
  153. ]);
  154. if ($data['side_plate1'] > 0) $data['side_plate'] = $data['side_plate1'];
  155. if ($data['side_plate2'] > 0) $data['side_plate'] .= ','.$data['side_plate2'];
  156. if ($data['side_plate3'] > 0) $data['side_plate'] .= ','.$data['side_plate3'];
  157. if ($data['side_plate4'] > 0) $data['side_plate'] .= ','.$data['side_plate4'];
  158. if ($data['side_plate5'] > 0) $data['side_plate'] .= ','.$data['side_plate5'];
  159. if ($data['lacing1'] > 0) $data['lacing'] = $data['lacing1'];
  160. if ($data['lacing2'] > 0) $data['lacing'] .= ','.$data['lacing2'];
  161. if ($data['lacing3'] > 0) $data['lacing'] .= ','.$data['lacing3'];
  162. if ($data['lacing4'] > 0) $data['lacing'] .= ','.$data['lacing4'];
  163. if ($data['lacing5'] > 0) $data['lacing'] .= ','.$data['lacing5'];
  164. if ($data['fula1'] > 0) $data['fula'] = $data['fula1'];
  165. if ($data['fula2'] > 0) $data['fula'] .= ','.$data['fula2'];
  166. if ($data['fula3'] > 0) $data['fula'] .= ','.$data['fula3'];
  167. if ($data['fula4'] > 0) $data['fula'] .= ','.$data['fula4'];
  168. if ($data['fula5'] > 0) $data['fula'] .= ','.$data['fula5'];
  169. if (!$validate->check($data)) {
  170. return Json::fail($validate->getError());
  171. }
  172. $res = $model->save($data);
  173. if ($res) return Json::successful('添加成功');
  174. return Json::fail('添加失败');
  175. }
  176. /**
  177. * 显示创建资源表单页.
  178. *
  179. * @return \think\Response
  180. */
  181. public function edit($id = 0)
  182. {
  183. $data = model::find($id);
  184. $f = [];
  185. $f[] = Form::input('name', '名称', $data['name'])->col(12);
  186. $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
  187. ['value' => 0, 'label' => '请选择分类'],
  188. ['value' => 1, 'label' => '顶板'],
  189. ['value' => 2, 'label' => '侧板'],
  190. ['value' => 3, 'label' => '拉筋'],
  191. ['value' => 4, 'label' => '底板'],
  192. ])->filterable(true);
  193. $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
  194. array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
  195. )->filterable(true);
  196. $f[] = Form::input('weight', '重量(kg)', $data['weight']);
  197. $f[] = Form::input('unit_price', '单价', $data['unit_price']);
  198. $f[] = Form::input('company', '单位', $data['company']);
  199. $f[] = Form::input('long', '长', $data['long']);
  200. $f[] = Form::input('wide', '宽', $data['wide']);
  201. $f[] = Form::hidden('id', $id);
  202. $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
  203. $this->assign(compact('form'));
  204. return $this->fetch('public/form-builder');
  205. }
  206. /**
  207. * 修改
  208. * @return void
  209. * @throws \think\db\exception\DataNotFoundException
  210. * @throws \think\db\exception\DbException
  211. * @throws \think\db\exception\ModelNotFoundException
  212. */
  213. public function update()
  214. {
  215. $model = new model;
  216. $data = Util::postMore([
  217. 'name',
  218. 'type',
  219. 'th_id',
  220. 'weight',
  221. 'unit_price',
  222. 'company',
  223. 'long',
  224. 'wide',
  225. 'id',
  226. ]);
  227. $validate = Validate::rule('name', 'require')->rule([
  228. 'name' => 'require',
  229. 'type' => 'require',
  230. 'th_id' => 'require',
  231. 'weight' => 'require',
  232. 'unit_price' => 'require',
  233. 'company' => 'require',
  234. 'long' => 'require',
  235. 'wide' => 'require',
  236. ]);
  237. $validate->message([
  238. 'name.require' => '名称不能为空',
  239. 'type.require' => '请选择分类',
  240. 'th_id.require' => '请选择厚度',
  241. 'weight.require' => '请填写重量',
  242. 'unit_price.require' => '请填写单价',
  243. 'company.require' => '请填写单位',
  244. 'long.require' => '请填写长度',
  245. 'wide.require' => '请填写宽度',
  246. ]);
  247. $details = $model->find($data['id']);
  248. $details['name'] = $data['name'];
  249. $details['thickness'] = $data['thickness'];
  250. $res = $details->save();
  251. if ($res) return Json::successful('修改成功');
  252. return Json::fail('修改失败');
  253. }
  254. /**
  255. * 删除
  256. * @param $id
  257. * @return void
  258. * @throws \Exception
  259. */
  260. public function delete($id)
  261. {
  262. if (!$id) Json::fail('删除失败');
  263. $model = new model;
  264. $res = model::destroy($id);
  265. if ($res){
  266. return Json::success('删除成功!');
  267. }else{
  268. return Json::fail($model->getErrorInfo());
  269. }
  270. }
  271. }