AppVersionServices.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\system;
  13. use app\dao\system\AppVersionDao;
  14. use app\services\BaseServices;
  15. use crmeb\services\FormBuilder as Form;
  16. use think\facade\Route as Url;
  17. /**
  18. * Class AppVersionServices
  19. * @package app\services\system
  20. */
  21. class AppVersionServices extends BaseServices
  22. {
  23. /**
  24. * DiyServices constructor.
  25. * @param AppVersionDao $dao
  26. */
  27. public function __construct(AppVersionDao $dao)
  28. {
  29. $this->dao = $dao;
  30. }
  31. /**
  32. * 版本列表
  33. * @param $platform
  34. * @return array
  35. */
  36. public function versionList($platform)
  37. {
  38. [$page, $limit] = $this->getPageValue();
  39. $list = $this->dao->versionList($platform, $page, $limit);
  40. foreach ($list as &$item) {
  41. $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
  42. }
  43. $count = $this->dao->count(['platform' => $platform]);
  44. return compact('list', 'count');
  45. }
  46. /**
  47. * 添加版本表单
  48. * @return array
  49. * @throws \FormBuilder\Exception\FormBuilderException
  50. */
  51. public function createForm($id = 0)
  52. {
  53. if ($id) {
  54. $info = $this->dao->get($id);
  55. }
  56. $field[] = Form::hidden('id', $info['id'] ?? 0);
  57. $field[] = Form::input('version', '版本号', $info['version'] ?? '')->col(24);
  58. $field[] = Form::radio('platform', '平台类型', $info['platform'] ?? 1)->options([['label' => 'Android', 'value' => 1], ['label' => 'IOS', 'value' => 2]]);
  59. $field[] = Form::input('info', '版本介绍', $info['info'] ?? '')->type('textarea');
  60. $field[] = Form::input('url', '下载链接', $info['url'] ?? '')->appendRule('suffix', [
  61. 'type' => 'div',
  62. 'class' => 'tips-info',
  63. 'domProps' => ['innerHTML' => '填写下载链接,Android的为压缩包的url地址,点击升级会自动下载压缩包替换安装,例如:域名/xxx.zip;IOS的为应用商店链接地址,直接跳转AppStore,例如:itms-apps://itunes.apple.com/cn/app/id1234567890']
  64. ]);
  65. $field[] = Form::radio('is_force', '强制', $info['is_force'] ?? 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  66. $field[] = Form::radio('is_new', '是否最新', $info['is_new'] ?? 1)->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]]);
  67. return create_form('添加版本信息', $field, Url::buildUrl('/system/version_save'), 'POST');
  68. }
  69. /**
  70. * 保存数据
  71. * @param $id
  72. * @param $data
  73. * @return mixed
  74. */
  75. public function versionSave($id, $data)
  76. {
  77. if ($id) {
  78. return $this->transaction(function () use ($data, $id) {
  79. if ($data['is_new']) {
  80. $this->dao->update(['platform' => $data['platform']], ['is_new' => 0]);
  81. }
  82. return $this->dao->update($id, $data);
  83. });
  84. } else {
  85. $data['is_del'] = 0;
  86. $data['add_time'] = time();
  87. return $this->transaction(function () use ($data) {
  88. $this->dao->update(['platform' => $data['platform']], ['is_new' => 0]);
  89. return $this->dao->save($data);
  90. });
  91. }
  92. }
  93. /**
  94. * 获取系统下最新的版本信息
  95. * @param $platform
  96. * @return array
  97. * @throws \think\db\exception\DataNotFoundException
  98. * @throws \think\db\exception\DbException
  99. * @throws \think\db\exception\ModelNotFoundException
  100. */
  101. public function getNewInfo($platform)
  102. {
  103. $res = $this->dao->get(['platform' => $platform, 'is_new' => 1]);
  104. if ($res) {
  105. $res = $res->toArray();
  106. $res['time'] = date('Y-m-d H:i:s', $res['add_time']);
  107. return $res;
  108. } else {
  109. return [];
  110. }
  111. }
  112. }