first commit

This commit is contained in:
编码猿
2024-09-27 01:32:49 +08:00
commit 28ebe05a64
7399 changed files with 1174529 additions and 0 deletions

View File

@@ -0,0 +1,95 @@
<?php
/**
* 模型基础数据服务
* Class ModelService
* @package service
*/
namespace app\admin\service;
use think\Model;
class ModelService extends Model {
/**
* 主键定义
* @var string
*/
protected $pk = 'id';
/**
* 格式化分页
* @param array $query 分页参数 ['word' => $word]
*/
public function formatQuery($query = []) {
$format_query = [
'query' => [],
];
foreach ($query as $k => $val) {
$format_query['query'] = [$k, $val];
}
return $format_query;
}
/**
* 修改字段值
* @param $update
* @return \think\response\Json
*/
public static function editField($update) {
$data = self::where('id', $update['id'])->update([$update['field'] => $update['value']]);
if ($data == 1) {
return __success('修改成功!');
} else {
return __error('数据没有修改!');
}
}
/**
* 新增
* @param $post
* @return \think\response\Json
* @throws \think\exception\PDOException
*/
public static function addData($post) {
try {
self::insert($post);
} catch (\Exception $e) {
return __error($e->getMessage());
}
return __success('添加成功');
}
/**
* 修改
* @param $post
* @return \think\response\Json
*/
public static function editData($post) {
try {
self::where('id', $post['id'])->update($post);
} catch (\Exception $e) {
return __error($e->getMessage());
}
return __success('修改成功');
}
/**
* 软删除操作
* @param $id 列ID
* @param bool $type 删除类型 false:软删除true:真实删除)
* @return bool|ModelService
* @throws \Exception
*/
public function delData($id, $type = false) {
is_array($id) ? $model = self::whereIn('id', $id) : $model = self::where('id', $id);
$del = $model->delete();
if ($del >= 1) return __success('删除成功');
return __error('删除失败,请检查!');
}
}