Commit 76bf604c authored by shajiaiming's avatar shajiaiming

fix

parent 14ca1798
......@@ -12,6 +12,7 @@ use common\service\exchange\ExchangeBuilderFactory;
use Yii;
use api\base\BaseController;
use common\models\pwallet\Notice;
use yii\data\Pagination;
/**
* 公告控制器
......@@ -21,50 +22,53 @@ use common\models\pwallet\Notice;
class NoticeController extends BaseController
{
/**
* 返回公告列表
*
* @var $page
* @var $limit
* @var $condition 筛选条件
* 申请列表
* @param integer page
* @param integer size
* @return array
*/
public function actionList()
{
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 10);
$post = $request->post();
$condition = [];
$data = null;
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$type = Yii::$app->request->get('type', '');
$post = array_filter($post, function ($value, $key) {
if ($key == 'status' && is_numeric($value)) {
return true;
}
if ($key == 'id' && is_numeric($value)) {
return true;
}
return $value;
}, ARRAY_FILTER_USE_BOTH);
if (isset($post['id'])) {
$condition[] = ['id' => $post['id']];
}
if (isset($post['title'])) {
$condition[] = ['like', 'title', $post['title']];
}
if (isset($post['author'])) {
$condition[] = ['author' => $post['author']];
}
if (isset($post['status'])) {
$condition[] = ['status' => $post['status']];
}
if (isset($post['create_at'])) {
$condition[] = ['>=', 'create_at', $post['create_at']];
if (empty($platform_id)) {
$msg = '缺少必要的参数';
$code = -1;
goto doEnd;
}
if (isset($post['update_at'])) {
$condition[] = ['>=', 'update_at', $post['update_at']];
$page = \Yii::$app->request->get('page', 1);
$size = \Yii::$app->request->get('size', 10);
$query = Notice::find()
->select('id, title, author, type, create_at')
->where(['status' => Notice::STATUS_ON])
->orderBy('create_at desc');
if (false != $type) {
$query->andWhere(['type' => (int)$type]);
}
$data = Notice::getList($page, $limit, $condition);
return $data;
$countQuery = clone $query;
$models = $query->offset(($page - 1) * $size)->limit($size)->all();
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $size]);
$data = [
'list' => $models,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => (int)$size,
'currentPage' => (int)$page,
]
];
$msg = 'ok';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionIndex()
......
......@@ -13,11 +13,48 @@ use common\core\BaseActiveRecord;
class Notice extends BaseActiveRecord
{
const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('db_pwallet');
}
public function rules()
{
return [
[['title', 'content', 'type', 'platform_id'], 'required'],
[['author'], 'safe'],
[['status', 'status', 'platform_id'], 'integer'],
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['title', 'content', 'author', 'status', 'type', 'platform_id'],
self:: SCENARIOS_UPDATE => ['id', 'title', 'content', 'author', 'status', 'type', 'platform_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'title' => '公告标题',
'content' => '公告内容',
'author' => '作者',
'status' => '公告状态',
'type' => '公告类型',
'platform_id' => '钱包',
];
}
public static function getList($page = 1, $limit = 10, $condition = [])
{
$query = self::find();
......
<?php
namespace wallet\controllers;
use common\models\pwallet\Notice;
use Yii;
use yii\data\Pagination;
use wallet\base\BaseController;
class NoticeController extends BaseController
{
public function actionIndex()
{
$msg = 'ok';
$code = 0;
$data = null;
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 10);
if (Yii::$app->request->isPost) {
$model = new Notice();
$model->setScenario(Notice::SCENARIOS_CREATE);
$params = Yii::$app->request->post();
$params['platform_id'] = $platform_id;
if (!$model->validate()) {
$msg = $model->errors;
$code = -1;
goto doEnd;
}
$model->save();
goto doEnd;
}
if (Yii::$app->request->isGet) {
$status = Yii::$app->request->get('status', '');
$type = Yii::$app->request->get('type', 0);
$query = Notice::find()->where(['platform_id' => $platform_id])->asArray();
$model = $query->offset(($page - 1) * $size)->orderBy('create_at')->limit($size)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $size]);
$data = [
'list' => $model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => $size,
'currentPage' => $page,
]
];
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionCategoryUpdate()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
$data = ExploreAppCategory::find()->select('id, name, sort, limit, style, status')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
goto doEnd;
}
if (Yii::$app->request->isPut) {
$params = Yii::$app->request->post();
$id = isset($params['id']) ? $params['id'] : null;
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$model = ExploreAppCategory::findOne($id);
if ($model->platform_id != $platform_id) {
$msg = '无权修改';
$code = -1;
goto doEnd;
}
$model->setScenario(ExploreAppCategory::SCENARIOS_UPDATE);
unset($params['id']);
$params['platform_id'] = $platform_id;
$name_arr = $params['name'];
$name = [];
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($params['name']);
$params['name'] = $name;
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$msg = $model->errors;
$code = -1;
goto doEnd;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionCategoryRemove()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
$id = Yii::$app->request->get('id');
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
if (Yii::$app->request->isDelete) {
$model_app = ExploreApp::find()->where(['app_category_id' => (int)$id])->asArray()->all();
if (false != $model_app) {
$msg = '请先删除该类别下的应用';
$code = -1;
goto doEnd;
}
$model = ExploreAppCategory::find()->where(['id' => $id, 'platform_id' => $platform_id])->one();
if ($model->platform_id != $platform_id) {
$msg = '无权修改';
$code = -1;
goto doEnd;
}
if (!$model->delete()) {
$msg = '删除失败';
$code = -1;
goto doEnd;
}
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionApps()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$category_id = Yii::$app->request->get('id', 0);
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 10);
if (false == $platform_id || false == $category_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$query = ExploreApp::find()
->where(['app_category_id' => $category_id])
->asArray();
$app_model = $query->offset(($page - 1) * $size)->orderBy('sort')->limit($size)->asArray()->all();
foreach ($app_model as &$val) {
$name = json_decode($val['name'], true);
$val['name'] = $name;
}
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $app_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => $size,
'currentPage' => $page,
]
];
goto doEnd;
}
if (Yii::$app->request->isPost) {
$model = new ExploreApp();
$model->setScenario(ExploreApp::SCENARIOS_CREATE);
$params = Yii::$app->request->post();
$params['platform_id'] = $platform_id;
$name_arr = $params['name'];
$name = [];
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($params['name']);
$params['name'] = $name;
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$msg = $model->errors;
$code = -1;
goto doEnd;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionAppUpdate()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
$data = ExploreApp::find()->select('id, name, icon, app_url, slogan, type, sort, status')->where(['platform_id' => $platform_id, 'id' => $id])->asArray()->one();
goto doEnd;
}
if (Yii::$app->request->isPut) {
$params = Yii::$app->request->post();
$id = isset($params['id']) ? $params['id'] : null;
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$model = ExploreApp::findOne($id);
if ($model->platform_id != $platform_id) {
$msg = '无权修改';
$code = -1;
goto doEnd;
}
$model->setScenario(ExploreApp::SCENARIOS_UPDATE);
unset($params['id']);
$params['platform_id'] = $platform_id;
$name_arr = $params['name'];
$name = [];
foreach (Yii::$app->params['lang'] as $key => $val) {
$name[$val] = isset($name_arr[$val]) ? $name_arr[$val] : '';
}
unset($params['name']);
$params['name'] = $name;
if ($model->load($params, '') && $model->save()) {
goto doEnd;
}
$msg = $model->errors;
$code = -1;
goto doEnd;
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionAppRemove()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
$id = Yii::$app->request->get('id');
if (false == $id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
if (Yii::$app->request->isDelete) {
$model = ExploreApp::find()->where(['id' => $id, 'platform_id' => $platform_id])->one();
if ($model->platform_id != $platform_id) {
$msg = '无权修改';
$code = -1;
goto doEnd;
}
if (false == $model || !$model->delete()) {
$msg = '删除失败';
$code = -1;
goto doEnd;
}
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ 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