AppVersionServices.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. $count = $this->dao->count(['platform' => $platform]);
  41. return compact('list', 'count');
  42. }
  43. /**
  44. * 添加版本表单
  45. * @return array
  46. * @throws \FormBuilder\Exception\FormBuilderException
  47. */
  48. public function createForm()
  49. {
  50. $field[] = Form::input('version', '版本号')->col(24);
  51. $field[] = Form::radio('platform', '平台类型', 1)->options([['label' => 'Android', 'value' => 1], ['label' => 'IOS', 'value' => 2]]);
  52. $field[] = Form::input('info', '版本介绍')->type('textarea');
  53. $field[] = Form::input('url', '下载链接');
  54. $field[] = Form::radio('is_force', '强制', 1)->options([['label' => '开启', 'value' => 1], ['label' => '关闭', 'value' => 0]]);
  55. return create_form('添加版本信息', $field, Url::buildUrl('/system/version_save'), 'POST');
  56. }
  57. /**
  58. * 保存数据
  59. * @param $id
  60. * @param $data
  61. * @return mixed
  62. */
  63. public function versionSave($id, $data)
  64. {
  65. if ($id) {
  66. $this->dao->update($id, $data);
  67. } else {
  68. $data['is_new'] = 1;
  69. $data['is_del'] = 0;
  70. $data['add_time'] = time();
  71. return $this->transaction(function () use ($data) {
  72. $this->dao->update(['platform' => $data['platform']], ['is_new' => 0]);
  73. return $this->dao->save($data);
  74. });
  75. }
  76. }
  77. /**
  78. * 获取系统下最新的版本信息
  79. * @param $platform
  80. * @return array
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\DbException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. */
  85. public function getNewInfo($platform)
  86. {
  87. $res = $this->dao->get(['platform' => $platform, 'is_new' => 1]);
  88. if ($res) {
  89. $res = $res->toArray();
  90. $res['time'] = date('Y-m-d H:i:s', $res['add_time']);
  91. return $res;
  92. } else {
  93. return [];
  94. }
  95. }
  96. }