* @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()); } } }