| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420 |
- <?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\WaterMaterialScience as model;
- /**
- * 订单管理控制器 同一个订单表放在一个控制器
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class WaterMaterialScience extends AuthController
- {
- /**
- * @return mixed
- */
- public function roof()
- {
- $this->assign('role', 'roof');
- return $this->fetch();
- }
- public function side_plate()
- {
- $this->assign('role', 'side_plate');
- return $this->fetch();
- }
- public function lacing()
- {
- $this->assign('role', 'lacing');
- return $this->fetch();
- }
- public function floor()
- {
- $this->assign('role', 'floor');
- return $this->fetch();
- }
- public function column()
- {
- $this->assign('role', 'column');
- return $this->fetch();
- }
- public function fula()
- {
- $this->assign('role', 'fula');
- return $this->fetch();
- }
- public function warm()
- {
- $this->assign('role', 'warm');
- return $this->fetch();
- }
- public function channel()
- {
- $this->assign('role', 'channel');
- return $this->fetch();
- }
- public function escalator()
- {
- $this->assign('role', 'escalator');
- return $this->fetch();
- }
- public function list()
- {
- $where = Util::getMore([
- ['page', 1],
- ['limit', 20],
- ['name', ''],
- ['role', '']
- ]);
- return Json::successlayui(model::list($where));
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create($id = 0, $role = 0)
- {
- if ($role == 'roof'){
- $type = 1;
- }elseif ($role == 'side_plate'){
- $type = 2;
- }elseif ($role == 'floor'){
- $type = 4;
- }else{
- return Json::fail('参数错误');
- }
- $f = [];
- $f[] = Form::input('name', '名称')->col(12);
- $f[] = Form::hidden('type', $type);
- $f[] = Form::select('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)');
- $f[] = Form::input('unit_price', '单价');
- $f[] = Form::input('company', '单位');
- $f[] = Form::input('long', '长');
- $f[] = Form::input('wide', '宽');
- $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function creates($id = 0, $role = 0)
- {
- if ($role == 'column'){
- $type = 5;
- }elseif ($role == 'fula'){
- $type = 6;
- }elseif ($role == 'lacing'){
- $type = 3;
- }else{
- return Json::fail('参数错误');
- }
- $f = [];
- $f[] = Form::input('name', '名称')->col(12);
- $f[] = Form::hidden('type', $type);
- $f[] = Form::select('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)');
- $f[] = Form::input('unit_price', '单价');
- $f[] = Form::input('company', '单位');
- $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create_warm($id = 0, $role = 0)
- {
- if ($role == 'warm'){
- $type = 7;
- }else{
- return Json::fail('参数错误');
- }
- $f = [];
- $f[] = Form::input('name', '名称')->col(12);
- $f[] = Form::hidden('type', $type);
- $f[] = Form::input('weight', '重量(kg)');
- $f[] = Form::input('unit_price', '单价');
- $f[] = Form::input('company', '单位');
- $f[] = Form::input('long', '长');
- $f[] = Form::input('wide', '宽');
- $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
- $form = Form::make_post_form('添加', $f, Url::buildUrl('save'));
- $this->assign(compact('form'));
- return $this->fetch('public/form-builder');
- }
- /**
- * 显示创建资源表单页.
- *
- * @return \think\Response
- */
- public function create_channel($id = 0, $role = 0)
- {
- if ($role == 'escalator'){
- $type = 9;
- }elseif ($role == 'channel'){
- $type = 8;
- }else{
- return Json::fail('参数错误');
- }
- $f = [];
- $f[] = Form::input('name', '名称')->col(12);
- $f[] = Form::hidden('type', $type);
- $f[] = Form::input('weight', '重量(kg)');
- $f[] = Form::input('unit_price', '单价');
- $f[] = Form::input('company', '单位');
- $f[] = Form::radio('is_gc', '公差', 0)->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
- $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([
- 'name',
- 'type',
- 'th_id',
- 'weight',
- 'unit_price',
- 'company',
- 'long',
- 'wide',
- 'is_gc'
- ]);
- $validate = Validate::rule('name', 'require')->rule([
- 'name' => 'require',
- 'type' => 'require',
- 'weight' => 'require',
- 'unit_price' => 'require',
- 'company' => 'require',
- ]);
- $validate->message([
- 'name.require' => '名称不能为空',
- 'type.require' => '请选择分类',
- 'weight.require' => '请填写重量',
- 'unit_price.require' => '请填写单价',
- 'company.require' => '请填写单位',
- ]);
- 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('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::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
- $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 \think\Response
- */
- public function edits($id = 0)
- {
- $data = model::find($id);
- $f = [];
- $f[] = Form::input('name', '名称', $data['name'])->col(12);
- $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::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
- $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 \think\Response
- */
- public function edit_warm($id = 0)
- {
- $data = model::find($id);
- $f = [];
- $f[] = Form::input('name', '名称', $data['name'])->col(12);
- $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::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
- $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 \think\Response
- */
- public function edit_channel($id = 0)
- {
- $data = model::find($id);
- $f = [];
- $f[] = Form::input('name', '名称', $data['name'])->col(12);
- $f[] = Form::input('weight', '重量(kg)', $data['weight']);
- $f[] = Form::input('unit_price', '单价', $data['unit_price']);
- $f[] = Form::input('company', '单位', $data['company']);
- $f[] = Form::radio('is_gc', '公差', $data['is_gc'])->options([['value' => 0, 'label' => '正常'], ['value' => 1, 'label' => '大公差']]);
- $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',
- 'th_id',
- 'weight',
- 'unit_price',
- 'company',
- 'long',
- 'wide',
- 'id',
- 'is_gc'
- ]);
- $validate = Validate::rule('name', 'require')->rule([
- 'name' => 'require',
- 'weight' => 'require',
- 'unit_price' => 'require',
- 'company' => 'require',
- ]);
- $validate->message([
- 'name.require' => '名称不能为空',
- 'type.require' => '请选择分类',
- 'weight.require' => '请填写重量',
- 'unit_price.require' => '请填写单价',
- 'company.require' => '请填写单位',
- ]);
- $details = $model->find($data['id']);
- $details['name'] = $data['name'];
- $details['th_id'] = $data['th_id'];
- $details['weight'] = $data['weight'];
- $details['unit_price'] = $data['unit_price'];
- $details['company'] = $data['company'];
- $details['is_gc'] = $data['is_gc'];
- $details['long'] = $data['long'];
- $details['wide'] = $data['wide'];
- $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());
- }
- }
- }
|