$length) { return mb_substr($string, 0, $length) . '...'; // 添加省略号 } return $string; } private function _filter($oBladeRow) { $oBladeRow->content = $this->subStr($oBladeRow->content); unset($oBladeRow->id); return $oBladeRow; } private function filter($oBlade, $sMod = "row") { if ($sMod == "row") { $oBlade = $this->_filter($oBlade); } else if ($sMod == "list") { foreach ($oBlade as &$oBladeRow) { $oBladeRow = $this->_filter($oBladeRow); } } return $oBlade; } public function List() { $oBlade = ModelBlade::all(); $oBlade = $this->filter($oBlade, "list"); return $this->toJson($oBlade); } public function Find($aParam) { $sField = $aParam["aOption"][1] ?? "id"; $sValue = $aParam["aArg"][1] ?? false; if ($sValue == "?") { return "/blade#find__{field?} {value}"; } $oBlade = ModelBlade::where($sField, $sValue)->first(); return $this->toJson($oBlade); } public function Content($aParam) { $sField = $aParam["aOption"][1] ?? "code"; $sValue = $aParam["aArg"][1] ?? false; if ($sValue == "?") { return "/blade#content__{field?} {value}"; } $oBlade = ModelBlade::where($sField, $sValue)->first(); return $oBlade->content; } public function Like($aParam) { $sField = $aParam["aOption"][1] ?? false; $sValue = $aParam["aArg"][1] ?? false; if ($sValue == "?") { return "/blade#like__{field} {value}"; } if (!$sField) { return "需要field"; } if (!$sValue) { return "需要value"; } $oBlade = ModelBlade::where($sField, "like", "%".$sValue."%")->get(); $oBlade = $this->filter($oBlade); return $this->toJson($oBlade); } public function Add($aParam) { $sCode = $aParam["aArg"][1] ?? false; if ($sCode == "?") { return "/blade#add "; } if (!$sCode) { return "需要code"; } $bExists = ModelBlade::where("code", $sCode)->exists(); if ($bExists) { return "code以存在"; } $oBlade = new ModelBlade(); $oBlade->code = $sCode; $oBlade->save(); $aParam["aOption"][1] = "code"; $aParam["aArg"][1] = $sCode; return $this->Find($aParam); } public function Del($aParam) { $sCode = $aParam["aArg"][1] ?? false; $sWhereField = $aParam["aOption"][1] ?? false; if ($sCode == "?") { return "/blade#del__ "; } if (!$sCode) { return "需要code"; } $oBlade = ModelBlade::where("code", $sCode); if (!$oBlade->exists()) { return "没有这个code"; } $r = $oBlade->delete(); return $r; } public function Set($aParam) { $sSetValue = $aParam["aArg"] ?? false; $sSetValue = implode(" ", $sSetValue); if ($sSetValue == "?") { $tmp = "/blade#set______ "; $tmp .= "\n /blade#set____ "; return $tmp; } // 有第三参数说明是findSet模式 if (isset($aParam["aOption"][3])) { $sWhereField = $aParam["aOption"][1] ?? false; $sWhereValue = $aParam["aOption"][2] ?? false; $sSetField = $aParam["aOption"][3] ?? false; $sMod = "findSet"; } else { $sWhereField = "code"; $sWhereValue = $aParam["aOption"][1] ?? false; $sSetField = $aParam["aOption"][2] ?? false; $sMod = "set"; } if (!$sWhereField) { return "需要whereField"; } if (!$sWhereValue) { return "需要whereValue"; } if (!$sSetField) { return "需要setValue"; } $oBlade = ModelBlade::where($sWhereField, $sWhereValue)->get(); if ($oBlade->isEmpty()) { return "没找到这个blade"; } $i = 0; foreach ($oBlade as $oBladeRow) { $oBladeRow->$sSetField = $sSetValue; $oBladeRow->save(); $i++; } if ($i == 1) { $aParam["aOption"][1] = "code"; $aParam["aArg"][1] = $oBladeRow->code; return $this->find($aParam); } return "影响".$i."条数据"; } }