VersionLogic.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\admin\logic;
  3. use app\model\CommonModel;
  4. use app\model\VersionModel;
  5. use think\facade\Db;
  6. use think\response\Json;
  7. class VersionLogic extends BaseLogic
  8. {
  9. public static function lastVersion(): Json
  10. {
  11. //最新版本信息
  12. $version = VersionModel::order("addtime desc")
  13. ->findOrEmpty()
  14. ->toArray();
  15. return json_show(CommonModel::$success, '获取成功', $version);
  16. }
  17. //获取版本列表
  18. public static function getList(array $data = []): Json
  19. {
  20. $where = [];
  21. if ($data['keyword'] != '') $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  22. $count = Db::name("version")
  23. ->where($where)
  24. ->count('id');
  25. $list = VersionModel::where($where)
  26. ->page($data['page'], $data['size'])
  27. ->order(['addtime' => 'desc'])
  28. ->select()
  29. ->toArray();
  30. return json_show(CommonModel::$success, '获取成功', ['list' => $list, 'count' => $count]);
  31. }
  32. //新增版本
  33. public static function create(array $data = []): Json
  34. {
  35. $data = [
  36. "title" => $data['title'],
  37. "content" => $data['content'],
  38. "version" => $data['version'],
  39. "addtime" => date("Y-m-d H:i:s")
  40. ];
  41. $inert = VersionModel::create($data)->save();
  42. //write_log("版本{$version}新建成功", $this->userinfo, "version", "add");
  43. return $inert ? json_show(CommonModel::$success, '版本信息新建成功') : json_show(CommonModel::$error_param, '版本信息新建失败');
  44. }
  45. }