beforeInit($model); $this->zskkInit($model); $this->afterInit($model); } protected function beforeInit($model) {} protected function afterInit($model) {} protected function zskkInit($model) { if(is_null($model)) { return; } if(isset($model->code)) { $this->setCode($model->code); } if(isset($model->msg)) { $this->setMsg($model->msg); } if(isset($model->data)) { $this->setData($model->data); } if(isset($model->error)) { $this->setError($model->error); } } public function setData($data) { $this->data = $data; return $this; } /** * @return null */ public function getData() { return $this->data; } /** * @param null $error */ public function setError($error): void { $this->error = $error; } /** * @return null */ public function getError() { return $this->error; } public function setMsg(string $msg) { $this->msg = $msg; return $this; } /** * @return string */ public function getMsg(): string { return $this->msg; } /** * @param int $code */ public function setCode(int $code) { $this->code = $code; return $this; } /** * @return int */ public function getCode(): int { return $this->code; } protected function setResponse($code = 0, $msg = '', $data = null, $error = null) { $this->setCode($code); $this->setMsg($msg); $this->setData($data); $this->setError($error); return $this; } protected function generateResponse() { return [ "code" => $this->getCode(), "msg" => $this->getMsg(), "data" => $this->getData(), "error" => $this->getError(), ]; } }