Compare commits

...

2 Commits

Author SHA1 Message Date
weiz e66183a964 Merge pull request '新增版本管理' (#3) from dev into master
Reviewed-on: #3
2023-12-04 10:04:18 +08:00
weiz 416b01bb0c 新增版本管理 2023-12-04 10:03:10 +08:00
5 changed files with 361 additions and 0 deletions

View File

@ -0,0 +1,92 @@
<?php
namespace app\adminapi\controller;
use app\adminapi\lists\AppUpdateLists;
use app\adminapi\logic\AppUpdateLogic;
use app\adminapi\validate\AppUpdateValidate;
use think\response\Json;
/**
* app更新控制器
* Class AppUpdateController
* @package app\adminapi\controller
*/
class AppUpdateController extends BaseAdminController
{
/**
* @notes 获取app更新列表
* @return Json
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function lists(): Json
{
return $this->dataLists(new AppUpdateLists());
}
/**
* @notes 添加app更新
* @return Json
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function add(): Json
{
$params = (new AppUpdateValidate())->post()->goCheck('add');
$result = AppUpdateLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(AppUpdateLogic::getError());
}
/**
* @notes 编辑app更新
* @return Json
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function edit(): Json
{
$params = (new AppUpdateValidate())->post()->goCheck('edit');
$result = AppUpdateLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(AppUpdateLogic::getError());
}
/**
* @notes 删除app更新
* @return Json
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function delete(): Json
{
$params = (new AppUpdateValidate())->post()->goCheck('delete');
AppUpdateLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取app更新详情
* @return Json
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function detail(): Json
{
$params = (new AppUpdateValidate())->goCheck('detail');
$result = AppUpdateLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace app\adminapi\lists;
use app\common\model\AppUpdate;
use app\common\lists\ListsSearchInterface;
/**
* app更新列表
* Class AppUpdateLists
* @package app\adminapi\lists
*/
class AppUpdateLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function setSearch(): array
{
return [
'=' => ['title', 'content', 'type', 'version', 'dow_url', 'force', 'quiet'],
];
}
/**
* @notes 获取app更新列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function lists(): array
{
return AppUpdate::where($this->searchWhere)
->field(['id', 'title', 'content', 'type', 'version', 'dow_url', 'force', 'quiet', 'create_time', 'update_time'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取app更新数量
* @return int
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function count(): int
{
return AppUpdate::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace app\adminapi\logic;
use app\common\model\AppUpdate;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* app更新逻辑
* Class AppUpdateLogic
* @package app\adminapi\logic
*/
class AppUpdateLogic extends BaseLogic
{
/**
* @notes 添加app更新
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/31 11:08
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
AppUpdate::create([
'title' => $params['title'],
'content' => $params['content'],
'type' => $params['type'],
'version' => $params['version'],
'dow_url' => $params['dow_url'],
'force' => $params['force'],
'quiet' => $params['quiet']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑app更新
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/31 11:08
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
AppUpdate::where('id', $params['id'])->update([
'title' => $params['title'],
'content' => $params['content'],
'type' => $params['type'],
'version' => $params['version'],
'dow_url' => $params['dow_url'],
'force' => $params['force'],
'quiet' => $params['quiet'],
'update_time'=>time()
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除app更新
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/08/31 11:08
*/
public static function delete(array $params): bool
{
return AppUpdate::destroy($params['id']);
}
/**
* @notes 获取app更新详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/08/31 11:08
*/
public static function detail($params): array
{
return AppUpdate::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,89 @@
<?php
namespace app\adminapi\validate;
use app\common\validate\BaseValidate;
/**
* app更新验证器
* Class AppUpdateValidate
* @package app\adminapi\validate
*/
class AppUpdateValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'title' => 'require',
'content' => 'require',
'type' => 'require',
'version' => 'require',
'dow_url' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'title' => '标题',
'content' => '内容',
'type' => '1ios 2安卓',
'version' => '版本',
'dow_url' => 'app链接',
];
/**
* @notes 添加场景
* @return AppUpdateValidate
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function sceneAdd()
{
return $this->only(['title','content','type','version','dow_url']);
}
/**
* @notes 编辑场景
* @return AppUpdateValidate
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function sceneEdit()
{
return $this->only(['id','title','content','type','version','dow_url']);
}
/**
* @notes 删除场景
* @return AppUpdateValidate
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return AppUpdateValidate
* @author likeadmin
* @date 2023/08/31 11:08
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace app\common\model;
use think\model\concern\SoftDelete;
/**
* app更新模型
* Class AppUpdate
* @package app\common\model
*/
class AppUpdate extends BaseModel
{
use SoftDelete;
protected $name = 'app_update';
protected string $deleteTime = 'delete_time';
}