# DataEdit快捷操作类库 ### DataEdit快捷操作类库使用示范 此源码截取某项目APP接口部分 >[danger] DataEdit快捷类库支持链式操作 最新的类库支持指向的模型分层 该示例指向到service层方法 ~~~ <?php /** * Created by PhpStorm. * User: Mikkle * QQ:776329498 * Date: 2017/11/18 * Time: 10:08 */ namespace app\api\controller\app; use app\api\controller\base\Base; use app\base\service\center\OptionsCenter; use mikkle\tp_tools\DataEdit; use mikkle\tp_tools\ShowCode; use think\Exception; use think\Log; /** * @title 设备类接口 * @description * @group APP接口 * Class Terminal * @package app\api\controller\app */ class Terminal extends Base { /** * @title 设备注册 * @description 当状态1001时,返回的type值 reg:表示机身码和设备号和后台的吻合 add:表示机身码不存在并添加 differ:表示和后台数据不符 * @author Mikkle * @url /api/app.terminal/register * @method POST * @param_send name:terminal_mac type:string require:1 default: other:40字符以内 desc:设备机身码 * @param_send name:terminal_code type:int require:1 default:8888883020508882 other:8位数字 desc:设备号 * @param_return type:注册状态 */ public function register(){ try{ $operate = DataEdit::instance(); $result = $operate->setParameter([ OptionsCenter::$fieldTerminalCode =>"terminal_code/d", OptionsCenter::$fieldTerminalMac =>"terminal_mac", ])->setValidate(false) ->setModel("base/app/terminal") ->setModelType("service") ->execModelAction("terminalRegister"); if ($result===false){ throw new Exception($operate->getError()); } return $result; }catch (Exception $e){ Log::error($e->getMessage()); return ShowCode::jsonCodeWithoutData(1008,$e->getMessage()); } } /** * @title 设备签到 * @description * @author Mikkle * @url /api/app.terminal/sign * @method POST * @param_send name:terminal_mac type:string require:1 default:40字符以内 other: desc: * @param_return park_list:站点列表 */ public function sign(){ try{ $operate = DataEdit::instance(); $result = $operate->setParameter([ OptionsCenter::$fieldTerminalMac =>"terminal_mac", ])->setValidate(false) ->setModel("base/app/terminal") ->setModelType("service") ->execModelAction("terminalSign"); if ($result===false){ throw new Exception($operate->getError()); } return $result; }catch (Exception $e){ Log::error($e->getMessage()); return ShowCode::jsonCodeWithoutData(1008,$e->getMessage()); } } } ~~~ 更多示例 ~~~ /** *$paramList = [ "company" => "company/s", "address" => "address/s", "contacts" => "contacts/s", "jobs" => "jobs/s", "mobile" => "mobile/s", "tencent_code" => "tencent_code/s", "desc" => "desc/s", "event_key" => "event_key/n", ]; $validate_name = "base/system/SystemApply"; $model_name = 'base/system/SystemApply'; $re = DataEdit::instance() ->setParameter($paramList) ->setAppend(["append" => "this is append"]) ->setValidate($validate_name) ->setModel($model_name) ->save();; return $re ? ReturnCode::jsonCode(1001) : ReturnCode::jsonCode(1003); * ~~~ >[info] 类库源码 https://www.kancloud.cn/mikkle/thinkphp5_study/484720