* @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\WaterCate as model; /** * 订单管理控制器 同一个订单表放在一个控制器 * Class StoreOrder * @package app\admin\controller\store */ class WaterCate extends AuthController { /** * @return mixed */ public function index() { return $this->fetch(); } public function list() { $where = Util::getMore([ ['page', 1], ['limit', 20], ['name', ''], ['role', ''], ['type', ''], ]); return Json::successlayui(model::list($where)); } /** * 显示创建资源表单页. * * @return \think\Response */ public function create($id = 0) { $f = []; $f[] = Form::input('name', '分类名称'); $f[] = Form::select('type', '选择分类', '')->options([ ['value' => 0, 'label' => '请选择分类'], ['value' => 1, 'label' => '顶板'], ['value' => 2, 'label' => '侧板'], ['value' => 3, 'label' => '拉筋'], ['value' => 4, 'label' => '底板'], ['value' => 5, 'label' => '立柱'], ['value' => 6, 'label' => '辅拉'], ['value' => 7, 'label' => '保温'], ['value' => 8, 'label' => '槽钢'], ['value' => 9, 'label' => '扶梯管'], ])->filterable(true); $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', 'is_gc', ]); $validate = Validate::rule([ 'name' => 'require', 'type' => 'require', ]); $validate->message([ 'name.require' => '名称不能为空', 'type.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']); $f[] = Form::select('type', '选择分类', (string)$data['type'])->options([ ['value' => 0, 'label' => '请选择分类'], ['value' => 1, 'label' => '顶板'], ['value' => 2, 'label' => '侧板'], ['value' => 3, 'label' => '拉筋'], ['value' => 4, 'label' => '底板'], ['value' => 5, 'label' => '立柱'], ['value' => 6, 'label' => '辅拉'], ['value' => 7, 'label' => '保温'], ['value' => 8, 'label' => '槽钢'], ['value' => 9, 'label' => '扶梯管'], ])->filterable(true); $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', 'type', 'id', 'is_gc' ]); $validate = Validate::rule([ 'title' => 'require', 'price' => 'require', ]); $validate->message([ 'name.require' => '名称不能为空', 'type.require' => '分类不能为空', ]); $details = $model->find($data['id']); $details['name'] = $data['name']; $details['type'] = $data['type']; $details['is_gc'] = $data['is_gc']; $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()); } } }