12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace app\admin\service\platform;
- use app\admin\service\Service;
- use app\common\models\Attachments;
- use app\common\models\Version as VersionModel;
- class Version extends Service {
-
- public static function getList($data,$condition=[]){
- return [
- "count"=>VersionModel::where($condition)->count(),
- "data"=>VersionModel::where($condition)->page($data["page"]??1,$data["limit"]??10)->order("id",'desc')->select()->toArray()
- ];
- }
-
- public static function detail($data){
- return [
- "data"=>VersionModel::where("id",$data["id"]??0)->find(),
- "type"=>$data["type"]??1
- ];
- }
-
- public static function save($data=[]){
- if(!empty($data["id"])){
- $obj = VersionModel::where("id",$data["id"])->find();
- if($data["url"] != $obj["url"]){
- if(Attachments::where("path",$obj["url"])->delete()){
- $file = trim($obj["url"],"/");
- file_exists($file) && unlink($file);
- }
- }
- return VersionModel::where("id",$data["id"])->save($data);
- }else{
- return VersionModel::create($data);
- }
- }
-
- public static function delete($id){
- $row = VersionModel::where('id',$id)->find();
- if(empty($row)){
- throw new \Exception("您要查找的数据不存在!",0);
- }
- if(Attachments::where("path",$row["url"])->delete()){
- $file = trim($row["url"],"/");
- file_exists($file) && unlink($file);
- }
- return VersionModel::where("id",$id)->delete();
- }
- }
|