AppletVersionService.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\service\admin\applet;
  12. use app\dict\applet\AppletlDict;
  13. use app\dict\sys\FileDict;
  14. use app\model\applet\AppletVersion;
  15. use app\service\core\applet\CoreAppletVersionService;
  16. use app\service\core\upload\CoreUploadService;
  17. use core\base\BaseAdminService;
  18. use Exception;
  19. /**
  20. * 文章服务层
  21. * Class ArticleService
  22. * @package app\service\admin\article
  23. */
  24. class AppletVersionService extends BaseAdminService
  25. {
  26. protected $core_applet_version_service;
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. $this->model = new AppletVersion();
  31. $this->core_applet_version_service = new CoreAppletVersionService;
  32. }
  33. /**
  34. * 获取列表
  35. * @param array $where
  36. * @return array
  37. */
  38. public function getPage(array $where = [])
  39. {
  40. return $this->core_applet_version_service->getPage($where);
  41. }
  42. /**
  43. * 获取信息
  44. * @param int $id
  45. * @return array
  46. */
  47. public function getInfo(int $id)
  48. {
  49. return $this->core_applet_version_service->getInfo($id);
  50. }
  51. /**
  52. * 添加
  53. * @param array $data
  54. * @return true
  55. */
  56. public function add(array $data)
  57. {
  58. $data['version_num'] = version_to_int($data['version']);//版本号数字
  59. $data['uid'] = $this->uid;//发布者
  60. $data['status'] = AppletlDict::OFF;
  61. $this->model->create($data);
  62. return true;
  63. }
  64. /**
  65. * 上传小程序包
  66. * @param $file
  67. * @return array
  68. * @throws Exception
  69. */
  70. public function upload($file){
  71. $core_upload_service = new CoreUploadService();
  72. $type = FileDict::APPLET;
  73. $dir = '/applet/'.$type.'/version/';
  74. return $core_upload_service->document($file, $this->site_id, $type, $dir, FileDict::LOCAL);
  75. }
  76. /**
  77. * 设置版本状态
  78. * @param int $id
  79. * @param $status
  80. * @return true
  81. */
  82. public function setStatus(int $id, $status){
  83. $data = array(
  84. 'status' => $status
  85. );
  86. $where = array(
  87. ['id', '=', $id]
  88. );
  89. $this->model->where($where)->update($data);
  90. return true;
  91. }
  92. /**
  93. * 编辑
  94. * @param int $id
  95. * @param array $data
  96. * @return true
  97. */
  98. public function edit(int $id, array $data)
  99. {
  100. $data['version_num'] = version_to_int($data['version']);//版本号数字
  101. $data['status'] = AppletlDict::OFF;
  102. $data['update_time'] = time();
  103. $this->model->where([['id', '=', $id]])->create($data);
  104. return true;
  105. }
  106. /**
  107. * 删除
  108. * @param int $id
  109. * @return true
  110. */
  111. public function del(int $id){
  112. $this->model->where([['id', '=', $id]])->delete();
  113. return true;
  114. }
  115. }