* @day: 2017/11/11 */ namespace app\admin\controller\diagnosis; use app\admin\controller\AuthController; use app\admin\model\user\User; 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\diagnosis\DiagnosisApply as model; /** * 订单管理控制器 同一个订单表放在一个控制器 * Class StoreOrder * @package app\admin\controller\store */ class DiagnosisApply extends AuthController { /** * @return mixed */ public function index() { return $this->fetch(); } public function list() { $where = Util::getMore([ ['page', 1], ['limit', 20], ['name', ''], ['role', ''], ['type', ''], ['gc', ''], ]); return Json::successlayui(model::list($where)); } /** * 显示创建资源表单页. * * @return \think\Response */ public function create($id = 0) { $f = []; $f[] = Form::input('name', '名称')->required(); $f[] = Form::select('type', '选择类型', '')->options([ ['value' => 1, 'label' => '陪诊'], ['value' => 2, 'label' => '代办'], ])->filterable(true)->required(); $f[] = Form::input('price', '金额')->required(); $f[] = Form::radio('status', '状态', 1)->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', 'price', 'status', ]); $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::textarea('remarks', '备注'); $f[] = Form::radio('status', '状态', 1)->options([['value' => -1, '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([ 'remarks', 'status', 'id' ]); $details = $model->find($data['id']); $user = User::where('uid', $details['uid'])->find(); if ($data['status'] == -1){ if (empty($data['remarks'])){ return Json::fail('请填入备注'); } $details['remarks'] = $data['remarks']; }else{ if ($user['is_receiver'] == 1){ return Json::successful('用户已成为接单员'); } $user['is_receiver'] = 1; $user->save(); } $details['status'] = $data['status']; $res = $details->save(); if ($res) return Json::successful('成功'); return Json::fail('失败'); } /** * 删除 * @param $id * @return void * @throws \Exception */ public function delete($id) { if (!$id) return Json::fail('删除失败'); $model = new model; $res = model::destroy($id); if ($res){ return Json::success('删除成功!'); }else{ return Json::fail($model->getErrorInfo()); } } /** * 设置单个产品上架|下架 * * @return json */ public function set_show($is_show = '', $id = '') { ($is_show == '' || $id == '') && Json::fail('缺少参数'); $res = model::where(['id' => $id])->update(['status' => (int)$is_show]); if ($res) { return JsonService::successful($is_show == 1 ? '显示成功' : '隐藏成功'); } else { return JsonService::fail($is_show == 1 ? '显示失败' : '隐藏失败'); } } public function card($id) { $data = model::find($id); $images = json_decode($data['images']); $this->assign('images', $images); return $this->fetch(); } }