123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?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\WaterCardOrder as model;
- /**
- * 订单管理控制器 同一个订单表放在一个控制器
- * Class StoreOrder
- * @package app\admin\controller\store
- */
- class WaterCardOrder 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('name', '名称')->col(12);
- $f[] = Form::select('type', '选择分类', '')->options([
- ['value' => 0, 'label' => '请选择分类'],
- ['value' => 1, 'label' => '顶板'],
- ['value' => 2, 'label' => '侧板'],
- ['value' => 3, 'label' => '拉筋'],
- ['value' => 4, 'label' => '底板'],
- ])->filterable(true);
- $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');
- }
- public function save()
- {
- $model = new model;
- $data = Util::postMore([
- 'name',
- 'type',
- 'th_id',
- 'weight',
- 'unit_price',
- 'company',
- 'long',
- 'wide',
- ]);
- $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' => '请填写宽度',
- ]);
- 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());
- }
- }
- }
|