Commit 2bab81c8 authored by ZhuChunYang's avatar ZhuChunYang

update

parent 14eca0b1
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
namespace api\controllers; namespace api\controllers;
use api\base\BaseController; use api\base\BaseController;
use common\models\psources\CoinAppVersion;
use common\models\pwallet\AppVersion; use common\models\pwallet\AppVersion;
class AppController extends BaseController class AppController extends BaseController
...@@ -48,4 +49,28 @@ class AppController extends BaseController ...@@ -48,4 +49,28 @@ class AppController extends BaseController
$data['version_code']=(integer)$data['version_code']; $data['version_code']=(integer)$data['version_code'];
return $data; return $data;
} }
public function actionUpdateVersion()
{
$type = \Yii::$app->request->post('type', 1);
$platform_id = \Yii::$app->request->post('platform_id', 1);
$data = CoinAppVersion::getLastStable($type,$platform_id);
if ($data) {
$logItems = json_decode($data['log']);
$logstr = '';
foreach($logItems as $item){
if($logstr){
$logstr .="\n".$item;
}else{
$logstr = $item;
}
}
$data['log'] = $logstr;
$data['id']=(integer)$data['id'];
$data['status']=(integer)$data['status'];
$data['version_code']=(integer)$data['version_code'];
}
return $data;
}
} }
\ No newline at end of file
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
namespace backend\controllers; namespace backend\controllers;
use common\models\psources\CoinPlatform;
use common\models\psources\CoinAppVersion;
use Yii; use Yii;
use common\models\pwallet\AppVersion; use common\models\pwallet\AppVersion;
use yii\web\UploadedFile; use yii\web\UploadedFile;
...@@ -24,12 +26,15 @@ class AppController extends BaseController ...@@ -24,12 +26,15 @@ class AppController extends BaseController
$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]); $type = $request->get('type', [1, 2, 3]);
$platform_id = $request->get('platform_id', 1);
$where = []; $where = [];
$where[] = ['in', 'type', $type]; $where[] = ['in', 'type', $type];
$data = AppVersion::getList($page, $limit, $where); $where[] = ['platform_id' => $platform_id];
$data = CoinAppVersion::getList($page, $limit, $where);
return $data; return $data;
} }
return $this->render('list'); $platforms = CoinPlatform::find()->asArray()->all();
return $this->render('list',['platforms' => $platforms]);
} }
/** /**
...@@ -40,11 +45,11 @@ class AppController extends BaseController ...@@ -40,11 +45,11 @@ class AppController extends BaseController
if (Yii::$app->request->isPost) { if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json'; Yii::$app->response->format = 'json';
if ($id = Yii::$app->request->post('id')) { if ($id = Yii::$app->request->post('id')) {
$model = AppVersion::findOne($id); $model = CoinAppVersion::findOne($id);
$model->scenario = AppVersion::APP_UPDATE; $model->scenario = CoinAppVersion::APP_UPDATE;
} else { } else {
$model = new AppVersion(); $model = new CoinAppVersion();
$model->scenario = AppVersion::APP_ADD; $model->scenario = CoinAppVersion::APP_ADD;
} }
$post = array_filter(Yii::$app->request->post(), function ($item) { $post = array_filter(Yii::$app->request->post(), function ($item) {
return $item; return $item;
...@@ -81,7 +86,7 @@ class AppController extends BaseController ...@@ -81,7 +86,7 @@ class AppController extends BaseController
$id = Yii::$app->request->get('id'); $id = Yii::$app->request->get('id');
if ($id) { if ($id) {
$model = AppVersion::findOne($id); $model = CoinAppVersion::findOne($id);
if ($model) { if ($model) {
$model->delete(); $model->delete();
return ['code' => 0, 'msg' => 'succeed']; return ['code' => 0, 'msg' => 'succeed'];
......
...@@ -10,11 +10,21 @@ use yii\helpers\Html; ...@@ -10,11 +10,21 @@ use yii\helpers\Html;
use backend\assets\app\IndexAsset; use backend\assets\app\IndexAsset;
IndexAsset::register($this); IndexAsset::register($this);
?> ?>
<div class="layui-row"> <div class="layui-row">
<form class="layui-form" >
<div> <div>
<a class="layui-btn btn-primary btn_add">添加<i class="fa fa-plus"></i></a> <a class="layui-btn btn-primary btn_add">添加<i class="fa fa-plus"></i></a>
<div class="layui-inline">
<div class="layui-input-inline">
<select class="layui-select" name="platform_id" lay-filter="platform_change">
<?php foreach($platforms as $key => $value): ?>
<option value="<?= $value['id'] ?>"><?= $value['name'] ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div> </div>
</form>
<div class="layui-tab layui-tab-card"> <div class="layui-tab layui-tab-card">
<ul class="layui-tab-title"> <ul class="layui-tab-title">
<li class="layui-this">Android</li> <li class="layui-this">Android</li>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Time: 下午5:45 * Time: 下午5:45
*/ */
;?> ?>
<style type="text/css"> <style type="text/css">
.layui-form-label{ .layui-form-label{
......
...@@ -23,7 +23,7 @@ table1.render({ ...@@ -23,7 +23,7 @@ table1.render({
elem: '#table1', elem: '#table1',
page: 1, page: 1,
limit: 10, limit: 10,
where: {type: [1, 2, 3]}, where: {type: [1, 2, 3],platform_id: $("select[name='platform_id']").val()},
url: '/admin/app/list', url: '/admin/app/list',
cols: [[ cols: [[
{field: 'id', title: '编号'}, {field: 'id', title: '编号'},
...@@ -44,7 +44,7 @@ table2.render({ ...@@ -44,7 +44,7 @@ table2.render({
elem: '#table2', elem: '#table2',
page: 1, page: 1,
limit: 10, limit: 10,
where: {type: [4, 5, 6]}, where: {type: [4, 5, 6],platform_id: $("select[name='platform_id']").val()},
url: '/admin/app/list', url: '/admin/app/list',
cols: [[ cols: [[
{field: 'id', title: '编号'}, {field: 'id', title: '编号'},
...@@ -140,6 +140,8 @@ $(".btn_add").click(function () { ...@@ -140,6 +140,8 @@ $(".btn_add").click(function () {
}); });
}); });
form.on('submit(formDemo)', function (data) { form.on('submit(formDemo)', function (data) {
var platform_obj = {platform_id: $("select[name='platform_id']").val()};
data.field = Object.assign(data.field,platform_obj);
$.post('/admin/app/add', data.field, function (rev) { $.post('/admin/app/add', data.field, function (rev) {
layer.msg(rev.msg); layer.msg(rev.msg);
if (rev.code == 0) { if (rev.code == 0) {
...@@ -177,4 +179,9 @@ function before_show(data) { ...@@ -177,4 +179,9 @@ function before_show(data) {
$('textarea[name="log"]').val(JSON.parse(data.log).join("\n")); $('textarea[name="log"]').val(JSON.parse(data.log).join("\n"));
} }
form.render(); form.render();
} }
\ No newline at end of file
form.on('select(platform_change)', function(data){
table1.reload('table1', {where:{platform_id:data.value}});
table2.reload('table2', {where:{platform_id:data.value}});
});
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/12/12
* Time: 10:42
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
/**
* 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 CoinAppVersion extends BaseActiveRecord
{
const APP_ADD = 'add';
const APP_UPDATE = 'update';
/**
* @throws \yii\base\InvalidConfigException
* @return null|object|\yii\db\Connection
*/
public static function getDb()
{
return Yii::$app->get('p_sources');
}
/**
* 获取最新的稳定版app
*
* @param int $type android(1) IOS(3)
* @return array
*/
public static function getLastStable($type = 1,$platform_id = 1)
{
$max_version = self::find()->where(['type' => $type,'platform_id' => $platform_id])->max('version');
$data = self::find()->where(['type' => $type,'platform_id' => $platform_id,'version' => $max_version])->asArray()->one();
return $data;
}
public function formName()
{
return '';
}
public function attributeLabels()
{
return [
'id' => 'ID',
'status' => '状态',
'type' => '类型',
'version_code' => '版本代码',
'version' => '版本号',
'download_url' => '下载地址',
'log' => '升级日志',
'platform_id' => '平台',
'created_at' => '创建时间',
'updated_at' => '更新时间',
];
}
public function rules()
{
return [
[['id', 'status', 'type', 'version_code','platform_id'], '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','platform_id'],
'update' => ['id', 'status', 'type', 'version_code', 'version', 'download_url', 'log'],
];
}
}
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