Commit fee67188 authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into feature/ticker

parents f980911f 642fa5fc
......@@ -126,10 +126,12 @@ class CoinDogController extends BaseController
public function actionArticleBanner()
{
$type = Yii::$app->request->get('type', 1);
$data = Article::find()
->select('id, image_url ,title, url')
->limit(5)
->where(['type' => $type])
->orderBy('update_at desc')
->limit(5)
->asArray()
->all();
......
<?php
namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\psources\ExploreApp;
use common\models\psources\CoinBannerItem;
use common\models\psources\ExploreAppCategory;
class ExploreController extends BaseController
{
public function actionIndex()
{
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$data = null;
if (false == $platform_id) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$app_category_model = ExploreAppCategory::find()->where(['platform_id' => $platform_id, 'status' => ExploreAppCategory::STATUS_ON])->orderBy('sort')->all();
if (false == $app_category_model) {
$msg = 'success';
$code = 0;
goto doEnd;
}
foreach ($app_category_model as $key => $val) {
unset($val->apps);
$val->name = $val->name[$this->lang];
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
->where(['app_category_id' => (int)$val->id, 'status' => ExploreApp::STATUS_ON])
->orderBy('sort')
->limit($val->limit)
->all();
if (empty($apps_model)) {
unset($app_category_model[$key]);
continue;
}
foreach ($apps_model as &$app) {
$app->name = $app->name[$this->lang];
}
$val->apps = $apps_model;
unset($val->sort);
unset($val->limit);
unset($val->platform_id);
}
foreach ($app_category_model as $val) {
$data[] = $val;
}
$msg = 'success';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionCategory()
{
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$category_id = Yii::$app->request->get('id', 0);
if (false == $platform_id || false == $category_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$app_category_model = ExploreAppCategory::find()->where(['id' => (int)$category_id, 'platform_id' => $platform_id])->all();
if (false == $app_category_model) {
$msg = 'success';
$code = 0;
$data = null;
goto doEnd;
}
foreach ($app_category_model as &$val) {
foreach ($val->applications as $app) {
$app->name = $app->name[$this->lang];
}
$val->name = $val->name[$this->lang];
$val->apps = $val->applications;
unset($val->id);
unset($val->sort);
unset($val->style);
unset($val->limit);
unset($val->platform_id);
}
$data = $app_category_model;
$msg = 'success';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionSearch()
{
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
$ids = Yii::$app->request->get('ids', '');
if (false == $platform_id || false == $ids) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$id_arr = explode(',', $ids);
$order = "FIELD(`id`,$ids)";
$apps_model = ExploreApp::find()->select('id, name, icon, type, app_url, slogan')
->where(['status' => ExploreApp::STATUS_ON])
->andWhere(['in', 'id', $id_arr])
->orderBy([$order => true])
->limit(4)
->all();
if (false == $apps_model) {
$msg = 'success';
$code = 0;
$data = null;
goto doEnd;
}
foreach ($apps_model as &$app) {
$app->name = $app->name[$this->lang];
}
$data = $apps_model;
$msg = 'success';
$code = 0;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionBanner()
{
$msg = 'ok';
$code = 0;
$header = Yii::$app->request->headers;
$platform_id = $header['FZM-PLATFORM-ID'] ?? null;
if (false == $platform_id) {
$msg = '参数错误';
$code = -1;
$data = null;
goto doEnd;
}
$coin_banner = CoinBannerItem::find()->select('banner_url, image_url, title')->where(['platform_id' => $platform_id])->asArray()->all();
$data = $coin_banner;
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
......@@ -12,6 +12,10 @@ use Yii;
class CoinBannerItem extends BaseActiveRecord
{
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
......@@ -22,6 +26,25 @@ class CoinBannerItem extends BaseActiveRecord
return '{{coin_banner_item}}';
}
public function rules()
{
return [
[['image_url', 'platform_id'], 'required'],
[['banner_url', 'title'], 'safe'],
[['banner_url', 'image_url'], 'url']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['image_url', 'banner_url', 'title', 'platform_id'],
self:: SCENARIOS_UPDATE => ['id', 'image_url', 'banner_url', 'title', 'platform_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public static function getItems($condition = [])
{
return self::find()->joinWith('platform')->where($condition)->asArray()->all();
......
<?php
namespace common\models\psources;
use Yii;
use yii\db\Expression;
use common\core\BaseActiveRecord;
use yii\behaviors\TimestampBehavior;
class ExploreApp extends BaseActiveRecord
{
const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{explore_app}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules()
{
return [
[['name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id'], 'required'],
[['type', 'sort', 'status', 'platform_id', 'app_category_id'], 'integer'],
[['icon'], 'url']
];
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id'],
self:: SCENARIOS_UPDATE => ['id', 'name', 'icon', 'app_url', 'slogan', 'type', 'sort', 'status', 'platform_id', 'app_category_id'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function getAppCategory()
{
return $this->hasOne(ExploreAppCategory::className(), ['id' => 'app_category_id']);
}
public static function getCasesStatus()
{
return [
self::STATUS_ON => '激活',
self::STATUS_OFF => '未激活',
];
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class ExploreAppCategory extends BaseActiveRecord
{
const STATUS_ON = 1; //激活
const STATUS_OFF = 0; //未激活
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{explore_app_category}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules()
{
return [
[['name', 'sort', 'limit', 'style', 'platform_id', 'status'], 'required'],
];
}
public function attributes()
{
return array_merge(parent::attributes(), ['apps']);
}
public function scenarios()
{
$scenarios = [
self:: SCENARIOS_CREATE => ['name', 'sort', 'limit', 'style', 'platform_id', 'status'],
self:: SCENARIOS_UPDATE => ['name', 'sort', 'limit', 'style', 'platform_id', 'status'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'name' => '应用分类名称',
'sort' => '应用分类排序',
'limit' => '该分类下首页可显示的应用数量',
'style' => '应用分类展示样式',
'status' => '应用分类状态'
];
}
public function getApplications()
{
return $this->hasMany(ExploreApp::className(), ['app_category_id' => 'id'])->select(['id', 'name', 'icon', 'app_url', 'slogan', 'type'])->orderBy('sort');
}
}
\ No newline at end of file
This diff is collapsed.
<?php
namespace wallet\controllers;
use Yii;
use yii\data\Pagination;
use wallet\base\BaseController;
use common\models\psources\CoinBannerItem;
class ExploreBannerController extends BaseController
{
public function actionIndex()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
$page = Yii::$app->request->get('page', 1);
if (Yii::$app->request->isGet) {
$query = CoinBannerItem::find()
->select('id, banner_url, image_url, title')
->where(['platform_id' => $platform_id])
->asArray();
$banner_model = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$data = [
'list' => $banner_model,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
goto doEnd;
}
if (Yii::$app->request->isPost) {
$model = new CoinBannerItem();
$model->setScenario(CoinBannerItem::SCENARIOS_CREATE);
$params = Yii::$app->request->post();
$params['platform_id'] = $platform_id;
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 actionUpdate()
{
$msg = 'ok';
$code = 0;
$data = null;
$platform_id = Yii::$app->request->getPlatformId();
if (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id');
$data = CoinBannerItem::find()->select('id, banner_url, image_url, title')->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 = CoinBannerItem::findOne($id);
$model->setScenario(CoinBannerItem::SCENARIOS_UPDATE);
unset($params['id']);
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 actionRemove()
{
$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 = CoinBannerItem::find()->where(['id' => $id, 'platform_id' => $platform_id])->one();
if (false == $model || !$model->delete()) {
$msg = '删除失败';
$code = -1;
goto doEnd;
}
}
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
<?php
namespace wallet\controllers;
use Yii;
use OSS\OssClient;
use yii\web\UploadedFile;
use wallet\base\BaseController;
class OssController extends BaseController
{
protected $accessKeyId = "LTAI4FxZ787zpBmjLmr6yMwA";
protected $accessKeySecret = "5OMu030RFIE2KP3fNJrhVRTlVqBLaE";
protected $endpoint = "http://oss-cn-shanghai.aliyuncs.com";
protected $bucket = "bqbwallet";
public function actionUpload()
{
$data = [];
$type = Yii::$app->request->post('type', '');
$uploaded_file = UploadedFile::getInstanceByName('file');
if (false == $uploaded_file || false == $type) {
$msg = '参数错误';
$code = -1;
goto doEnd;
}
$object = md5(date('Y-m-d H:i:s') . $uploaded_file->tempName) . '.' . $uploaded_file->extension;
$filePath = $uploaded_file->tempName;
$ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
$result = $ossClient->uploadFile($this->bucket, 'upload/' . (empty($type) ? '' : $type . '/') . $object, $filePath);
if (!isset($result["info"]['url'])) {
$msg = '上传失败';
$code = -1;
goto doEnd;
}
$code = 0;
$msg = 'ok';
$data = $result["info"]['url'];
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