|
@@ -0,0 +1,296 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @author: xaboy<365615158@qq.com>
|
|
|
+ * @day: 2017/11/11
|
|
|
+ */
|
|
|
+
|
|
|
+namespace app\admin\controller\water;
|
|
|
+
|
|
|
+use app\admin\controller\AuthController;
|
|
|
+use crmeb\services\{ExpressService,
|
|
|
+ JsonService,
|
|
|
+ JsonService as Json,
|
|
|
+ MiniProgramService,
|
|
|
+ WechatService,
|
|
|
+ FormBuilder as Form,
|
|
|
+ CacheService,
|
|
|
+ UtilService as Util};
|
|
|
+use think\facade\Route as Url;
|
|
|
+use think\facade\Validate;
|
|
|
+Use app\admin\model\water\WaterDefault as model;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 订单管理控制器 同一个订单表放在一个控制器
|
|
|
+ * Class StoreOrder
|
|
|
+ * @package app\admin\controller\store
|
|
|
+ */
|
|
|
+class WaterDefault extends AuthController
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ return $this->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public function list()
|
|
|
+ {
|
|
|
+ $where = Util::getMore([
|
|
|
+ ['page', 1],
|
|
|
+ ['limit', 20],
|
|
|
+ ['name', ''],
|
|
|
+ ['card', ''],
|
|
|
+ ['order_id', ''],
|
|
|
+ ]);
|
|
|
+
|
|
|
+ return Json::successlayui(model::list($where));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示创建资源表单页.
|
|
|
+ *
|
|
|
+ * @return \think\Response
|
|
|
+ */
|
|
|
+ public function create($id = 0)
|
|
|
+ {
|
|
|
+ $f = [];
|
|
|
+ $f[] = Form::input('high', '高度')->col(12);
|
|
|
+ $f[] = Form::select('roof', '顶板', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('floor', '底板', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('column', '立柱', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+
|
|
|
+ $f[] = Form::select('side_plate1', '侧板1', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('side_plate2', '侧板2', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('side_plate3', '侧板3', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('side_plate4', '侧板4', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('side_plate5', '侧板5', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+
|
|
|
+ $f[] = Form::select('lacing1', '拉筋1', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('lacing2', '拉筋2', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('lacing3', '拉筋3', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('lacing4', '拉筋4', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('lacing5', '拉筋5', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+
|
|
|
+ $f[] = Form::select('fula1', '辅拉1', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('fula2', '辅拉2', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('fula3', '辅拉3', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('fula4', '辅拉4', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::select('fula5', '辅拉5', 0)->options(
|
|
|
+ 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())
|
|
|
+ )->filterable(true);
|
|
|
+
|
|
|
+ $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
|
|
|
+ $this->assign(compact('form'));
|
|
|
+ return $this->fetch('public/form-builder');
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function save()
|
|
|
+ {
|
|
|
+ $model = new model;
|
|
|
+ $data = Util::postMore([
|
|
|
+ 'high',
|
|
|
+ 'roof',
|
|
|
+ 'floor',
|
|
|
+ 'column',
|
|
|
+ 'side_plate1',
|
|
|
+ 'side_plate2',
|
|
|
+ 'side_plate3',
|
|
|
+ 'side_plate4',
|
|
|
+ 'side_plate5',
|
|
|
+ 'lacing1',
|
|
|
+ 'lacing2',
|
|
|
+ 'lacing3',
|
|
|
+ 'lacing4',
|
|
|
+ 'lacing5',
|
|
|
+ 'fula1',
|
|
|
+ 'fula2',
|
|
|
+ 'fula3',
|
|
|
+ 'fula4',
|
|
|
+ 'fula5',
|
|
|
+ ]);
|
|
|
+ $validate = Validate::rule([
|
|
|
+ 'high' => 'require',
|
|
|
+ 'roof' => 'require',
|
|
|
+ 'floor' => 'require',
|
|
|
+ 'column' => 'require',
|
|
|
+ 'side_plate1' => 'require',
|
|
|
+ 'lacing1' => 'require',
|
|
|
+ 'fula1' => 'require',
|
|
|
+ ]);
|
|
|
+ $validate->message([
|
|
|
+ 'high.require' => '高度不能为空',
|
|
|
+ 'roof.require' => '请选择顶板',
|
|
|
+ 'floor.require' => '请选择底板',
|
|
|
+ 'column.require' => '请填写立柱',
|
|
|
+ 'side_plate1.require' => '最少填写侧板1',
|
|
|
+ 'lacing1.require' => '最少填写拉筋1',
|
|
|
+ 'fula1.require' => '最少填写辅拉1',
|
|
|
+ ]);
|
|
|
+ if ($data['side_plate1'] > 0) $data['side_plate'] = $data['side_plate1'];
|
|
|
+ if ($data['side_plate2'] > 0) $data['side_plate'] .= ','.$data['side_plate2'];
|
|
|
+ if ($data['side_plate3'] > 0) $data['side_plate'] .= ','.$data['side_plate3'];
|
|
|
+ if ($data['side_plate4'] > 0) $data['side_plate'] .= ','.$data['side_plate4'];
|
|
|
+ if ($data['side_plate5'] > 0) $data['side_plate'] .= ','.$data['side_plate5'];
|
|
|
+
|
|
|
+ if ($data['lacing1'] > 0) $data['lacing'] = $data['lacing1'];
|
|
|
+ if ($data['lacing2'] > 0) $data['lacing'] .= ','.$data['lacing2'];
|
|
|
+ if ($data['lacing3'] > 0) $data['lacing'] .= ','.$data['lacing3'];
|
|
|
+ if ($data['lacing4'] > 0) $data['lacing'] .= ','.$data['lacing4'];
|
|
|
+ if ($data['lacing5'] > 0) $data['lacing'] .= ','.$data['lacing5'];
|
|
|
+
|
|
|
+ if ($data['fula1'] > 0) $data['fula'] = $data['fula1'];
|
|
|
+ if ($data['fula2'] > 0) $data['fula'] = $data['fula2'];
|
|
|
+ if ($data['fula3'] > 0) $data['fula'] = $data['fula3'];
|
|
|
+ if ($data['fula4'] > 0) $data['fula'] = $data['fula4'];
|
|
|
+ if ($data['fula5'] > 0) $data['fula'] = $data['fula5'];
|
|
|
+ if (!$validate->check($data)) {
|
|
|
+ return Json::fail($validate->getError());
|
|
|
+ }
|
|
|
+ $res = $model->save($data);
|
|
|
+ if ($res) return Json::successful('添加成功');
|
|
|
+ return Json::fail('添加失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示创建资源表单页.
|
|
|
+ *
|
|
|
+ * @return \think\Response
|
|
|
+ */
|
|
|
+ public function edit($id = 0)
|
|
|
+ {
|
|
|
+ $data = model::find($id);
|
|
|
+ $f = [];
|
|
|
+ $f[] = Form::input('name', '名称', $data['name'])->col(12);
|
|
|
+ $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([
|
|
|
+ ['value' => 0, 'label' => '请选择分类'],
|
|
|
+ ['value' => 1, 'label' => '顶板'],
|
|
|
+ ['value' => 2, 'label' => '侧板'],
|
|
|
+ ['value' => 3, 'label' => '拉筋'],
|
|
|
+ ['value' => 4, 'label' => '底板'],
|
|
|
+ ])->filterable(true);
|
|
|
+ $f[] = Form::select('th_id', '选择厚度', (string)$data['th_id'])->options(
|
|
|
+ array_merge([['value' => 0, 'label' => '请选择分类']], \app\admin\model\water\WaterThickness::order('id DESC')->field('id as value,name as label')->select()->toArray())
|
|
|
+ )->filterable(true);
|
|
|
+ $f[] = Form::input('weight', '重量(kg)', $data['weight']);
|
|
|
+ $f[] = Form::input('unit_price', '单价', $data['unit_price']);
|
|
|
+ $f[] = Form::input('company', '单位', $data['company']);
|
|
|
+ $f[] = Form::input('long', '长', $data['long']);
|
|
|
+ $f[] = Form::input('wide', '宽', $data['wide']);
|
|
|
+ $f[] = Form::hidden('id', $id);
|
|
|
+ $form = Form::make_post_form('修改', $f, Url::buildUrl('update'));
|
|
|
+ $this->assign(compact('form'));
|
|
|
+ return $this->fetch('public/form-builder');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ * @return void
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function update()
|
|
|
+ {
|
|
|
+ $model = new model;
|
|
|
+ $data = Util::postMore([
|
|
|
+ 'name',
|
|
|
+ 'type',
|
|
|
+ 'th_id',
|
|
|
+ 'weight',
|
|
|
+ 'unit_price',
|
|
|
+ 'company',
|
|
|
+ 'long',
|
|
|
+ 'wide',
|
|
|
+ 'id',
|
|
|
+ ]);
|
|
|
+ $validate = Validate::rule('name', 'require')->rule([
|
|
|
+ 'name' => 'require',
|
|
|
+ 'type' => 'require',
|
|
|
+ 'th_id' => 'require',
|
|
|
+ 'weight' => 'require',
|
|
|
+ 'unit_price' => 'require',
|
|
|
+ 'company' => 'require',
|
|
|
+ 'long' => 'require',
|
|
|
+ 'wide' => 'require',
|
|
|
+ ]);
|
|
|
+ $validate->message([
|
|
|
+ 'name.require' => '名称不能为空',
|
|
|
+ 'type.require' => '请选择分类',
|
|
|
+ 'th_id.require' => '请选择厚度',
|
|
|
+ 'weight.require' => '请填写重量',
|
|
|
+ 'unit_price.require' => '请填写单价',
|
|
|
+ 'company.require' => '请填写单位',
|
|
|
+ 'long.require' => '请填写长度',
|
|
|
+ 'wide.require' => '请填写宽度',
|
|
|
+ ]);
|
|
|
+ $details = $model->find($data['id']);
|
|
|
+ $details['name'] = $data['name'];
|
|
|
+ $details['thickness'] = $data['thickness'];
|
|
|
+ $res = $details->save();
|
|
|
+ if ($res) return Json::successful('修改成功');
|
|
|
+ return Json::fail('修改失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ * @param $id
|
|
|
+ * @return void
|
|
|
+ * @throws \Exception
|
|
|
+ */
|
|
|
+ public function delete($id)
|
|
|
+ {
|
|
|
+ if (!$id) Json::fail('删除失败');
|
|
|
+ $model = new model;
|
|
|
+
|
|
|
+ $res = model::destroy($id);
|
|
|
+ if ($res){
|
|
|
+ return Json::success('删除成功!');
|
|
|
+ }else{
|
|
|
+ return Json::fail($model->getErrorInfo());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|