# 服务层源码示例 截取部分源码 ~~~ <?php /** * Created by PhpStorm. * User: Mikkle * QQ:776329498 * Date: 2017/11/18 * Time: 11:49 */ namespace app\base\service\app; use app\base\service\base\ServiceBase; use app\base\service\center\OptionsCenter; use mikkle\tp_tools\ShowCode; use app\base\model\terminal\Terminal as TerminalModel; class Terminal extends ServiceBase { public function _initialize() { $this->model = new TerminalModel(); } public function terminalRegister($data){ $this->functionName = __FUNCTION__; $this->args = $data; if (empty($data[OptionsCenter::$fieldTerminalCode])){ $this->addError( "设备码参数丢失"); return ShowCode::jsonCodeWithoutData(1003,$this->error); }; $map = [ OptionsCenter::$fieldTerminalCode =>$data[OptionsCenter::$fieldTerminalCode], ]; $terminal = $this->getInfoObject($map); if (empty($terminal)){ $this->addError ("设备码不存在"); return ShowCode::jsonCodeWithoutData(1010,$this->error ); } if ((int)$terminal[OptionsCenter::$fieldTerminalStatus] == 0){ $this->addError ("设备未使用状态"); return ShowCode::jsonCodeWithoutData(1010,$this->error); } switch (true) { case (empty($terminal[OptionsCenter::$fieldTerminalMac])): $terminal->save([OptionsCenter::$fieldTerminalMac => $data[OptionsCenter::$fieldTerminalMac]]); return ShowCode::jsonCode(1001, ["type" => "add"], "设备添加成功"); break; case ($terminal[OptionsCenter::$fieldTerminalMac] == $data[OptionsCenter::$fieldTerminalMac]): return ShowCode::jsonCode(1001, ["type" => "reg"], "设备注册成功"); break; default: $this->addError ( "设备机身码不符"); return ShowCode::jsonCode(1001, ["type" => "differ"], "设备机身码不符"); } } public function terminalSign($data){ $this->functionName = __FUNCTION__; $this->args = $data; if (empty($data[OptionsCenter::$fieldTerminalMac])){ $this->addError ( "设备终端号参数丢失"); return ShowCode::jsonCodeWithoutData(1003,$this->error); }; $map = [ OptionsCenter::$fieldTerminalMac=>$data[OptionsCenter::$fieldTerminalMac], ]; $terminal = $this->getInfoArray($map); if (empty($terminal)){ $this->addError ( "设备不存在"); return ShowCode::jsonCodeWithoutData(1010,$this->error ); } if ((int)$terminal["terminal_status"] == 0){ $this->addError ( "设备未使用状态"); return ShowCode::jsonCodeWithoutData(1010,"设备未使用状态"); } $result["park_list"]=$this->model->getTerminalParkList($terminal[OptionsCenter::$pk]); return ShowCode::jsonCode(1001,$result); } } ~~~