Commit 259c5345 authored by rlgy's avatar rlgy

app版本管理

parent 01021167
...@@ -20,14 +20,73 @@ class AppController extends BaseController ...@@ -20,14 +20,73 @@ class AppController extends BaseController
Yii::$app->response->format = 'json'; Yii::$app->response->format = 'json';
$request = Yii::$app->request; $request = Yii::$app->request;
$type = $request->get('type', '0');
$page = $request->get('page', 1); $page = $request->get('page', 1);
$limit = $request->get('limit', 10); $limit = $request->get('limit', 10);
$type = $request->get('type', [1, 2, 3]);
$where = []; $where = [];
$where[] = ['type' => $type]; $where[] = ['in', 'type', $type];
$data = AppVersion::getList($page, $limit, $where); $data = AppVersion::getList($page, $limit, $where);
return $data; return $data;
} }
return $this->render('list'); return $this->render('list');
} }
/**
* 添加一个app版本
*/
public function actionAdd()
{
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
if ($id = Yii::$app->request->post('id')) {
$model = AppVersion::findOne($id);
$model->scenario = AppVersion::APP_UPDATE;
} else {
$model = new AppVersion();
$model->scenario = AppVersion::APP_ADD;
}
$post = array_filter(Yii::$app->request->post(), function ($item) {
return $item;
});
if ($model->load($post) && $model->validate()) {
if (!isset($post['id'])) {
$model->created_at = date('Y-m-d H:i:s');
}
$model->updated_at = date('Y-m-d H:i:s');
//更新日志使用json array
if (isset($post['log'])) {
$log_str = $post['log'];
$log_arr = explode("\n", $log_str);
$log_json = json_encode($log_arr);
$model->log = $log_json;
}
$model->save();
return ['code' => 0, 'msg' => 'succeed'];
}
$errors = $model->errors;
foreach ($errors as $error) {
return ['code' => 1, 'msg' => $error[0]];
}
}
}
/**
* @return array
* @throws \Throwable
* @throws \yii\db\StaleObjectException
*/
public function actionDelete()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id');
if ($id) {
$model = AppVersion::findOne($id);
if ($model) {
$model->delete();
return ['code' => 0, 'msg' => 'succeed'];
}
}
return ['code' => 1, 'msg' => 'failed'];
}
} }
\ No newline at end of file
...@@ -22,35 +22,43 @@ $this->registerJsFile('@web/js/app/index.js'); ...@@ -22,35 +22,43 @@ $this->registerJsFile('@web/js/app/index.js');
</ul> </ul>
<div class="layui-tab-content"> <div class="layui-tab-content">
<div class="layui-tab-item layui-show"> <div class="layui-tab-item layui-show">
<table class="layui-table" id="table1"></table> <table class="layui-table" id="table1" lay-filter="table"></table>
</div> </div>
<div class="layui-tab-item"> <div class="layui-tab-item">
<table class="layui-table" id="table2"></table> <table class="layui-table" id="table2" lay-filter="table"></table>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<!-- 添加页面 --> <!-- 添加页面 -->
<div class="layui-row add" style="display: none"> <div class="layui-row add" style="display: none;padding: 5px;">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11"> <div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form form_add" action="javascript:void(0)" method="post"> <form class="layui-form form_add" action="javascript:void(0)" method="post" lay-filter="form1">
<input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input type="hidden" name="id" value="">
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">类型</label> <label class="layui-form-label">类型</label>
<div class="layui-input-block"> <div class="layui-input-block">
<!-- <?= Html::dropDownList('type', null, <select name="type">
[1 => '安卓稳定版', 2 => '安卓公测版', 3 => '安卓内测版', 4 => 'IOS稳定版', 5 => 'IOS公测版', 6 => 'IOS内测版'], <option value="1">安卓稳定版</option>
['class' => 'my-select select-hand']) ?> --> <option value="2">安卓公测版</option>
<?= Html::dropDownList('type', null, [1 => '安卓稳定版', 4 => 'IOS稳定版', 7 => 'IOS商店版'], <option value="3">安卓内侧版</option>
['class' => 'my-select select-hand']) ?> <option value="4">IOS稳定版</option>
<option value="5">IOS公测版</option>
<option value="6">IOS内侧版</option>
</select>
</div> </div>
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">状态</label> <label class="layui-form-label">状态</label>
<div class="layui-input-block"> <div class="layui-input-block">
<!-- <?= Html::dropDownList('status', null, [1 => '上线', 2 => '推荐更新', 3 => '下线'], <select name="status">
['class' => 'my-select select-hand']) ?> --> <option value="1">上线</option>
<?= Html::dropDownList('status', null, [1 => '上线', 3 => '下线'], <option value="2">推荐升级</option>
['class' => 'my-select select-hand']) ?> <option value="3">下线</option>
<option value="4">强制更新</option>
</select>
</div> </div>
</div> </div>
<div class="layui-form-item layui-form-text"> <div class="layui-form-item layui-form-text">
...@@ -60,14 +68,22 @@ $this->registerJsFile('@web/js/app/index.js'); ...@@ -60,14 +68,22 @@ $this->registerJsFile('@web/js/app/index.js');
class="layui-input"> class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label" style="width: 100px;">版本代码</label>
<div class="layui-input-block">
<input type="text" name="version_code" required lay-verify="required" placeholder=""
autocomplete="off"
class="layui-input">
</div>
</div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label">下载链接</label> <label class="layui-form-label" style="width: 100px;">下载链接</label>
<div class="layui-input-block"> <div class="layui-input-block">
<input type="text" name="download_url" placeholder="" autocomplete="off" class="layui-input"> <input type="text" name="download_url" placeholder="" autocomplete="off" class="layui-input">
</div> </div>
</div> </div>
<div class="layui-form-item layui-form-text"> <div class="layui-form-item layui-form-text">
<label class="layui-form-label">更新日志</label> <label class="layui-form-label" style="width: 100px;">更新日志</label>
<div class="layui-input-block"> <div class="layui-input-block">
<textarea name="log" placeholder="请输入内容" class="layui-textarea"></textarea> <textarea name="log" placeholder="请输入内容" class="layui-textarea"></textarea>
</div> </div>
...@@ -83,7 +99,7 @@ $this->registerJsFile('@web/js/app/index.js'); ...@@ -83,7 +99,7 @@ $this->registerJsFile('@web/js/app/index.js');
</div> </div>
<script type="text/html" id="operTpl"> <script type="text/html" id="operTpl">
<a class="btn_edit"><i class="layui-icon">&#xe642;</i></a> <a class="btn_edit" lay-event="edit"><i class="layui-icon">&#xe642;</i></a>
<a class="btn_detail"><i class="layui-icon">&#xe60a;</i></a> <a class="btn_detail" lay-event="detail"><i class="layui-icon">&#xe60a;</i></a>
<a class="btn_delete"><i class="layui-icon" style="color: red">&#xe640;</i></a> <a class="btn_delete" lay-event="delete"><i class="layui-icon" style="color: red">&#xe640;</i></a>
</script> </script>
\ No newline at end of file
var table1 = layui.table; var table1 = layui.table;
var table2 = layui.table; var table2 = layui.table;
var form = layui.form;
var type = [ var type = [
{code: 0, name: ''}, {code: 0, name: ''},
{code: 1, name: '安卓稳定版'}, {code: 1, name: '安卓稳定版'},
...@@ -15,13 +15,14 @@ var vstatus = [ ...@@ -15,13 +15,14 @@ var vstatus = [
{code: 1, name: '上线'}, {code: 1, name: '上线'},
{code: 2, name: '推荐更新'}, {code: 2, name: '推荐更新'},
{code: 3, name: '下线'}, {code: 3, name: '下线'},
{code: 4, name: '强制更新'},
]; ];
var layer_add;
table1.render({ table1.render({
elem: '#table1', elem: '#table1',
page: 1, page: 1,
limit: 10, limit: 10,
where: {type: type[1].code}, where: {type: [1, 2, 3]},
url: '/admin/app/list', url: '/admin/app/list',
cols: [[ cols: [[
{field: 'id', title: '编号'}, {field: 'id', title: '编号'},
...@@ -42,7 +43,7 @@ table2.render({ ...@@ -42,7 +43,7 @@ table2.render({
elem: '#table2', elem: '#table2',
page: 1, page: 1,
limit: 10, limit: 10,
where: {type: type[4].code}, where: {type: [4, 5, 6]},
url: '/admin/app/list', url: '/admin/app/list',
cols: [[ cols: [[
{field: 'id', title: '编号'}, {field: 'id', title: '编号'},
...@@ -59,17 +60,102 @@ table2.render({ ...@@ -59,17 +60,102 @@ table2.render({
{title: '操作', templet: '#operTpl'}, {title: '操作', templet: '#operTpl'},
]] ]]
}); });
form.render();
layui.table.on('tool(table)', function (obj) {
var data = obj.data;
var event = obj.event;
if (event == 'delete') {
var ldelete = layer.confirm('确定要删除' + type[data.type].name + data.version + '?', {
icon: 3,
title: '删除'
}, function (index) {
$.get('/admin/app/delete', {id: data.id}, function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
obj.del();
layer.close(ldelete);
}
});
});
} else if (event == 'detail') {
before_show(data);
//禁用提交按钮
$("form button").css('display', 'none');
layer_add = layer.open({
type: 1,
title: '版本信息',
content: $('.add'), //这里content是一个普通的String
scrollbar: false,
area: '700px',
cancel: function (index, layero) {
after_close_add(false);
$("form button").css('display', '');
}
});
} else if (event == 'edit') {
before_show(data);
layer_add = layer.open({
type: 1,
title: '版本信息',
content: $('.add'), //这里content是一个普通的String
scrollbar: false,
area: '700px',
cancel: function (index, layero) {
after_close_add(false);
}
});
}
});
//添加图层 //添加图层
$(".btn_add").click(function(){ $(".btn_add").click(function () {
layer.open({ layer_add = layer.open({
type: 1, type: 1,
title: '版本信息', title: '版本信息',
content: $('.add'), //这里content是一个普通的String content: $('.add'), //这里content是一个普通的String
scrollbar: false, scrollbar: false,
area: '700px', area: '700px',
cancel: function(index, layero){ cancel: function (index, layero) {
$('.add').attr('style', 'display:none') after_close_add(false);
}
});
});
form.on('submit(formDemo)', function (data) {
$.post('/admin/app/add', data.field, function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
layer.close(layer_add);
after_close_add();
} }
}) });
}); return false;
\ No newline at end of file });
function after_close_add(reflush = true) {
if (reflush) {
table1.reload('table1', {});
table2.reload('table2', {});
}
$('.add').attr('style', 'display:none');
$('input[name="id"]').val('');
$('select[name="type"]').val(0);
$('select[name="status"]').val(0);
$('input[name="version"]').val('');
$('input[name="version_code"]').val('');
$('input[name="download_url"]').val('');
$('textarea[name="log"]').val('');
form.render();
}
function before_show(data) {
$('input[name="id"]').val(data.id);
$('select[name="type"]').val(data.type);
$('select[name="status"]').val(data.status);
$('input[name="version"]').val(data.version);
$('input[name="version_code"]').val(data.version_code);
$('input[name="download_url"]').val(data.download_url);
if (data.log) {
$('textarea[name="log"]').val(JSON.parse(data.log).join("\n"));
}
form.render();
}
\ No newline at end of file
...@@ -11,8 +11,24 @@ namespace common\models\pwallet; ...@@ -11,8 +11,24 @@ namespace common\models\pwallet;
use Yii; use Yii;
use common\core\BaseActiveRecord; use common\core\BaseActiveRecord;
/**
* Class AppVersion
* @property integer $id
* @property integer $status
* @property integer $type
* @property integer $version_code
* @property string $version
* @property string $download_url
* @property string $log
* @property string $created_at
* @property string $updated_at
* @package common\models\pwallet
*/
class AppVersion extends BaseActiveRecord class AppVersion extends BaseActiveRecord
{ {
const APP_ADD = 'add';
const APP_UPDATE = 'update';
/** /**
* @return null|object|\yii\db\Connection * @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException * @throws \yii\base\InvalidConfigException
...@@ -50,4 +66,45 @@ EOF; ...@@ -50,4 +66,45 @@ EOF;
return []; return [];
} }
} }
public function formName()
{
return '';
}
public function attributeLabels()
{
return [
'id' => 'ID',
'status' => '状态',
'type' => '类型',
'version_code' => '版本代码',
'version' => '版本号',
'download_url' => '下载地址',
'log' => '升级日志',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
public function rules()
{
return [
[['id', 'status', 'type', 'version_code'], 'integer'],
[['log', 'created_at', 'updated_at'], 'string'],
[['version'], 'string', 'max' => 17],
[['download_url'], 'string', 'max' => 255],
[['status', 'type', 'version_code', 'version', 'download_url'], 'required', 'on' => 'add'],
[['id', 'status', 'type', 'version_code', 'version', 'download_url'], 'required', 'on' => 'update']
];
}
public function scenarios()
{
return [
'add' => ['status', 'type', 'version_code', 'version', 'download_url', 'log'],
'update' => ['id', 'status', 'type', 'version_code', 'version', 'download_url', 'log']
];
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment