[], 'allow' => ['index', 'read', 'save', 'update', 'delete'] ]; Hook::listen('check_auth',$action); $request = Request::instance(); $a = strtolower($request->action()); if (!in_array($a, $action['permission'])) { parent::_initialize(); } else { $param = Request::instance()->param(); $this->param = $param; } } /** * 列表 * * @param InvoiceInfoLogic $invoiceInfoLogic * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function index(InvoiceInfoLogic $invoiceInfoLogic) { $data = $invoiceInfoLogic->index($this->param); return resultArray(['data' => $data]); } /** * 详情 * * @param InvoiceInfoLogic $invoiceInfoLogic * @return \think\response\Json * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function read(InvoiceInfoLogic $invoiceInfoLogic) { if (empty($this->param['info_id'])) return resultArray(['error' => '参数错误']); $data = $invoiceInfoLogic->read($this->param['info_id']); return resultArray(['data' => $data]); } /** * 创建 * * @param InvoiceInfoLogic $invoiceInfoLogic * @return \think\response\Json */ public function save(InvoiceInfoLogic $invoiceInfoLogic) { if (empty($this->param['customer_id'])) return resultArray(['error' => '请选择客户!']); $param = $this->param; $userInfo = $this->userInfo; $param['user_id'] = $userInfo['id']; if (!$invoiceInfoLogic->save($param)) return resultArray(['error' => '操作失败!']); return resultArray(['data' => '操作成功!']); } /** * 编辑 * * @param InvoiceInfoLogic $invoiceInfoLogic * @return \think\response\Json * @throws \think\Exception * @throws \think\exception\PDOException */ public function update(InvoiceInfoLogic $invoiceInfoLogic) { if (empty($this->param['info_id'])) return resultArray(['error' => '参数错误!']); if (!$invoiceInfoLogic->update($this->param)) return resultArray(['error' => '操作失败!']); return resultArray(['data' => '操作成功!']); } /** * 删除 * * @param InvoiceInfoLogic $invoiceInfoLogic * @return \think\response\Json * @throws \think\Exception * @throws \think\exception\PDOException */ public function delete(InvoiceInfoLogic $invoiceInfoLogic) { if (empty($this->param['info_id'])) return resultArray(['error' => '参数错误!']); if (!$invoiceInfoLogic->delete($this->param['info_id'])) return resultArray(['error' => '操作失败!']); return resultArray(['data' => '操作成功!']); } }