Commit 83880703 authored by shajiaiming's avatar shajiaiming

Merge branch 'master' into feature/airdrop

parents d172b753 21832ada
<?php
namespace api\base;
class BaseConstant
{
const ERROR = 'error';
const MSG = 'msg';
const MESSAGE = 'message';
const CODE = 'code';
const VAL = 'val';
const DATA = 'data';
const OK = 'ok';
const FINALTAG = 'finaltag';
}
......@@ -37,7 +37,7 @@ class BaseResponse extends Response
$return = $data;
}
if (YII_ENV_DEV) {
$return['time'] = \Yii::$app->controller->end - \Yii::$app->controller->start;
#$return['time'] = \Yii::$app->controller->end - \Yii::$app->controller->start;
}
\Yii::$app->response->data = $return;
parent::send();
......
<?php
namespace api\base;
use yii\helpers\Html;
use yii\web\Response;
class ResponseMsg
{
public $is_support_jsonp = false;
public $header_list = [];
private static $default_header_list = [];
public function __construct()
{
// if ('cli' !== php_sapi_name()){
// $this->header_list = self::$default_header_list;
// $this->fzmCrossHeader();
// }
}
public function fzmCrossHeader()
{
$allow_list = \Yii::$app->params['allow_options_domain']['common'];
$origin = \Yii::$app->request->headers->get('Origin');
if (!in_array($origin, $allow_list)) {
$origin = implode(',', $allow_list);
}
$this->header('Access-Control-Allow-Origin', $origin);
$this->header('Access-Control-Allow-Methods', 'POST,GET,OPTIONS');
$this->header('Access-Control-Allow-Credentials', 'true');
$this->header('Access-Control-Allow-Headers', 'Authorization,FZM-REQUEST-OS,FZM-USER-IP,FZM-REQUEST-UUID,Content-Type,Content-Length');
}
public static function setDefaultHeader($default_header_list)
{
foreach ($default_header_list as $key => $header) {
self::$default_header_list[$key] = $header;
}
}
public static function getDefaultHeader()
{
return self::$default_header_list;
}
public function arrSuccess($data = BaseConstant::OK, $code = 200)
{
return [BaseConstant::ERROR => false, BaseConstant::MESSAGE => $data, BaseConstant::CODE => $code];
}
public function arrFail($data, $code = -1)
{
return [BaseConstant::ERROR => true, BaseConstant::MESSAGE => $data, BaseConstant::CODE => $code];
}
/**
* 失败返回接口
* @param string $msg
* @param int $code
* @return string
*/
public function jsonError($msg = '', $code = -1)
{
if (empty($msg)) {
$msg = 'unknown error';
}
$view = [
BaseConstant::CODE => $code,
BaseConstant::MSG => $msg,
BaseConstant::DATA => null,
];
$json = json_encode($view);
return $this->dumpJsonData($json);
}
/**
* 成功返回接口
* @param string $msg
* @param int $code
* @return string
*/
public function jsonSuccess($data = '', $code = 200)
{
$view = [
BaseConstant::CODE => $code,
BaseConstant::MESSAGE => BaseConstant::OK,
BaseConstant::DATA => $data
];
$json = json_encode($view);
return $this->dumpJsonData($json);
}
/**
* 直接处理接口数据
* @param $ret
*/
public function dealRet($ret)
{
if (true === $ret[BaseConstant::ERROR]) {
$this->jsonError($ret[BaseConstant::MESSAGE] ? : 'unknown error');
} else {
$this->jsonSuccess($ret[BaseConstant::MESSAGE] ? : BaseConstant::OK);
}
}
/**
* 根据是否为JSONP做特殊处理输出
* @param $json
* @return string
*/
public function dumpJsonData($json)
{
$callback = '';
if (true === $this->is_support_jsonp) {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
$callback_key = 'jsonpcallback';
$callback = $_GET[$callback_key];
if ($callback) {
$callback = Html::encode($callback_key);
$json = $callback . '(' . $json . ')';
}
}
if (!$callback && !$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return $json;
}
/**
* @param $json_str
* @param string $callback_key
* @return string
*/
public function printByJson($json_str, $callback_key = '')
{
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . $json_str . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return $json_str;
}
}
/**
* @param $arr
* @param string $callback_key
* @return string
*/
public function printByArr($arr, $callback_key = '')
{
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
public function printOldFail($code, $code_msg, $detail_code, $detail_msg, $callback_key = '')
{
$this->fzmCrossHeader();
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
$arr = ['code' => $code, 'error' => $code_msg, 'ecode' => $detail_code, 'message' => $detail_msg, 'data' => []];
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
/**
* @param $success_data
* @param string $callback_key
* @return string
*/
public function printOldSuccess($success_data, $callback_key = '')
{
$this->fzmCrossHeader();
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
$arr = ['code' => 200, 'ecode' => 200, 'error' => 'OK', 'message' => 'OK', 'data' => $success_data];
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
/**
* 解决xdebug cookie设置不了的问题
*/
private function isDebug()
{
if (defined('SERVICE_ENV') && (SERVICE_ENV === 'test' || SERVICE_ENV === 'local') && isset($_GET['debug'])) {
return true;
}
return false;
}
public function header($key, $value)
{
$this->header_list[$key] = $value;
}
public function getHeaders()
{
return $this->header_list;
}
public function withHeaders($header_arr)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
foreach ($header_arr as $key => $val) {
\Yii::$app->response->headers->add($key, $val);
}
return $this;
}
public function withContent($content)
{
return $content;
}
}
......@@ -60,15 +60,17 @@ class AppController extends BaseController
$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;
if(!empty($data['log'])){
$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'];
......
......@@ -31,8 +31,22 @@ class ApplicationController extends BaseController
}
$recommendData = ApplicationBusiness::getRecommendList($condition);
foreach($recommendData as $j => &$val){
$name_arr = json_decode($val['name'], true);
$val['name'] = $name_arr[$this->lang];
}
$data['recommend'] =$recommendData;
$cate_app_data = ApplicationBusiness::getCategoryAppList($condition);
foreach ($cate_app_data as $key => &$val){
$name = json_decode($val['name'], true);
$val['name'] = $name[$this->lang];
if(!empty($val['apps'])){
foreach($val['apps'] as $j => &$value){
$name = json_decode($value['name'], true);
$value['name'] = $name[$this->lang];
}
}
}
$data['cate_app_data'] = $cate_app_data;
$data['banner'] = ApplicationBusiness::getBannerList($condition);
$result['code'] = 0;
......@@ -48,6 +62,16 @@ class ApplicationController extends BaseController
{
$result['code'] = 0;
$result['data'] = ApplicationBusiness::getCategoryAppList();
foreach ($result['data'] as $key => &$val){
$name = json_decode($val['name'], true);
$val['name'] = $name[$this->lang];
if(!empty($val['apps'])){
foreach($val['apps'] as $j => &$value){
$name = json_decode($value['name'], true);
$value['name'] = $name[$this->lang];
}
}
}
return $result;
}
......@@ -59,7 +83,11 @@ class ApplicationController extends BaseController
$request = Yii::$app->request;
$id = $request->post('id',0);
if($id){
return ApplicationBusiness::appInfo($id);
$result = ApplicationBusiness::appInfo($id);
$data = $result['data'];
$name = json_decode($data['name'], true);
$data['name'] = $name[$this->lang];
return ['code' => 0,'data' => $data];
}else{
return ['code' => 1,'data' => [],'msg' => 'id不能为空'];
}
......@@ -126,6 +154,8 @@ class ApplicationController extends BaseController
$icon_Items = array_column($appItems,'icon');
$icon_Infos = CoinImage::getItemsByIds($icon_Items);
foreach($appItems as &$value){
$name = json_decode($value['name'], true);
$value['name'] = $name[$this->lang];
if($value['icon']){
$value['icon'] = $icon_Infos[$value['icon']]['base_url'].$icon_Infos[$value['icon']]['file_url'];
}else{
......@@ -138,7 +168,9 @@ class ApplicationController extends BaseController
$cate_id = $item['cate_id'];
$app_id = $item['app_id'];
$cate_app_items[$cate_id]['cate_id'] = $cate_id;
$cate_app_items[$cate_id]['name'] = $item['name'];
$name_arr = json_decode($item['name'], true);
$name = $name_arr[$this->lang];
$cate_app_items[$cate_id]['name'] = $name;
$cate_app_items[$cate_id]['apps'][] = $appItems[$app_id];
}
foreach ($cate_app_items as $item){
......@@ -159,13 +191,16 @@ class ApplicationController extends BaseController
$cate_id = $request->get('cate_id','');
if($cate_id){
$cate_info = CoinApplicationCategory::getCategoryById($cate_id);
$name = $cate_info->name[$this->lang];
$cate_info_data['id'] = $cate_info->id;
$cate_info_data['name'] = $cate_info->name;
$cate_info_data['name'] = $name;
$appItems = ApplicationBusiness::getCateAppInfo(0,[['cate_id' => $cate_id]]);
if($appItems){
$appItems = array_shift($appItems);
foreach($appItems as &$value){
$value['app_user_num'] = ApplicationBusiness::getAppUserNum($value['app_id']);
$name_arr = json_decode($value['name'], true);
$value['name'] = $name_arr[$this->lang];
}
$cate_info_data['apps'] = $appItems;
return ['code' => 0,'data' => $cate_info_data];
......
......@@ -11,6 +11,7 @@ namespace api\controllers;
use api\base\BaseController;
use common\base\Exception;
use common\business\BrowerBusiness;
use common\business\Chain33Business;
use common\business\CoinBusiness;
use common\business\ExchangeBusiness;
use common\models\psources\Coin;
......@@ -35,7 +36,7 @@ class CoinController extends BaseController
public function actionGetCoinById()
{
$request = Yii::$app->request;
$id = $request->post('id', 0);
$id = $request->post('id', 0);
if ($id) {
$ret = CoinBusiness::getCoinAllById($id);
if ($ret) {
......@@ -55,9 +56,9 @@ class CoinController extends BaseController
*/
public function actionGetRecList()
{
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$platform_id = $request->post('platform_id', 2);//默认币钱包
if ($platform_id == 1) {
$platform_id = 3;
......@@ -73,7 +74,7 @@ class CoinController extends BaseController
$condition['recommend'] = $recommend;
}
$select = ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain'];
$datas = CoinRecommend::getList($page, $limit, $condition, [], $select);
$datas = CoinRecommend::getList($page, $limit, $condition, [], $select);
//获取详细信息
$coin_recommends = &$datas['data'];
if (!empty($coin_recommends)) {
......@@ -81,8 +82,8 @@ class CoinController extends BaseController
//获取币种信息
$coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id');
//获取行情信息
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names);
if ($coin_infos) {
......@@ -93,19 +94,19 @@ class CoinController extends BaseController
$value[$item] = $coin_infos[$value['cid']][$item];
if ($value['platform_id'] != 2) {
//国盾币不需要行情
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['high'] = $coin_quotations[$temp_key]['high'];
$value['last'] = $coin_quotations[$temp_key]['last'];
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
} else {
$value['low'] = 0;
$value['low'] = 0;
$value['high'] = 0;
$value['last'] = 0;
$value['rmb'] = 0;
$value['rmb'] = 0;
}
}
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['chain_quotation'] = $coin_quotations[$coin_infos[$value['cid']]['chain']];
unset($value['create_time'], $value['update_time'], $value['cid']);
}
......@@ -120,9 +121,9 @@ class CoinController extends BaseController
*/
public function actionGetNewRecList()
{
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$request = Yii::$app->request;
$page = $request->post('page', 1);
$limit = $request->post('limit', 999);
$platform_id = $request->post('platform_id', 1);//默认币钱包
$recommend = $request->post('recommend', '');
......@@ -130,22 +131,22 @@ class CoinController extends BaseController
if ($recommend) {
$condition['recommend'] = $recommend;
}
$select = ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain', 'treaty'];
$select = ['id', 'sid', 'icon', 'name', 'optional_name', 'nickname', 'platform', 'chain', 'treaty'];
$order_by = ['sort' => SORT_ASC];
$datas = CoinRecommend::getList($page, $limit, $condition, $order_by, $select);
$datas = CoinRecommend::getList($page, $limit, $condition, $order_by, $select);
//获取详细信息
$coin_recommends = &$datas['data'];
if (!empty($coin_recommends)) {
$coin_ids = array_column($coin_recommends, 'cid');
//获取币种信息
$coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id');
foreach ($coin_infos as $key => &$val){
foreach ($coin_infos as $key => &$val) {
$nickname = json_decode($val['nickname'], true);
$val['nickname'] = $nickname[$this->lang];
}
//获取行情信息
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_names = array_column($coin_infos, 'name');
$coin_names = array_merge($coin_names, array_column($coin_infos, 'chain'));
$coin_quotations = ExchangeBusiness::getQuatationByNames($coin_names);
if ($coin_infos) {
......@@ -156,28 +157,30 @@ class CoinController extends BaseController
$value[$item] = $coin_infos[$value['cid']][$item];
if ($value['platform_id'] != 2) {
//国盾币不需要行情
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['low'] = $coin_quotations[$temp_key]['low'];
$value['high'] = $coin_quotations[$temp_key]['high'];
$value['last'] = $coin_quotations[$temp_key]['last'];
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
$value['usd'] = $coin_quotations[$temp_key]['usd'] ?? 0;
$value['rmb'] = $coin_quotations[$temp_key]['rmb'];
$value['usd'] = $coin_quotations[$temp_key]['usd'] ?? 0;
} else {
$value['low'] = 0;
$value['low'] = 0;
$value['high'] = 0;
$value['last'] = 0;
$value['rmb'] = 0;
$value['usd'] = 0;
$value['rmb'] = 0;
$value['usd'] = 0;
}
}
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['id'] = $value['cid'];
$value['sid'] = ucfirst($value['sid']);
$value['chain_quotation'] = $coin_quotations[$coin_infos[$value['cid']]['chain']];
$value['chain_rmb'] = isset($coin_quotations[$coin_infos[$value['cid']]['chain']]['rmb']) ? $coin_quotations[$coin_infos[$value['cid']]['chain']]['rmb'] : 0;
$value['chain_usd'] = isset($coin_quotations[$coin_infos[$value['cid']]['chain']]['usd']) ? $coin_quotations[$coin_infos[$value['cid']]['chain']]['usd'] : 0;
unset($value['create_time'], $value['update_time'], $value['cid']);
}
unset($key, $value);
}
}
if(!$datas['data']){
if (!$datas['data']) {
$datas['data'] = null;
}
return $datas;
......@@ -193,20 +196,20 @@ class CoinController extends BaseController
public function actionGetMinerFeeByName()
{
$names = Yii::$app->request->post('name');
$coin = Coin::findOne(['name' => $names]);
$coin = Coin::findOne(['name' => $names]);
if ($coin) {
$chain = $coin->chain;
$miner_fee = MinerFee::find()->where(['platform' => $chain,'type' => 1])->one();
if(!$miner_fee){
throw new Exception('8', '旷工费未设置');
}
$chain = $coin->chain;
$miner_fee = MinerFee::find()->where(['platform' => $chain, 'type' => 1])->one();
if (!$miner_fee) {
throw new Exception('8', '旷工费未设置');
}
} else {
//如果coin为null,$coin->minerFee会抛出Trying to get property 'minerFee' of non-object",code=>8
throw new Exception('8', '币种不存在');
}
$result = (array)$miner_fee->getAttributes();
$result['min'] = number_format($result['min'],6);
$result['max'] = number_format($result['max'],6);
$result = (array)$miner_fee->getAttributes();
$result['min'] = number_format($result['min'], 6);
$result['max'] = number_format($result['max'], 6);
return $result;
}
......@@ -215,28 +218,25 @@ class CoinController extends BaseController
*/
public function actionCoinIndex()
{
$names = Yii::$app->request->post('names');
$platforms = [];
$newNames = [];
if(!$names){
return ['code' => 0,'data' => []];
$names = Yii::$app->request->post('names');
if (!$names) {
return ['code' => 0, 'data' => []];
}
foreach($names as $item){
$item_array = explode(',',$item);
$newNames [] = $item_array[0];
if(isset($item_array[1])){
if(!in_array($item_array[1],$platforms)){
$platforms [] = $item_array[1];
foreach ($names as $key => $val) {
if(strpos($val, ',') !== false){
$val_array = explode(',', $val);
if('USDT' == strtoupper($val_array[0]) && 'BTC' == strtoupper($val_array[1])) {
$condition[] = [$val_array[0], 'omni'];
continue;
}
$condition[] = [$val_array[0], $val_array[1]];
} else {
$condition[] = $val;
}
}
$condition = [['in', 'name', $newNames]];
if($platforms){
$condition[] = ['in', 'platform', $platforms];
}
$result = ExchangeBusiness::getApiListForIndex(1, 999, $condition);
$result = ExchangeBusiness::getApiListForIndex(1, 999, $condition);
if ($result) {
$chains = array_unique(array_column($result['data'], 'chain'));
$chains = array_unique(array_column($result['data'], 'chain'));
$chain_quotation = [];
foreach ($chains as $key => $value) {
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
......@@ -245,6 +245,8 @@ class CoinController extends BaseController
$nickname = json_decode($value['nickname'], true);
$value['nickname'] = $nickname[$this->lang];
$value['chain_quotation'] = $chain_quotation[$value['chain']] ?: null;
$value['chain_rmb'] = isset($value['chain_quotation']['rmb']) ? $value['chain_quotation']['rmb'] : 0;
$value['chain_usd'] = isset($value['chain_quotation']['usd']) ? $value['chain_quotation']['usd'] : 0;
}
return $result;
}
......@@ -257,23 +259,23 @@ class CoinController extends BaseController
*/
public function actionSearchCoinByName()
{
$request = Yii::$app->request;
$name = $request->post('name', '');
$page = $request->post('page', 1);
$limit = $request->post('limit', 10);
$request = Yii::$app->request;
$name = $request->post('name', '');
$page = $request->post('page', 1);
$limit = $request->post('limit', 10);
$platform_ids = $request->post('platform_id', null);
$condition = [['in', 'chain', ['ETH','DCR','BTC','BTY']]];
$condition = [['in', 'chain', ['ETH', 'DCR', 'BTC', 'BTY']]];
if (!empty($name)) {
$condition[] = ['or',['address' => $name],['or', ['like', 'name', $name], ['like', 'nickname', $name]]];
$condition[] = ['or', ['address' => $name], ['or', ['like', 'name', $name], ['like', 'nickname', $name]]];
}
if ($platform_ids) {
/* $platform_id_arr = explode(',', $platform_ids);
$condition_arr = ['OR'];
foreach ($platform_id_arr as $key => $value) {
array_push($condition_arr, ['=', 'platform_id', $value]);
}
$condition[] = $condition_arr;*/
/* $platform_id_arr = explode(',', $platform_ids);
$condition_arr = ['OR'];
foreach ($platform_id_arr as $key => $value) {
array_push($condition_arr, ['=', 'platform_id', $value]);
}
$condition[] = $condition_arr;*/
$condition[] = ['>', "find_in_set($platform_ids, platform_id)", 0];
}
......@@ -281,10 +283,10 @@ class CoinController extends BaseController
if (empty($result)) {
return ['code' => 0, 'count' => 0, 'data' => []];
}
$total = $result['total'];
$total = $result['total'];
$result = $result['data'];
if ($result) {
$chains = array_unique(array_column($result, 'chain'));
$chains = array_unique(array_column($result, 'chain'));
$chain_quotation = [];
foreach ($chains as $key => $value) {
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
......@@ -295,6 +297,8 @@ class CoinController extends BaseController
foreach ($result as $key => &$value) {
$nickname = json_decode($value['nickname'], true);
$value['nickname'] = $nickname[$this->lang];
$value['chain_rmb'] = isset($value['chain_quotation']['rmb']) ? $value['chain_quotation']['rmb'] : 0;
$value['chain_usd'] = isset($value['chain_quotation']['usd']) ? $value['chain_quotation']['usd'] : 0;
}
return ['code' => 0, 'count' => $total, 'data' => $result];
}
......@@ -308,8 +312,8 @@ class CoinController extends BaseController
public function actionTransaction()
{
$request = Yii::$app->request;
$name = $request->post('name', '');
$txhash = $request->post('txhash', '');
$name = $request->post('name', '');
$txhash = $request->post('txhash', '');
if ($name && $txhash) {
return BrowerBusiness::getTransStatus($name, $txhash);
}
......@@ -323,12 +327,12 @@ class CoinController extends BaseController
public function actionGetBrowerByPlatform()
{
$request = Yii::$app->request;
$platform = $request->post('platform', '');
if($platform){
$brower_url = Yii::$app->redis->hget('platform_brower_info',$platform);
return ['code' => 0,'data' => $brower_url];
}else{
return ['code' => 1,'data' => [],'msg' => '平台参数不能为空'];
$platform = $request->post('platform', '');
if ($platform) {
$brower_url = Yii::$app->redis->hget('platform_brower_info', $platform);
return ['code' => 0, 'data' => $brower_url];
} else {
return ['code' => 1, 'data' => [], 'msg' => '平台参数不能为空'];
}
}
......@@ -338,25 +342,34 @@ class CoinController extends BaseController
public function actionGetWithHold()
{
$request = Yii::$app->request;
$platform = $request->get('platform', '');
if($platform){
$platform = $request->get('platform', '');
$coin_name = $request->get('coinname', '');
if (empty($coin_name)) {
$platform_with_hold = CoinPlatformWithHold::getRecord($platform);
if($platform_with_hold){
$des = Yii::$app->des;
$platform_with_hold['private_key'] = $des->encrypt($platform_with_hold['private_key']);
return ['code' => 0,'data' => $platform_with_hold];
}else{
$data = [
'id' => 0,
'platform' => '',
'address' => '',
'private_key' => '',
'exer' => ''
];
return ['code' => 0, 'data' => $data];
}
}else{
return ['code' => 1,'data' => [],'msg' => '平台参数不能为空'];
$des = Yii::$app->des;
$platform_with_hold['private_key'] = $des->encrypt($platform_with_hold['private_key']);
return ['code' => 0, 'data' => $platform_with_hold];
}
$platform_with_hold = CoinPlatformWithHold::getRecord($platform);
$coin_info = Coin::find()->select('treaty')->where(['name' => strtoupper($coin_name), 'platform' => $platform])->asArray()->one();
$des = Yii::$app->des;
$platform_with_hold['private_key'] = $des->encrypt($platform_with_hold['private_key']);
if (1 == $coin_info['treaty']) {
$platform_with_hold['exer'] = 'user.p.' . $platform . '.token';
$platform_with_hold['tokensymbol'] = $coin_name;
$platform_with_hold['fee'] = 0;
} else {
$platform_with_hold['exer'] = 'user.p.' . $platform . '.coins';
$platform_with_hold['tokensymbol'] = $platform . '.coins';
$platform_with_hold['fee'] = (float)sprintf("%0.4f", (double)$platform_with_hold['fee']);
}
$service = new Chain33Business();
$result = $service->getProperFee();
if (0 === $result['code']) {
$platform_with_hold['bty_fee'] = (float)sprintf("%0.4f", $result['result']['properFee'] / 1e8);
} else {
$platform_with_hold['bty_fee'] = (float)sprintf("%0.4f", Yii::$app->params['bty_fee']);
}
return ['code' => 0, 'data' => $platform_with_hold];
}
}
......@@ -10,61 +10,12 @@ use yii\data\Pagination;
class GameBetController extends BaseController
{
/**
* 获取游戏状态
*
* @return array
*/
public function actionGameStatus()
{
$service = new Chain33Business();
$result = $service->getGameStatus();
if( 0 !== $result['code']){
return ['code' => -1,'data' => [], 'msg' => $result['msg']];
}
$queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){
return ['code' => -1,'data' => [], 'msg' => 'error'];
}
$resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'],true);
$current_round = $resultJSON['current_round'];
$cache_current_round = Yii::$app->redis->get('chain33_game_status');
if(empty($cache_current_round)){
$cache_current_round = CoinGameBet::find()->max('round');
Yii::$app->redis->set('chain33_game_status',$cache_current_round,'EX',300);
}
$cache_current_round = (false == $cache_current_round ? 0 : $cache_current_round);
if($cache_current_round >= $current_round){
return ['code' => -1,'data' => [], 'msg' => '数据已为最新'];
}
Yii::$app->redis->set('chain33_game_status',$current_round,'EX',300);
$result = $service->getBetStatus($cache_current_round, $current_round);
if( 0 !== $result['code']){
return ['code' => -1,'data' => [], 'msg' => '数据错误'];
}
$queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){
return ['code' => -1,'data' => [], 'msg' => '数据错误'];
}
foreach ($queryResultItems['queryResultItems'] as $key => $val){
if( false == $val['found'] ) continue;
$resultArr = json_decode($val['resultJSON'],true);
$datas[] = [
$resultArr['round'], $resultArr['player'], $resultArr['amount'], $resultArr['height'], $resultArr['guess_num'], $resultArr['rand_num'], $resultArr['player_win']
];
}
CoinGameBet::loadArray($datas);
return ['code' => 1,'data' => [], 'msg' => '数据更新成功'];
}
public function actionBetStatus()
{
$platform = Yii::$app->request->get('platform', 'ts_wallet');
$player = Yii::$app->request->get('player', '');
$page = Yii::$app->request->get('page', 1);
if(empty($player)){
if(empty($player) || empty($platform)){
$msg = '请求参数错误';
$code = -1;
$data = null;
......@@ -72,9 +23,10 @@ class GameBetController extends BaseController
}
$query = CoinGameBet::find()
->select('round, player, amount, height, guess_num, guess_num, rand_num, player_win')
->select('round, player, amount, height, guess_num, guess_num, rand_num, player_win, platform')
->where('player= :player',[':player' => $player])
->andWhere(['valid' => CoinGameBet::VAILD_TRUE])
->andWhere(['platform' => $platform])
#->andWhere(['valid' => CoinGameBet::VAILD_TRUE])
->orderBy('update_time desc');
$count = $query->count();
......
......@@ -11,46 +11,90 @@ namespace api\controllers;
use Yii;
use api\base\BaseController;
use common\models\pwallet\GameUser;
use common\models\pwallet\GameUserAddress;
class GameController extends BaseController {
/**
* 保存地址与昵称
*/
public function actionSaveAddressAndNickname(){
$post = Yii::$app->request->post();
$address = $post['address']??'';
$nickname = $post['nickname']??'';
if (empty($address) || empty($nickname)) {
return ['code' => -1, 'msg' => '地址和昵称不能为空', 'data' => ''];
}
//判断重复
$count = GameUser::find()->where(['nickname' => $nickname])->count();
if ($count > 0) {
return ['code' => -1, 'msg' => '昵称重复'];
}
// todo 保存
$models = new GameUser();
$models->nickname = $nickname;
$models->address = $address;
if ($models->save()) {
return ['code' => 0, 'msg' => 'Succeed', 'data' => $models->id];
}
return ['code' => -1, 'msg' => 'Failed'];
}
class GameController extends BaseController
{
/**
* 保存地址与昵称
*/
public function actionSaveAddressAndNickname()
{
$post = Yii::$app->request->post();
$address = $post['address'] ?? '';
$nickname = $post['nickname'] ?? '';
if (empty($address) || empty($nickname)) {
return ['code' => -1, 'msg' => '地址和昵称不能为空', 'data' => null];
}
//判断重复
$count = GameUser::find()->where(['nickname' => $nickname])->count();
if ($count > 0) {
return ['code' => -1, 'msg' => '昵称重复'];
}
// todo 保存
$models = new GameUser();
$models->nickname = $nickname;
$models->address = $address;
if ($models->save()) {
return ['code' => 0, 'msg' => 'Succeed', 'data' => $models->id];
}
return ['code' => -1, 'msg' => 'Failed'];
}
/**
* 根据地址获取昵称
*/
public function actionGetNicknameByAddress(){
$address = Yii::$app->request->post('address', '');
if (empty($address)) {
return ['code' => -1, 'msg' => '地址不能为空', 'data' => ''];
}
//todo 获取地址
$address = GameUser::find()->select(['nickname'])->where(['address' => $address])->one();
if (!empty($address)) {
return ['code' => 0, 'msg'=> 'Succeed', 'data' => $address];
}
return ['code' => -1, 'msg' => 'Failed'];
}
/**
* 根据地址获取昵称
*/
public function actionGetNicknameByAddress()
{
$address = Yii::$app->request->post('address', '');
if (empty($address)) {
return ['code' => -1, 'msg' => '地址不能为空', 'data' => null];
}
//todo 获取地址
$address = GameUser::find()->select(['nickname'])->where(['address' => $address])->one();
if (!empty($address)) {
return ['code' => 0, 'msg' => 'Succeed', 'data' => $address];
}
return ['code' => -1, 'msg' => 'Failed'];
}
public function actionSaveGameInfo()
{
$post = Yii::$app->request->post();
$address = $post['address'] ?? '';
$nickname = $post['nickname'] ?? '';
if (empty($address) || empty($nickname)) {
return ['code' => -1, 'msg' => '地址和昵称不能为空', 'data' => null];
}
//判断重复
$count = GameUserAddress::find()->where(['address' => $address])->count();
if ($count > 0) {
return ['code' => -1, 'msg' => '地址已存在', 'data' => null];
}
// todo 保存
$models = new GameUserAddress();
$models->nickname = $nickname;
$models->address = $address;
if ($models->save()) {
return ['code' => 0, 'msg' => 'Succeed', 'data' => $models->id];
}
return ['code' => -1, 'msg' => 'Failed', 'data' => null];
}
public function actionGetNicknameByAddressArr()
{
$address = Yii::$app->request->post('address', '');
if (empty($address)) {
return ['code' => -1, 'msg' => '地址不能为空', 'data' => null];
}
//todo 获取地址
$address = GameUserAddress::find()
->select(['nickname', 'address'])
->where(['in', 'address', $address])
->asArray()->all();
if (!empty($address)) {
return ['code' => 0, 'msg' => 'Succeed', 'data' => $address];
}
return ['code' => -1, 'msg' => '数据为空', 'data' => null];
}
}
\ No newline at end of file
......@@ -5,9 +5,11 @@
* Date: 2018/11/14
* Time: 18:53
*/
namespace api\controllers;
use api\base\BaseController;
use common\models\psources\CoinHashMemo;
use common\models\psources\CoinTokenTransfer;
use common\service\chain33\Chain33Service;
use Yii;
......@@ -16,47 +18,101 @@ use Yii;
class TradeController extends BaseController
{
/**
* 添加本地备注
*/
* 添加本地备注
*/
public function actionAddMemo()
{
$request = Yii::$app->request;
$hash = $request->post('hash');
$memo = $request->post('memo');
if($hash && $memo){
Yii::$app->redis->hset('trade_hash_memo',$hash,$memo);
return ['code' => 0,'data' => [], 'msg' => '本地备注添加成功'];
}else{
return ['code' => 1,'data' => [],'msg' => '交易hash值或者本地备注不能为空'];
$request = Yii::$app->request;
$hash = $request->post('hash');
if (empty($hash)) {
return ['code' => 1, 'data' => [], 'msg' => '交易hash值不能为空'];
}
$model = new CoinHashMemo();
$model->setScenario(CoinHashMemo::SCENARIOS_CREATE);
if ($model->load(Yii::$app->request->post(), '') && $model->save()) {
return ['code' => 0, 'data' => [], 'msg' => '本地备注添加成功'];
} else {
return ['code' => 1, 'data' => [], 'msg' => current($model->firstErrors)];
}
}
public function actionUpdateMemo()
{
$request = Yii::$app->request;
$hash = $request->post('hash');
$memo = $request->post('memo');
if (empty($hash)) {
return ['code' => 1, 'data' => [], 'msg' => '交易hash值不能为空'];
}
$model = CoinHashMemo::find()->where(['hash' => $hash])->one();
if (empty($model)) {
return ['code' => 1, 'data' => [], 'msg' => '记录不存在'];
}
CoinHashMemo::updateAll(['memo' => $memo], 'hash = :hash', [':hash' => $hash]);
return ['code' => 0, 'data' => [], 'msg' => '本地备注更新成功'];
}
/**
* 查看本地备注
*/
public function actionGetMemo()
{
$request = Yii::$app->request;
$hash = $request->post('hash');
if($hash){
$memo = Yii::$app->redis->hget('trade_hash_memo',$hash);
return ['code' => 0,'data' => $memo];
}else{
return ['code' => 1,'data' => [],'msg' => '交易hash值不能为空'];
$request = Yii::$app->request;
$hash = $request->post('hash');
$version = $request->post('version', '');
if (empty($hash)) {
return ['code' => 1, 'data' => [], 'msg' => '交易hash值不能为空'];
}
$model = CoinHashMemo::find()->where(['hash' => $hash])->asArray()->one();
if (empty($version)) {
if (empty($model)) {
return ['code' => 1, 'data' => '', 'msg' => '记录不存在'];
}
return ['code' => 0, 'data' => $model['memo']];
} else {
if (empty($model)) {
return ['code' => 0, 'data' => ['memo' => '', 'coins_fee' => ''], 'msg' => '记录不存在'];
}
return ['code' => 0, 'data' => [
'memo' => $model['memo'],
'coins_fee' => $model['coins_fee']
]];
}
}
public function actionSyncToDb()
{
$data = [];
$result = Yii::$app->redis->HGETALL('trade_hash_memo');
foreach ($result as $key => $val) {
if (($key + 2) % 2 == 0) {
$data[] = [
'hash' => $val,
'memo' => $result[$key + 1]
];
}
}
foreach ($data as $val) {
if ('0xc080c6a0937f25d1017e5e88bdcff5c3979810c8a6cc1f3a64cf50970da28fc9' == $val['hash']) continue;
$coin_memo_hash = new CoinHashMemo();
$coin_memo_hash->hash = $val['hash'];
$coin_memo_hash->memo = $val['memo'];
$coin_memo_hash->save();
}
exit;
}
public function actionAddressIsExist()
{
$get = Yii::$app->request->get();
$to = $get['coin_address'] ?? '';
if(empty($to)){
if (empty($to)) {
return ['code' => -1, 'msg' => '参数不能为空'];
}
$coinTokenTransfer = CoinTokenTransfer::find()->where(['coin_address' => $to, 'code' => 1])->one();
if(!$coinTokenTransfer){
if (!$coinTokenTransfer) {
return ['code' => 0, 'msg' => 'record does not exist'];
}
......@@ -68,12 +124,12 @@ class TradeController extends BaseController
{
$get = Yii::$app->request->get();
$to = $get['coin_address'] ?? '';
if(empty($to)){
if (empty($to)) {
return ['code' => -1, 'msg' => '参数不能为空'];
}
$coinTokenTransfer = CoinTokenTransfer::find()->where(['coin_address' => $to, 'code' => 1])->one();
if($coinTokenTransfer){
if ($coinTokenTransfer) {
return ['code' => -1, 'msg' => 'record already exists'];
}
......@@ -86,8 +142,8 @@ class TradeController extends BaseController
$service = new Chain33Service();
$createRawTransaction = $service->createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer);
if(0 != $createRawTransaction['code']){
$createRawTransaction = $service->createTokenRawTransaction($to, $amount, $isToken, $tokenSymbol, $fee, $note, $execer);
if (0 != $createRawTransaction['code']) {
$msg = $createRawTransaction['msg'];
$code = -1;
goto doEnd;
......@@ -98,7 +154,7 @@ class TradeController extends BaseController
$expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){
if (0 != $signRawTx['code']) {
$msg = $signRawTx['msg'];
$code = -1;
goto doEnd;
......@@ -106,7 +162,7 @@ class TradeController extends BaseController
$sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str);
if(0 != $result['code']){
if (0 != $result['code']) {
$msg = $result['msg'];
$code = -1;
goto doEnd;
......
<?php
namespace api\controllers;
use api\base\BaseController;
use common\models\psources\CoinAirDropTrade;
use common\models\psources\CoinPlatform;
use common\service\chain33\Chain33Service;
use Yii;
class WalletController extends BaseController
{
public function actionInfo()
{
$code = 0;
$msg = 'success';
$platform_id = Yii::$app->request->get('platform_id', '');
if(empty($platform_id)){
$msg = '参数不能为空';
$code = -1;
$data = null;
goto doEnd;
}
$data = CoinPlatform::find()->select("name, download_url, introduce")->where(['id' => $platform_id])->asArray()->one();
if(empty($data)){
$msg = '数据不存在';
$data = null;
$code = -1;
goto doEnd;
}
$data['title'] = $data['name'];
unset($data['name']);
doEnd :
return ['code' => $code, 'data' => $data, 'msg' => $msg];
}
public function actionGameTradeUpdate()
{
$coinAirDropTrade = CoinAirDropTrade::find()->where(['attach' => 2 ,'msg' => '0'])->limit(30)->all();
foreach ($coinAirDropTrade as $val){
$fee = 100000;
$amount = 1 * 1e8;
$execer = 'coins';
$note = '';
$service = new Chain33Service();
$createRawTransaction = $service->createRawTransaction($val->coins_address, $amount, $fee, $note, $execer);
if(0 != $createRawTransaction['code']){
continue;
}
$txHex = $createRawTransaction['result'];
$privkey = '72c3879f1f9b523f266a9545b69bd41c0251483a93e21e348e85118afe17a5e2';
$expire = '1m';
$signRawTx = $service->signRawTx($privkey, $txHex, $expire);
if(0 != $signRawTx['code']){
continue;
}
$sign_str = $signRawTx['result'];
$result = $service->sendTransaction($sign_str);
if(0 != $result['code']){
continue;
}
$currentModel = CoinAirDropTrade::findOne($val->id);
$currentModel->attach = 2;
$currentModel->balance = 0;
$currentModel->msg = $result['result'];
$currentModel->save();
}
return ['code' => 1, 'msg' => 'ok'];
}
public function actionGetBalance()
{
$coinAirDropTrade = CoinAirDropTrade::find()->where(['balance' => 0])->limit(60)->all();
$address = [];
foreach ($coinAirDropTrade as $val){
$address[] = $val->coins_address;
}
$service = new Chain33Service();
$execer = 'coins';
$result = $service->getBalance($address, $execer);
if(0 == $result['code']){
$result_balance = $result['result'];
foreach ($result_balance as $val){
$coinAirDropTrade = CoinAirDropTrade::find()->where(['coins_address' => $val['addr']])->one();
if(empty($coinAirDropTrade)) continue;
$coinAirDropTrade->balance = $val['balance'];
$coinAirDropTrade->save();
}
}
return ['code' => 1, 'msg' => 'ok'];
}
}
\ No newline at end of file
<?php
/**
* Created By Sublime Text 3
*
* @authors rlgy <rlgyzhcn@qq.com>
* @date 2018-09-07 17:41:04
*/
namespace backend\assets\applicationCategory;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/application-category';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
\ No newline at end of file
<?php
/**
* Created By Sublime Text 3
*
* @authors rlgy <rlgyzhcn@qq.com>
* @date 2018-09-07 17:41:04
*/
namespace backend\assets\wallet;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/wallet';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ namespace backend\controllers;
use backend\models\coin\CoinApplicationCategoryForm;
use common\models\psources\CoinApplicationCategory;
use common\models\psources\CoinBanner;
use common\models\psources\CoinImage;
use Yii;
......@@ -27,19 +28,22 @@ class ApplicationCategoryController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$name = $request->get('category_name', '');
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$name = $request->get('category_name', '');
$where = [];
if(1 !== $user_platform_id){
if (1 !== $user_platform_id) {
$where[] = ['platform_id' => $user_platform_id];
}
if($name){
if ($name) {
$where[] = ['name' => $name];
}
$data = CoinApplicationCategory::getList($page, $limit, $where);
foreach ($data['data'] as $key => &$val){
$data = CoinApplicationCategory::getList($page, $limit, $where);
foreach ($data['data'] as &$val) {
$val['name'] = str_replace('en-US', 'en', $val['name']);
$val['name'] = str_replace('zh-CN', 'zh', $val['name']);
}
foreach ($data['data'] as $key => &$val) {
$val['coin_name'] = isset($val['platform']['name']) ? $val['platform']['name'] : '';
}
......@@ -55,26 +59,96 @@ class ApplicationCategoryController extends BaseController
{
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$fields = ['id','name','sort','icon','banner','banner_url'];
$fields = ['id', 'name', 'sort', 'icon', 'banner', 'banner_url'];
$params = $this->initParams(Yii::$app->request->post(), $fields);
$application_category = new CoinApplicationCategoryForm();
if($params['id']){ //edit
if ($params['id']) { //edit
$category = CoinApplicationCategory::getCategoryById($params['id']);
$params['platform_id'] = $category->platform_id;
$application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_EDIT);
$application_category->load($params,'');
$application_category->load($params, '');
return $application_category->edit();
}else{
} else {
$params['platform_id'] = Yii::$app->user->identity->platform_id;
$application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_ADD);
$application_category->load($params,'');
$application_category->load($params, '');
return $application_category->add();
}
}
}
public function actionAdd()
{
$model = new CoinApplicationCategoryForm();
$model->setScenario(CoinApplicationCategoryForm::SCENARIO_ADD);
if (Yii::$app->request->isPost) {
$fields = ['id', 'name', 'sort', 'icon', 'banner', 'banner_url'];
$params = $this->initParams(Yii::$app->request->post(), $fields);
$params['platform_id'] = Yii::$app->user->identity->platform_id;
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $params['name'];
$name = [];
foreach ($name_arr as $key => $val) {
$name[$lang[$key]] = $val;
}
unset($params['name']);
$params['name'] = $name;
$model->load($params, '');
$result = $model->add();
if (0 === $result['code']) {
$this->success('添加成功', '/admin/application-category/index');
}
}
return $this->render('add', ['model' => $model]);
}
public function actionEdit()
{
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$fields = ['id', 'name', 'sort', 'icon', 'banner', 'banner_url'];
$params = $this->initParams(Yii::$app->request->post(), $fields);
$application_category = new CoinApplicationCategoryForm();
$category = CoinApplicationCategory::getCategoryById($params['id']);
$params['platform_id'] = $category->platform_id;
$application_category->setScenario(CoinApplicationCategoryForm::SCENARIO_EDIT);
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $params['name'];
$name = [];
foreach ($name_arr as $key => $val) {
$name[$lang[$key]] = $val;
}
unset($params['name']);
$params['name'] = $name;
$application_category->load($params, '');
return $application_category->edit();
}
$id = Yii::$app->request->get('id', null);
$coin = CoinApplicationCategory::getAppCategory($id);
$icon_model = CoinImage::findOne($coin['icon']);
$banner_model = CoinImage::findOne($coin['banner']);
$coin['icon_url'] = empty($icon_model) ? '' : $icon_model->base_url . $icon_model->file_url;
$coin['banner_image_url'] = empty($banner_model) ? '' : $banner_model->base_url . $banner_model->file_url;
$name_arr = json_decode($coin['name'], true);
$coin['name_ja'] = isset($name_arr['ja']) ? $name_arr['ja'] : '';
$coin['name_zh'] = isset($name_arr['zh-CN']) ? $name_arr['zh-CN'] : '';
$coin['name_en'] = isset($name_arr['en-US']) ? $name_arr['en-US'] : '';
$this->layout = false;
return $this->render('edit', ['model' => $coin]);
}
/**
* @return array
* @throws \Throwable
......@@ -102,18 +176,18 @@ class ApplicationCategoryController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('id', '');
$sort = $request->get('sort',1);
if($id){
$id = $request->get('id', '');
$sort = $request->get('sort', 1);
if ($id) {
$category = CoinApplicationCategory::getCategoryById($id);
if(!$category){
return ['code' => 1,'msg' =>'分类不存在,不能设置排序'];
if (!$category) {
return ['code' => 1, 'msg' => '分类不存在,不能设置排序'];
}
$category->sort=$sort;
$category->sort = $sort;
$category->save();
return ['code' => 0,'msg' => '分类排序设置成功'];
}else{
return ['code' => 1 ,'msg' => '分类排序设置失败'];
return ['code' => 0, 'msg' => '分类排序设置成功'];
} else {
return ['code' => 1, 'msg' => '分类排序设置失败'];
}
}
}
......@@ -124,26 +198,26 @@ class ApplicationCategoryController extends BaseController
*/
public function actionBannerIndex()
{
if(Yii::$app->request->isAjax){
if (Yii::$app->request->isAjax) {
$id = Yii::$app->request->get('id');
Yii::$app->response->format = 'json';
$applicate_category = CoinApplicationCategory::getCategoryById($id);
if($applicate_category){
if ($applicate_category) {
$data = CoinBanner::getBannerInfoByIds($applicate_category->h5_banner);
}else{
$data = ['code' => 0,'data' => []];
} else {
$data = ['code' => 0, 'data' => []];
}
return $data;
}else{
} else {
$id = Yii::$app->request->get('id');
if($id){
if ($id) {
$applicate_category = CoinApplicationCategory::getCategoryById($id);
if($applicate_category){
return $this->render('banner-index',['applicate_category' => $applicate_category]);
}else{
if ($applicate_category) {
return $this->render('banner-index', ['applicate_category' => $applicate_category]);
} else {
$this->error('id参数不合法', Yii::$app->request->getReferrer());
}
}else{
} else {
$this->error('id参数不能为空', Yii::$app->request->getReferrer());
}
}
......@@ -155,16 +229,16 @@ class ApplicationCategoryController extends BaseController
*/
public function actionAddBanner()
{
if(Yii::$app->request->isPost){
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$id = Yii::$app->request->post('applicate_category_id',0);
$image_id = Yii::$app->request->post('image',0);
$banner_url = Yii::$app->request->post('banner_url',0);
if($id && $image_id){
$id = Yii::$app->request->post('applicate_category_id', 0);
$image_id = Yii::$app->request->post('image', 0);
$banner_url = Yii::$app->request->post('banner_url', 0);
if ($id && $image_id) {
$coin_applicate_category_form = new CoinApplicationCategoryForm();
return $coin_applicate_category_form->addBanner($id,$image_id,$banner_url);
}else{
return ['code' => 1,'msg'=> 'banner添加失败'];
return $coin_applicate_category_form->addBanner($id, $image_id, $banner_url);
} else {
return ['code' => 1, 'msg' => 'banner添加失败'];
}
}
}
......@@ -180,7 +254,7 @@ class ApplicationCategoryController extends BaseController
$applicate_category_id = Yii::$app->request->get('applicate_category_id');
if ($id && $applicate_category_id) {
$coin_applicateion_category_form = new CoinApplicationCategoryForm();
return $coin_applicateion_category_form->delBanner($id,$applicate_category_id);
return $coin_applicateion_category_form->delBanner($id, $applicate_category_id);
}
return ['code' => 1, 'msg' => 'failed'];
}
......@@ -194,18 +268,18 @@ class ApplicationCategoryController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('id', '');
$enable = $request->get('enable',1);
if($id){
$id = $request->get('id', '');
$enable = $request->get('enable', 1);
if ($id) {
$category = CoinApplicationCategory::getCategoryById($id);
if(!$category){
return ['code' => 1,'msg' =>'分类不存在,不能设置启用状态'];
if (!$category) {
return ['code' => 1, 'msg' => '分类不存在,不能设置启用状态'];
}
$category->enable = $enable;
$category->save();
return ['code' => 0,'msg' => '分类使用状态设置成功'];
}else{
return ['code' => 1 ,'msg' => '分类使用状态设置失败'];
return ['code' => 0, 'msg' => '分类使用状态设置成功'];
} else {
return ['code' => 1, 'msg' => '分类使用状态设置失败'];
}
}
}
......
......@@ -5,13 +5,16 @@
* Date: 2018/10/15
* Time: 10:26
*/
namespace backend\controllers;
use backend\models\coin\CoinApplicationForm;
use common\models\psources\CoinAppCate;
use common\models\psources\CoinApplication;
use common\models\psources\CoinApplicationCategory;
use common\models\psources\CoinImage;
use Yii;
class ApplicationController extends BaseController
{
/**
......@@ -20,28 +23,32 @@ class ApplicationController extends BaseController
*/
public function actionList()
{
if(Yii::$app->request->isAjax){
if (Yii::$app->request->isAjax) {
$id = Yii::$app->request->get('id');
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$data = CoinApplication::getListByCategory($page, $limit, $id);
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$data = CoinApplication::getListByCategory($page, $limit, $id);
foreach ($data['data'] as &$val){
$val['name'] = str_replace('en-US', 'en', $val['name']);
$val['name'] = str_replace('zh-CN', 'zh', $val['name']);
}
return $data;
}else{
} else {
$id = Yii::$app->request->get('id');
if($id){
if ($id) {
$parent_category = CoinApplicationCategory::getCategoryById($id);
$platform_id = Yii::$app->user->identity->platform_id;
$condition = ['platform_id' => $platform_id];
$cate_items = CoinApplicationCategory::getCateItemsArray($condition);
if($parent_category){
return $this->render('list',['parent_category' => $parent_category,'cate_items' => $cate_items]);
}else{
if ($parent_category) {
return $this->render('list', ['parent_category' => $parent_category, 'cate_items' => $cate_items]);
} else {
$this->error('id参数不合法', Yii::$app->request->getReferrer());
}
}else{
} else {
$this->error('id参数不能为空', Yii::$app->request->getReferrer());
}
}
......@@ -53,21 +60,33 @@ class ApplicationController extends BaseController
*/
public function actionAdd()
{
if(Yii::$app->request->isPost){
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$category_id = Yii::$app->request->get('category_id');
$fields = ['category_id','h5_icon','official_url','introduce_image','show_width','show_height','open_type', 'open_type_app', 'platform_type', 'name','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type', 'platform_id'];
$fields = ['category_id', 'h5_icon', 'official_url', 'introduce_image', 'show_width', 'show_height', 'open_type', 'open_type_app', 'platform_type', 'name', 'sort', 'icon', 'type', 'native_url', 'native_login_url', 'h5_url', 'android_url', 'ios_url', 'app_store_url', 'advertise', 'description', 'redirect_type', 'platform_id'];
$data = Yii::$app->request->post();
$data['open_type_app'] = (0 == $data['open_type_app']) ? 1 : $data['open_type_app'];
$params = array_merge($data,['category_id' => $category_id, 'platform_id' => Yii::$app->user->identity->platform_id]);
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $data['name'];
$name = [];
foreach ($name_arr as $key => $val){
$name[$lang[$key]] = $val;
}
unset($data['name']);
$data['name'] = $name;
$data['open_type_app'] = (0 == $data['open_type_app']) ? 1 : $data['open_type_app'];
$params = array_merge($data, ['category_id' => $category_id, 'platform_id' => Yii::$app->user->identity->platform_id]);
$params = $this->initParams($params, $fields);
$coin_applicateion_form = new CoinApplicationForm();
$coin_applicateion_form->setScenario(CoinApplicationForm::SCENARIO_ADD);
$coin_applicateion_form->load($params,'');
$coin_applicateion_form->load($params, '');
$result = $coin_applicateion_form->add();
if($result['code'] == 0){
$this->success('添加成功', '/admin/application/list?id='.$category_id);
}else{
if ($result['code'] == 0) {
$this->success('添加成功', '/admin/application/list?id=' . $category_id);
} else {
$this->error($result['msg'], Yii::$app->request->getReferrer());
}
}
......@@ -82,55 +101,74 @@ class ApplicationController extends BaseController
{
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$fields = ['category_id','id','h5_icon','official_url','introduce_image','show_width','show_height','open_type', 'open_type_app','platform_type', 'name','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type', 'platform_id'];
$fields = ['category_id', 'id', 'h5_icon', 'official_url', 'introduce_image', 'show_width', 'show_height', 'open_type', 'open_type_app', 'platform_type', 'name', 'sort', 'icon', 'type', 'native_url', 'native_login_url', 'h5_url', 'android_url', 'ios_url', 'app_store_url', 'advertise', 'description', 'redirect_type', 'platform_id'];
$data = Yii::$app->request->post();
$data['open_type_app'] = (0 == $data['open_type_app']) ? 1 : $data['open_type_app'];
$params = array_merge($data,['platform_id' => Yii::$app->user->identity->platform_id]);
$lang = [
'zh-CN',
'en-US',
'ja'
];
$name_arr = $data['name'];
$name = [];
foreach ($name_arr as $key => $val){
$name[$lang[$key]] = $val;
}
unset($data['name']);
$data['name'] = $name;
$data['open_type_app'] = (0 == $data['open_type_app']) ? 1 : $data['open_type_app'];
#var_dump($data);exit;
$params = array_merge($data, ['platform_id' => Yii::$app->user->identity->platform_id]);
$params = $this->initParams($params, $fields);
$coin_applicateion_form = new CoinApplicationForm();
$coin_applicateion_form->setScenario(CoinApplicationForm::SCENARIO_EDIT);
$coin_applicateion_form->load($params,'');
$coin_applicateion_form->load($params, '');
return $coin_applicateion_form->edit();
} elseif (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id', null);
$category_id = Yii::$app->request->get('category_id', null);
if ($id) {
$applicate = CoinApplication::getApplicateById($id);
$applicate = CoinApplication::getApplicateById($id);
$coin_ids = [];
if($applicate['icon']){
if ($applicate['icon']) {
$coin_ids[] = $applicate['icon'];
}
if($applicate['h5_icon']){
if ($applicate['h5_icon']) {
$coin_ids[] = $applicate['h5_icon'];
}
if($applicate['introduce_image']){
if ($applicate['introduce_image']) {
$coin_ids[] = $applicate['introduce_image'];
}
if($coin_ids){
if ($coin_ids) {
$coin_items = CoinImage::getItemsByIds($coin_ids);
}
$app_cate = CoinAppCate::getAppCate($category_id,$id);
if($applicate['icon']){
$app_cate = CoinAppCate::getAppCate($category_id, $id);
if ($applicate['icon']) {
$icon_info = $coin_items[$applicate['icon']];
$applicate['icon_url'] =$icon_info['base_url'].$icon_info['file_url'];
}else{
$applicate['icon_url'] ="";
$applicate['icon_url'] = $icon_info['base_url'] . $icon_info['file_url'];
} else {
$applicate['icon_url'] = "";
}
if($applicate['h5_icon']){
if ($applicate['h5_icon']) {
$icon_info = $coin_items[$applicate['h5_icon']];
$applicate['h5_icon_url'] =$icon_info['base_url'].$icon_info['file_url'];
}else{
$applicate['h5_icon_url'] ="";
$applicate['h5_icon_url'] = $icon_info['base_url'] . $icon_info['file_url'];
} else {
$applicate['h5_icon_url'] = "";
}
if($applicate['introduce_image']){
if ($applicate['introduce_image']) {
$icon_info = $coin_items[$applicate['introduce_image']];
$applicate['introduce_image_url'] =$icon_info['base_url'].$icon_info['file_url'];
}else{
$applicate['introduce_image_url'] ="";
$applicate['introduce_image_url'] = $icon_info['base_url'] . $icon_info['file_url'];
} else {
$applicate['introduce_image_url'] = "";
}
$applicate['sort'] = $app_cate->sort;
$name_arr = json_decode($applicate['name'], true);
$applicate['name_ja'] = $name_arr['ja'];
$applicate['name_en'] = $name_arr['en-US'];
$applicate['name_zh'] = $name_arr['zh-CN'];
$this->layout = false;
return $this->render('edit', ['item' => $applicate,'category_id' => $category_id]);
return $this->render('edit', ['item' => $applicate, 'category_id' => $category_id]);
}
}
}
......@@ -149,7 +187,7 @@ class ApplicationController extends BaseController
$category_id = Yii::$app->request->get('category_id');
if ($id && $category_id) {
$coin_applicateion_form = new CoinApplicationForm();
return $coin_applicateion_form->del($id,$category_id);
return $coin_applicateion_form->del($id, $category_id);
}
return ['code' => 1, 'msg' => 'failed'];
}
......@@ -160,13 +198,13 @@ class ApplicationController extends BaseController
*/
public function actionAddCategory()
{
if(Yii::$app->request->isPost){
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$cate_id = Yii::$app->request->post('cate_id');
$app_id = Yii::$app->request->post('app_id');
$sort = Yii::$app->request->post('sort',0);
$cate_id = Yii::$app->request->post('cate_id');
$app_id = Yii::$app->request->post('app_id');
$sort = Yii::$app->request->post('sort', 0);
$coin_applicateion_form = new CoinApplicationForm();
return $coin_applicateion_form->addCategory($app_id,$cate_id,$sort);
return $coin_applicateion_form->addCategory($app_id, $cate_id, $sort);
}
}
......@@ -176,34 +214,34 @@ class ApplicationController extends BaseController
*/
public function actionImageIndex()
{
if(Yii::$app->request->isAjax){
if (Yii::$app->request->isAjax) {
$id = Yii::$app->request->get('id');
$image_category = Yii::$app->request->get('image_category',1);
$image_category = Yii::$app->request->get('image_category', 1);
Yii::$app->response->format = 'json';
$applicate = CoinApplication::getApplicate($id);
if($applicate){
if($image_category == 1){
if ($applicate) {
if ($image_category == 1) {
$data = CoinImage::getItemsByImageIds($applicate->image_ids);
}else if($image_category == 2){
} else if ($image_category == 2) {
$data = CoinImage::getItemsByImageIds($applicate->h5_image_ids);
}else{
$data = ['code' => 0,'data' => []];
} else {
$data = ['code' => 0, 'data' => []];
}
}else{
$data = ['code' => 0,'data' => []];
} else {
$data = ['code' => 0, 'data' => []];
}
return $data;
}else{
} else {
$id = Yii::$app->request->get('id');
if($id){
if ($id) {
$applicate = CoinApplication::getApplicate($id);
if($applicate){
return $this->render('image-index',['applicate' => $applicate]);
}else{
if ($applicate) {
return $this->render('image-index', ['applicate' => $applicate]);
} else {
$this->error('id参数不合法', Yii::$app->request->getReferrer());
}
}else{
} else {
$this->error('id参数不能为空', Yii::$app->request->getReferrer());
}
}
......@@ -215,16 +253,16 @@ class ApplicationController extends BaseController
*/
public function actionAddImage()
{
if(Yii::$app->request->isPost){
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$id = Yii::$app->request->post('applicate_id',0);
$image_id = Yii::$app->request->post('image',0);
$image_category = Yii::$app->request->post('image_category',1);
if($id && $image_id){
$id = Yii::$app->request->post('applicate_id', 0);
$image_id = Yii::$app->request->post('image', 0);
$image_category = Yii::$app->request->post('image_category', 1);
if ($id && $image_id) {
$coin_applicate_form = new CoinApplicationForm();
return $coin_applicate_form->addImage($id,$image_id,$image_category);
}else{
return ['code' => 1,'msg'=> '图片添加失败'];
return $coin_applicate_form->addImage($id, $image_id, $image_category);
} else {
return ['code' => 1, 'msg' => '图片添加失败'];
}
}
}
......@@ -238,10 +276,10 @@ class ApplicationController extends BaseController
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id');
$applicate_id = Yii::$app->request->get('applicate_id');
$image_category = Yii::$app->request->get('image_category',1);
$image_category = Yii::$app->request->get('image_category', 1);
if ($id && $applicate_id) {
$coin_applicateion_form = new CoinApplicationForm();
return $coin_applicateion_form->delImage($id,$applicate_id,$image_category);
return $coin_applicateion_form->delImage($id, $applicate_id, $image_category);
}
return ['code' => 1, 'msg' => 'failed'];
}
......@@ -255,19 +293,19 @@ class ApplicationController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('id', '');
$category_id = $request->get('category_id','');
$sort = $request->get('sort',1);
if($id && $category_id){
$app_cate = CoinAppCate::getAppCate($category_id,$id);
if(!$app_cate){
return ['code' => 1,'msg' =>'应用不存在,不能设置排序'];
$id = $request->get('id', '');
$category_id = $request->get('category_id', '');
$sort = $request->get('sort', 1);
if ($id && $category_id) {
$app_cate = CoinAppCate::getAppCate($category_id, $id);
if (!$app_cate) {
return ['code' => 1, 'msg' => '应用不存在,不能设置排序'];
}
$app_cate->sort=$sort;
$app_cate->sort = $sort;
$app_cate->save();
return ['code' => 0,'msg' => '应用排序设置成功'];
}else{
return ['code' => 1 ,'msg' => '应用排序设置失败'];
return ['code' => 0, 'msg' => '应用排序设置成功'];
} else {
return ['code' => 1, 'msg' => '应用排序设置失败'];
}
}
}
......@@ -281,18 +319,18 @@ class ApplicationController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('id', '');
$enable = $request->get('enable',1);
if($id){
$id = $request->get('id', '');
$enable = $request->get('enable', 1);
if ($id) {
$applicate = CoinApplication::getApplicate($id);
if(!$applicate){
return ['code' => 1,'msg' =>'应用不存在,不能设置启用状态'];
if (!$applicate) {
return ['code' => 1, 'msg' => '应用不存在,不能设置启用状态'];
}
$applicate->enable = $enable;
$applicate->save();
return ['code' => 0,'msg' => '应用使用状态设置成功'];
}else{
return ['code' => 1 ,'msg' => '应用使用状态设置失败'];
return ['code' => 0, 'msg' => '应用使用状态设置成功'];
} else {
return ['code' => 1, 'msg' => '应用使用状态设置失败'];
}
}
}
......@@ -306,18 +344,18 @@ class ApplicationController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('app_id', '');
$h5_image_showtype = $request->get('h5_image_showtype',1);
if($id){
$id = $request->get('app_id', '');
$h5_image_showtype = $request->get('h5_image_showtype', 1);
if ($id) {
$applicate = CoinApplication::getApplicate($id);
if(!$applicate){
return ['code' => 1,'msg' =>'应用不存在'];
if (!$applicate) {
return ['code' => 1, 'msg' => '应用不存在'];
}
$applicate->h5_image_showtype = $h5_image_showtype;
$applicate->save();
return ['code' => 0,'msg' => '显示尺寸设置成功'];
}else{
return ['code' => 1 ,'msg' => '显示尺寸设置失败'];
return ['code' => 0, 'msg' => '显示尺寸设置成功'];
} else {
return ['code' => 1, 'msg' => '显示尺寸设置失败'];
}
}
}
......
......@@ -30,7 +30,7 @@ class CoinBannerController extends BaseController
$request = Yii::$app->request;
$image_url = $request->post('image_url', '');
$banner_url = $request->post('banner_url','');
if($image_url && $banner_url){
if($image_url){
$banner_item = new CoinBannerItem();
$banner_item->banner_url = $banner_url;
$banner_item->image_url = $image_url;
......
......@@ -32,12 +32,12 @@ class CoinController extends BaseController
public function actionIndex()
{
if (Yii::$app->request->isAjax) {
$request = Yii::$app->request;
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$name = $request->get('name', null);
$platform = $request->get('platform', '');
$chain = $request->get('chain', '');
$request = Yii::$app->request;
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$name = $request->get('name', null);
$platform = $request->get('platform', '');
$chain = $request->get('chain', '');
$recommend = $request->get('recommend', '');
$condition = [];
......@@ -69,7 +69,7 @@ class CoinController extends BaseController
}
$platforms = Coin::getPlatformList();
$chains = Coin::getChainList();
return $this->render('index', ['platforms' => $platforms,'chains' => $chains]);
return $this->render('index', ['platforms' => $platforms, 'chains' => $chains]);
}
/**
......@@ -78,7 +78,7 @@ class CoinController extends BaseController
*/
public function actionAdd()
{
$model = new CoinForm();
$model = new CoinForm();
$model->scenario = 'add';
if (Yii::$app->request->isPost) {
$request = Yii::$app->request;
......@@ -89,6 +89,9 @@ class CoinController extends BaseController
$coin = Yii::createObject(Coin::className());
$data = array_merge($request->post(), ['platform_id' => Yii::$app->user->identity->platform_id]);
unset($data['id']);
if (isset($data['optional_name'])) {
$data['optional_name'] = strtoupper($data['optional_name']);
}
$data['name'] = strtoupper($data['name']);
$data['platform'] = strtolower($data['platform']);
$data['chain'] = strtoupper($data['chain']);
......@@ -101,10 +104,10 @@ class CoinController extends BaseController
$introduce_arr = $data['introduce'];
$nickname = [];
$introduce = [];
foreach ($nickname_arr as $key => $val){
foreach ($nickname_arr as $key => $val) {
$nickname[$lang[$key]] = $val;
}
foreach ($introduce_arr as $key => $val){
foreach ($introduce_arr as $key => $val) {
$introduce[$lang[$key]] = $val;
}
unset($data['nickname']);
......@@ -139,13 +142,16 @@ class CoinController extends BaseController
{
if (Yii::$app->request->isPost) {
$model = new CoinForm();
$model->scenario = 'update';
$req = Yii::$app->request;
$model = new CoinForm();
$model->scenario = 'update';
$req = Yii::$app->request;
$data = $req->post();
$data['name'] = strtoupper($data['name']);
$data['platform'] = strtolower($data['platform']);
$data['chain'] = strtoupper($data['chain']);
if (isset($data['optional_name'])) {
$data['optional_name'] = strtoupper($data['optional_name']);
}
Yii::$app->response->format = 'json';
if ($model->load($data) && $model->validate()) {
$platform_id = Yii::$app->user->identity->platform_id;
......@@ -170,16 +176,16 @@ class CoinController extends BaseController
$introduce_arr = $data['introduce'];
$nickname = [];
$introduce = [];
foreach ($nickname_arr as $key => $val){
foreach ($nickname_arr as $key => $val) {
$nickname[$lang[$key]] = $val;
}
foreach ($introduce_arr as $key => $val){
foreach ($introduce_arr as $key => $val) {
$introduce[$lang[$key]] = $val;
}
unset($data['nickname']);
$data['nickname'] = $nickname;
$data['introduce'] = $introduce;
$coin = Yii::createObject(Coin::className());
$coin = Yii::createObject(Coin::className());
$result = $coin->updateOne($data);
if ($result === true) {
return ['code' => 0, 'msg' => 'succeed'];
......@@ -201,7 +207,7 @@ class CoinController extends BaseController
} elseif (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id', null);
if ($id) {
$coin = Coin::findOne(['id' => $id]);
$coin = Coin::findOne(['id' => $id]);
$this->layout = false;
return $this->render('edit', ['model' => $coin]);
}
......@@ -241,17 +247,17 @@ class CoinController extends BaseController
public function actionDelete()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id', 0);
$id = Yii::$app->request->get('id', 0);
if ($id) {
$coin_recommend = CoinRecommend::find()->where(['cid' => $id])->one();
if($coin_recommend){
if ($coin_recommend) {
return ['code' => -1, 'msg' => '推荐币种里有改币种,无法删除'];
}
$model = Coin::findOne(['id' => $id]);
if ($model) {
$platform_id = Yii::$app->user->identity->platform_id;
$can = false;
$can = false;
if (Yii::$app->params['admin'] != Yii::$app->user->id) {
$coin = Coin::find()->where(['id' => $id, 'platform_id' => $platform_id])->one();
......@@ -282,7 +288,7 @@ class CoinController extends BaseController
*/
public function actionGetExchangeListById()
{
$id = Yii::$app->request->get('id', 0);
$id = Yii::$app->request->get('id', 0);
$exchanges = [];
if ($id) {
$exchanges = CoinBusiness::getExchangeListById($id);
......@@ -302,11 +308,11 @@ class CoinController extends BaseController
if (Yii::$app->request->isAjax) {
$get = Yii::$app->request->get();
$page = $get['page'] ?? 1;
$limit = $get['limit'] ?? 10;
$name = $get['name'] ?? '';
$page = $get['page'] ?? 1;
$limit = $get['limit'] ?? 10;
$name = $get['name'] ?? '';
$platform = $get['platform'] ?? '';
$chain = $get['chain'] ?? '';
$chain = $get['chain'] ?? '';
$condition = [];
......@@ -348,8 +354,8 @@ class CoinController extends BaseController
$platforms = CoinPlatform::find()->where(['id' => $user_platform_id])->asArray()->all();
}
return $this->render('package', [
'platforms' => $platforms,
'chains' => $chains,
'platforms' => $platforms,
'chains' => $chains,
'coin_platforms' => $coin_platforms,
]);
}
......@@ -363,7 +369,7 @@ class CoinController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
$id = Yii::$app->request->get('id', '');
$id = Yii::$app->request->get('id', '');
$platform_id = Yii::$app->request->get('platform_id', '');
if (empty($platform_id)) {
return ['code' => -1, 'msg' => '请选择钱包'];
......@@ -385,8 +391,8 @@ class CoinController extends BaseController
}
if ($can) {
//删除
$platform_ids = array_diff($platform_ids, [$platform_id]);
$platform_ids = implode(',', $platform_ids);
$platform_ids = array_diff($platform_ids, [$platform_id]);
$platform_ids = implode(',', $platform_ids);
$coin->platform_id = $platform_ids;
if ($coin->save()) {
return ['code' => 0, 'msg' => '删除成功'];
......@@ -411,10 +417,10 @@ class CoinController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
$get = Yii::$app->request->get();
$get = Yii::$app->request->get();
$platform_id = $get['platform_id'] ?? '';
$name = $get['name'] ?? '';
$chain = $get['chain'] ?? '';
$name = $get['name'] ?? '';
$chain = $get['chain'] ?? '';
foreach (['platform_id' => '平台', 'name' => '币种名称', 'chain' => '币种主链'] as $key => $value) {
if (empty($$key)) {
return ['code' => -1, 'msg' => $value . '不能为空'];
......@@ -423,9 +429,9 @@ class CoinController extends BaseController
$coin = Coin::find()->where(['name' => $name, 'chain' => $chain])->One();
if ($coin) {
$can = false;
$can = false;
$user_platform_id = Yii::$app->user->identity->platform_id;
$platform_ids = explode(',', $coin->platform_id);
$platform_ids = explode(',', $coin->platform_id);
if ($user_platform_id == Yii::$app->params['admin']) {
$can = true;
......@@ -457,9 +463,9 @@ class CoinController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
$get = Yii::$app->request->get();
$get = Yii::$app->request->get();
$platform_id = $get['platform_id'] ?? '';
$coin_ids = $get['coin_ids'] ?? '';
$coin_ids = $get['coin_ids'] ?? '';
foreach (['platform_id' => '钱包', 'coin_ids' => '币种'] as $key => $value) {
if (empty($$key)) {
return ['code' => -1, 'msg' => $value . '不能为空'];
......@@ -467,11 +473,11 @@ class CoinController extends BaseController
}
$user_platform_id = Yii::$app->user->identity->platform_id;
if ($user_platform_id == Yii::$app->params['admin']) {
$coin_id_items = explode(',',$coin_ids);
foreach($coin_id_items as $id) {
$coin_id_items = explode(',', $coin_ids);
foreach ($coin_id_items as $id) {
$coin = Coin::getOneById($id);
if($coin){
$platform_ids = explode(',',$coin->platform_id);
if ($coin) {
$platform_ids = explode(',', $coin->platform_id);
$platform_ids = implode(',', array_unique(array_merge($platform_ids, [$platform_id])));
$coin->platform_id = $platform_ids;
$coin->save();
......@@ -491,9 +497,9 @@ class CoinController extends BaseController
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = Response::FORMAT_JSON;
$get = Yii::$app->request->get();
$get = Yii::$app->request->get();
$platform_id = $get['platform_id'] ?? '';
$coin_ids = $get['coin_ids'] ?? '';
$coin_ids = $get['coin_ids'] ?? '';
foreach (['platform_id' => '钱包', 'coin_ids' => '币种'] as $key => $value) {
if (empty($$key)) {
return ['code' => -1, 'msg' => $value . '不能为空'];
......@@ -501,11 +507,11 @@ class CoinController extends BaseController
}
$user_platform_id = Yii::$app->user->identity->platform_id;
if ($user_platform_id == Yii::$app->params['admin']) {
$coin_id_items = explode(',',$coin_ids);
foreach($coin_id_items as $id) {
$coin_id_items = explode(',', $coin_ids);
foreach ($coin_id_items as $id) {
$coin = Coin::getOneById($id);
if($coin){
$platform_ids = explode(',',$coin->platform_id);
if ($coin) {
$platform_ids = explode(',', $coin->platform_id);
$platform_ids = implode(',', array_diff($platform_ids, [$platform_id]));
$coin->platform_id = $platform_ids;
$coin->save();
......@@ -527,11 +533,11 @@ class CoinController extends BaseController
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$data = Coin::getPlatformList();
foreach ($data as $item){
if($item){
foreach ($data as $item) {
if ($item) {
$platformInfo['platform'] = $item;
$icon = Yii::$app->redis->hget('platform_image_info',$item);
$brower_url = Yii::$app->redis->hget('platform_brower_info',$item);
$icon = Yii::$app->redis->hget('platform_image_info', $item);
$brower_url = Yii::$app->redis->hget('platform_brower_info', $item);
$platformInfo['icon'] = $icon ?? '';
$platformInfo['brower_url'] = $brower_url ?? '';
$platformItems[] = $platformInfo;
......@@ -548,12 +554,12 @@ class CoinController extends BaseController
*/
public function actionAddPlatformCoin()
{
if(Yii::$app->request->isPost){
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$platform = Yii::$app->request->post('platform');
$image = Yii::$app->request->post('image');
if($platform && $image){
Yii::$app->redis->hset('platform_image_info',$platform,$image);
if ($platform && $image) {
Yii::$app->redis->hset('platform_image_info', $platform, $image);
return ['code' => 0, 'msg' => '图片添加成功'];
}
return ['code' => 0, 'msg' => '图片添加失败'];
......@@ -569,13 +575,13 @@ class CoinController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$platform = $request->get('platform','');
$brower_url = $request->get('brower_url','');
if($platform){
Yii::$app->redis->hset('platform_brower_info',$platform,$brower_url);
return ['code' => 0,'msg' => '区块链浏览器地址设置成功'];
}else{
return ['code' => 1 ,'msg' => '区块链浏览器地址设置失败'];
$platform = $request->get('platform', '');
$brower_url = $request->get('brower_url', '');
if ($platform) {
Yii::$app->redis->hset('platform_brower_info', $platform, $brower_url);
return ['code' => 0, 'msg' => '区块链浏览器地址设置成功'];
} else {
return ['code' => 1, 'msg' => '区块链浏览器地址设置失败'];
}
}
}
......
......@@ -71,7 +71,6 @@ class CoinRecommendController extends BaseController
$platform_id = empty($get['platform_id']) ? 1 : $get['platform_id'];
$user_platform_id = Yii::$app->user->identity->platform_id;
#var_dump($platform_id, $user_platform_id);exit;
if (1 != $user_platform_id && $user_platform_id != $platform_id) {
return ['code' => -1, 'msg' => '没有权限修改'];
}
......
......@@ -12,6 +12,7 @@ use common\service\trusteeship\Trusteeship;
use Yii;
use common\models\psources\MinerFee;
use backend\models\coin\MinerFeeForm;
use common\models\psources\Coin;
use \Exception;
class MinerFeeController extends BaseController
......@@ -23,18 +24,18 @@ class MinerFeeController extends BaseController
{
if (Yii::$app->request->isAjax) {
$request = Yii::$app->request;
$type = $request->get('type',1);
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$type = $request->get('type', 1);
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$data = MinerFee::getList($page, $limit, [['type' => $type]]);//数据不多
if ($data['count'] > 0) {
$data['code'] = 0;
} else {
$data['code'] = 1;
$data['msg'] = '数据为空';
$data['msg'] = '数据为空';
}
Yii::$app->response->format = 'json';
Yii::$app->response->data = $data;
Yii::$app->response->data = $data;
Yii::$app->response->send();
}
return $this->render('index');
......@@ -45,27 +46,32 @@ class MinerFeeController extends BaseController
*/
public function actionAdd()
{
$model = new MinerFeeForm();
$model->scenario = 'add';
$type = Yii::$app->request->get('type',1);
$model = new MinerFeeForm();
$type = Yii::$app->request->get('type', 1);
if (MinerFeeForm::TYPE_WALLET == $type) {
$model->setScenario(MinerFeeForm::SCENARIOS_WALLET_CREATE);
} else {
$model->setScenario(MinerFeeForm::SCENARIOS_TRUSTEESHIP_CREATE);
}
$platforms = Coin::getChainList();
if (Yii::$app->request->isPost) {
$request = Yii::$app->request;
if ($model->load($request->post()) && $model->validate()) {
$minerFee = new MinerFee();
$minerFee->platform = $model->platform;
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
$minerFee->type = $type;
$minerFee = new MinerFee();
$minerFee->platform = $model->platform;
if (MinerFeeForm::TYPE_WALLET == $type) {
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
} else {
$minerFee->fee = $model->fee;
}
$minerFee->type = $type;
$minerFee->create_at = date('Y-m-d H:i:s');
$minerFee->update_at = date('Y-m-d H:i:s');
try {
$minerFee->save();
$this->success('添加成功', '/admin/miner-fee/cost');
} catch (Exception $exception) {
$this->error($exception->getMessage(), '/admin/miner-fee/add');
}
$minerFee->save();
$this->success('添加成功', '/admin/miner-fee/cost');
}
//表单验证失败
$errors = $model->errors;
......@@ -77,7 +83,7 @@ class MinerFeeController extends BaseController
}
$this->error($errors, Yii::$app->request->getReferrer());
}
return $this->render('add', ['model' => $model]);
return $this->render('add', ['model' => $model, 'platforms' => $platforms, 'type' => $type]);
}
/**
......@@ -86,24 +92,30 @@ class MinerFeeController extends BaseController
*/
public function actionEdit()
{
$model = new MinerFeeForm();
$model->scenario = 'edit';
$id = Yii::$app->request->get('id', null);
$model = new MinerFeeForm();
$id = Yii::$app->request->get('id', null);
$type = Yii::$app->request->get('type', 1);
if (MinerFeeForm::TYPE_WALLET == $type) {
$model->setScenario(MinerFeeForm::SCENARIOS_WALLET_UPDATE);
} else {
$model->setScenario(MinerFeeForm::SCENARIOS_TRUSTEESHIP_UPDATE);
}
if ($id) {
$minerFee = MinerFee::findOne(['id' => $id]);
$platforms = Coin::getChainList();
if ($minerFee) {
if (Yii::$app->request->isPost) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
$minerFee->update_at = date('Y-m-d H:i:s');
try {
$minerFee->save();
$this->success('更新成功', '/admin/miner-fee/cost');
} catch (Exception $exception) {
$this->error($exception->getMessage(), Yii::$app->request->getReferrer());
if (MinerFeeForm::TYPE_WALLET == $type) {
$minerFee->min = $model->min;
$minerFee->max = $model->max;
$minerFee->level = $model->level;
} else {
$minerFee->fee = $model->fee;
}
$minerFee->update_at = date('Y-m-d H:i:s');
$minerFee->save();
$this->success('更新成功', '/admin/miner-fee/cost');
}
$errors = $model->errors;
if ($errors) {
......@@ -114,7 +126,7 @@ class MinerFeeController extends BaseController
}
$this->error($errors, Yii::$app->request->getReferrer());
}
return $this->render('edit', ['model' => $minerFee]);
return $this->render('edit', ['model' => $minerFee, 'platforms' => $platforms, 'type' => $type]);
}
}
$this->error('公告不存在', Yii::$app->request->getReferrer());
......@@ -149,24 +161,24 @@ class MinerFeeController extends BaseController
Yii::$app->response->format = 'json';
$trusteeship = new Trusteeship();
$data = $trusteeship->getSupportCoin();
if($data['code'] != 0){
if ($data['code'] != 0) {
return ['code' => -1, 'msg' => $data['msg']];
}else{
$trusteeship_coins = array_column($data['data'],'currency');
} else {
$trusteeship_coins = array_column($data['data'], 'currency');
$list = MinerFee::getList(1, 999, [['type' => 2]]);
if($list){
$local_coins = array_column($list['data'],'platform');
}else{
if ($list) {
$local_coins = array_column($list['data'], 'platform');
} else {
$local_coins = [];
}
$need_add_coins = array_diff($trusteeship_coins,$local_coins);
if(!$need_add_coins){
return ['code' => 0,'msg' => '币种库已经最新'];
$need_add_coins = array_diff($trusteeship_coins, $local_coins);
if (!$need_add_coins) {
return ['code' => 0, 'msg' => '币种库已经最新'];
}
foreach($need_add_coins as $item){
$minerFee = new MinerFee();
$minerFee->platform = $item;
$minerFee->type = 2;
foreach ($need_add_coins as $item) {
$minerFee = new MinerFee();
$minerFee->platform = $item;
$minerFee->type = 2;
$minerFee->create_at = date('Y-m-d H:i:s');
$minerFee->update_at = date('Y-m-d H:i:s');
$minerFee->save();
......@@ -184,19 +196,19 @@ class MinerFeeController extends BaseController
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$id = $request->get('id', '');
$fee = $request->get('fee',0);
if($id){
$id = $request->get('id', '');
$fee = $request->get('fee', 0);
if ($id) {
$minerFee = MinerFee::find()->where(['id' => $id])->one();
if(!$minerFee){
return ['code' => 1,'msg' =>'币种旷工费异常'];
if (!$minerFee) {
return ['code' => 1, 'msg' => '币种旷工费异常'];
}
$minerFee->fee = $fee;
$minerFee->update_at = date('Y-m-d H:i:s');
$minerFee->save();
return ['code' => 0,'msg' => '旷工费设置成功'];
}else{
return ['code' => 1 ,'msg' => '旷工费设置失败'];
return ['code' => 0, 'msg' => '旷工费设置成功'];
} else {
return ['code' => 1, 'msg' => '旷工费设置失败'];
}
}
}
......
......@@ -5,14 +5,116 @@
* Date: 2018/12/17
* Time: 10:13
*/
namespace backend\controllers;
use common\models\psources\CoinApplicationCategory;
use backend\models\coin\CoinPlatformForm;
use common\models\psources\CoinPlatform;
use Yii;
class WalletController extends BaseController
{
public function actionList()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$request = Yii::$app->request;
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$name = $request->get('name', '');
$where = [];
if ($name) {
$where[] = ['name' => $name];
}
$data = CoinPlatform::getList($page, $limit, $where);
$data['code'] = 0;
Yii::$app->response->format = 'json';
return $data;
}
return $this->render('index');
}
public function actionAdd()
{
$model = new CoinPlatformForm();
$model->scenario = 'add';
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post();
if ($model->load($data, '') && $model->validate()) {
$coin = Yii::createObject(CoinPlatform::className());
$result = $coin->addOne($data);
if ($result === true) {
$this->success('添加成功', '/admin/wallet/list');
}
}
//表单验证失败
$errors = $model->errors;
if ($errors) {
foreach ($errors as $key => $item) {
$errors = $item[0];
break;
}
} elseif (isset($result) && $result['code'] != 0) {
$errors = $result['message'];
}
$this->error($errors, Yii::$app->request->getReferrer());
}
return $this->render('add', ['model' => $model]);
}
public function actionEdit()
{
if (Yii::$app->request->isPost) {
$model = new CoinPlatformForm();
$model->scenario = 'update';
$data = Yii::$app->request->post();
Yii::$app->response->format = 'json';
if ($model->load($data, '') && $model->validate()) {
$coin = Yii::createObject(CoinPlatform::className());
$result = $coin->updateOne($data);
if ($result === true) {
return ['code' => 0, 'msg' => 'succeed'];
}
}
$errors = $model->errors;
if ($errors) {
foreach ($errors as $key => $item) {
$errors = $item[0];
break;
}
} elseif (isset($result) && $result['code'] != 0) {
$errors = $result['message'];
}
return ['code' => 1, 'msg' => $errors];
} elseif (Yii::$app->request->isGet) {
$id = Yii::$app->request->get('id', null);
if ($id) {
$coin = CoinPlatform::findOne(['id' => $id]);
$this->layout = false;
return $this->render('edit', ['model' => $coin]);
}
}
}
public function actionDelete()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id', 0);
if ($id) {
$model = CoinPlatform::findOne(['id' => $id]);
if ($model) {
try {
$model->delete();
return ['code' => 0, 'msg' => 'succeed'];
} catch (\Throwable $t) {
return ['code' => $t->getCode(), 'msg' => $t->getMessage()];
}
}
}
return ['code' => -1, 'msg' => '删除失败'];
}
/**
* @return string
* 设置钱包密码
......@@ -24,23 +126,21 @@ class WalletController extends BaseController
$new_passwd = Yii::$app->request->post('new_passwd');
$confirm_passwd = Yii::$app->request->post('confirm_passwd');
$passwd = Yii::$app->redis->get('wallet_passwd');
if(!$passwd){
Yii::$app->redis->set('wallet_passwd',$new_passwd);
if (!$passwd) {
Yii::$app->redis->set('wallet_passwd', $new_passwd);
$this->success('钱包密码设置成功', Yii::$app->request->getReferrer());
}
if($passwd != $old_passwd){
if ($passwd != $old_passwd) {
$this->error('原始密码错误', Yii::$app->request->getReferrer());
}
if($new_passwd != $confirm_passwd){
if ($new_passwd != $confirm_passwd) {
$this->error('确认密码和设置的密码不一致', Yii::$app->request->getReferrer());
}
Yii::$app->redis->set('wallet_passwd',$new_passwd);
Yii::$app->redis->set('wallet_passwd', $new_passwd);
$this->success('钱包密码设置成功', Yii::$app->request->getReferrer());
}
return $this->render('set-passwd');
}
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
* Date: 2018/10/12
* Time: 19:10
*/
namespace backend\models\coin;
use backend\models\BaseForm;
......@@ -12,6 +13,7 @@ use common\models\psources\CoinAppCate;
use common\models\psources\CoinApplicateRecommend;
use common\models\psources\CoinApplication;
use Yii;
class CoinApplicationForm extends BaseForm
{
const SCENARIO_ADD = 'add';
......@@ -46,8 +48,8 @@ class CoinApplicationForm extends BaseForm
public function scenarios()
{
return [
self::SCENARIO_ADD => ['category_id','name','h5_icon','official_url','introduce_image','show_width','show_height','open_type', 'open_type_app', 'platform_type','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type', 'platform_id'],
self::SCENARIO_EDIT => ['category_id','id','h5_icon','official_url','introduce_image','show_width','show_height','open_type', 'open_type_app', 'platform_type','name','sort','icon','type','native_url','native_login_url','h5_url','android_url','ios_url','app_store_url','advertise','description','redirect_type', 'platform_id'],
self::SCENARIO_ADD => ['category_id', 'name', 'h5_icon', 'official_url', 'introduce_image', 'show_width', 'show_height', 'open_type', 'open_type_app', 'platform_type', 'sort', 'icon', 'type', 'native_url', 'native_login_url', 'h5_url', 'android_url', 'ios_url', 'app_store_url', 'advertise', 'description', 'redirect_type', 'platform_id'],
self::SCENARIO_EDIT => ['category_id', 'id', 'h5_icon', 'official_url', 'introduce_image', 'show_width', 'show_height', 'open_type', 'open_type_app', 'platform_type', 'name', 'sort', 'icon', 'type', 'native_url', 'native_login_url', 'h5_url', 'android_url', 'ios_url', 'app_store_url', 'advertise', 'description', 'redirect_type', 'platform_id'],
];
}
......@@ -55,42 +57,42 @@ class CoinApplicationForm extends BaseForm
public function attributeLabels()
{
return [
'id' => 'ID',
'category_id' => '分类ID',
'name' => '名称',
'icon' => '图标',
'h5_icon' => 'h5图标',
'official_url' => '官方链接',
'introduce_image' => '介绍图',
'sort' => '排序',
'type' => '类型',
'native_url' => '原生链接',
'native_login_url' => '原生登录链接',
'h5_url' => 'h5链接',
'android_url' => '安卓链接',
'ios_url' => 'ios企业版链接',
'app_store_url' => 'ios商店版链接',
'advertise' => '宣传语',
'description' => '介绍',
'redirect_type' => '跳转方式',
'show_width' => '显示宽度',
'show_height' => '显示高度',
'open_type' => 'H5打开方式 PC版',
'open_type_app' => 'H5打开方式 APP版',
'platform_type' => '所属平台',
'platform_id' => '平台Id'
'id' => 'ID',
'category_id' => '分类ID',
'name' => '名称',
'icon' => '图标',
'h5_icon' => 'h5图标',
'official_url' => '官方链接',
'introduce_image' => '介绍图',
'sort' => '排序',
'type' => '类型',
'native_url' => '原生链接',
'native_login_url' => '原生登录链接',
'h5_url' => 'h5链接',
'android_url' => '安卓链接',
'ios_url' => 'ios企业版链接',
'app_store_url' => 'ios商店版链接',
'advertise' => '宣传语',
'description' => '介绍',
'redirect_type' => '跳转方式',
'show_width' => '显示宽度',
'show_height' => '显示高度',
'open_type' => 'H5打开方式 PC版',
'open_type_app' => 'H5打开方式 APP版',
'platform_type' => '所属平台',
'platform_id' => '平台Id'
];
}
public function rules()
{
return [
[['name','category_id'], 'required', 'on' => self::SCENARIO_ADD],
[['category_id'], 'required', 'on' => self::SCENARIO_ADD],
['sort', 'default', 'value' => 1],
['sort', 'integer'],
['icon', 'default', 'value' => 0],
['advertise','string', 'length' => [0, 20]],
['description','string', 'length' => [0, 500]],
['advertise', 'string', 'length' => [0, 20]],
['description', 'string', 'length' => [0, 500]],
['type', 'default', 'value' => 1],
['redirect_type', 'default', 'value' => 1],
['show_height', 'default', 'value' => 0],
......@@ -102,14 +104,14 @@ class CoinApplicationForm extends BaseForm
public function checkName($attribute, $params)
{
$res = CoinApplication::find()->where(['name' => $this->$attribute])->one();
$scenario = $this->getScenario();
if($scenario == self::SCENARIO_ADD){
if($res){
$this->addError($attribute,'应用名称已存在');
$scenario = $this->getScenario();
if ($scenario == self::SCENARIO_ADD) {
if ($res) {
$this->addError($attribute, '应用名称已存在');
}
}else if($scenario == self::SCENARIO_EDIT){
if($res && $res->id != $this->id){
$this->addError($attribute,'应用名称已存在');
} else if ($scenario == self::SCENARIO_EDIT) {
if ($res && $res->id != $this->id) {
$this->addError($attribute, '应用名称已存在');
}
}
}
......@@ -119,13 +121,13 @@ class CoinApplicationForm extends BaseForm
*/
public function add()
{
if($this->validate()){
if ($this->validate()) {
$tr = CoinApplication::getDb()->beginTransaction();
try{
try {
$coin_applicate = new CoinApplication();
$coin_applicate->setAttributes($this->attributes,false);
$coin_applicate->setAttributes($this->attributes, false);
$res = $coin_applicate->save();
if($res){
if ($res) {
$coin_app_cate = new CoinAppCate();
$coin_app_cate->app_id = $coin_applicate->id;
$coin_app_cate->cate_id = $this->category_id;
......@@ -133,15 +135,15 @@ class CoinApplicationForm extends BaseForm
$coin_app_cate->save();
$tr->commit();
}
return ['code' => 0,'msg' => '应用添加成功!'];
}catch (\Exception $e){
return ['code' => 0, 'msg' => '应用添加成功!'];
} catch (\Exception $e) {
$tr->rollBack();
return ['code' => 1,'msg' => $e->getMessage()];
return ['code' => 1, 'msg' => $e->getMessage()];
}
}else{
} else {
$error = self::getModelError($this);
return ['code' => 1,'msg' => $error];
return ['code' => 1, 'msg' => $error];
}
}
......@@ -150,29 +152,29 @@ class CoinApplicationForm extends BaseForm
*/
public function edit()
{
if($this->validate()){
if ($this->validate()) {
$tr = CoinApplication::getDb()->beginTransaction();
try{
try {
$coin_applicate = CoinApplication::getApplicate($this->id);
if($coin_applicate){
if ($coin_applicate) {
$image_ids = $coin_applicate->image_ids;
$coin_applicate->setAttributes($this->attributes,false);
$coin_applicate->setAttributes($this->attributes, false);
$coin_applicate->image_ids = $image_ids;
$coin_applicate->save();
CoinApplicateRecommend::updateName($this->id,2,$this->name); //更新首页推荐name
CoinAppCate::updateSort($this->category_id,$this->id,$this->sort);
CoinApplicateRecommend::updateName($this->id, 2, $this->name); //更新首页推荐name
CoinAppCate::updateSort($this->category_id, $this->id, $this->sort);
$tr->commit();
return ['code' => 0,'msg' => '应用修改成功!'];
}else{
return ['code' => 1,'msg' => '应用不存在'];
return ['code' => 0, 'msg' => '应用修改成功!'];
} else {
return ['code' => 1, 'msg' => '应用不存在'];
}
}catch (\Exception $e){
} catch (\Exception $e) {
$tr->rollBack();
return ['code' => 1,'msg' => $e->getMessage()];
return ['code' => 1, 'msg' => $e->getMessage()];
}
}else{
} else {
$error = self::getModelError($this);
return ['code' => 1,'msg' => $error];
return ['code' => 1, 'msg' => $error];
}
}
......@@ -180,27 +182,27 @@ class CoinApplicationForm extends BaseForm
* @param $id
* 删除应用
*/
public function del($id,$category_id)
public function del($id, $category_id)
{
$coin_app_cate = CoinAppCate::getAppCate($category_id,$id);
if($coin_app_cate){
$coin_app_cate = CoinAppCate::getAppCate($category_id, $id);
if ($coin_app_cate) {
$tr = CoinApplication::getDb()->beginTransaction();
try{
try {
$cate_count = CoinAppCate::getCateCountByAppId($id);
if($cate_count == 1){
$applicate = CoinApplication::getApplicate($id);
$applicate->delete();
CoinApplicateRecommend::del($id,2); //删除首页推荐
if ($cate_count == 1) {
$applicate = CoinApplication::getApplicate($id);
$applicate->delete();
CoinApplicateRecommend::del($id, 2); //删除首页推荐
}
$coin_app_cate->delete();
$tr->commit();
return ['code' => 0,'msg' => '应用分类删除成功'];
}catch (\Exception $e){
return ['code' => 1,'msg' => $e->getMessage()];
return ['code' => 0, 'msg' => '应用分类删除成功'];
} catch (\Exception $e) {
return ['code' => 1, 'msg' => $e->getMessage()];
}
}else{
return ['code' => 1,'msg' => '应用分类不存在'];
} else {
return ['code' => 1, 'msg' => '应用分类不存在'];
}
}
......@@ -209,68 +211,68 @@ class CoinApplicationForm extends BaseForm
* @param $id
* 添加所属分类
*/
public function addCategory($id,$category_id,$sort)
public function addCategory($id, $category_id, $sort)
{
$coin_app_cate = CoinAppCate::getAppCate($category_id,$id);
if($coin_app_cate){
return ['code' => 1,'msg' => '应用已属于该分类,不能再添加'];
}else{
$coin_app_cate = CoinAppCate::getAppCate($category_id, $id);
if ($coin_app_cate) {
return ['code' => 1, 'msg' => '应用已属于该分类,不能再添加'];
} else {
$coin_app_cate = new CoinAppCate();
$coin_app_cate->app_id = $id;
$coin_app_cate->cate_id = $category_id;
$coin_app_cate->sort = $sort;
$coin_app_cate->save();
return ['code' => 0,'msg' => '应用所属分类添加成功'];
return ['code' => 0, 'msg' => '应用所属分类添加成功'];
}
}
public function addImage($id,$image_id,$image_category)
public function addImage($id, $image_id, $image_category)
{
$coin_applicate = CoinApplication::getApplicate($id);
if($coin_applicate){
if($image_category == 1){ //app图片
if ($coin_applicate) {
if ($image_category == 1) { //app图片
$image_ids_field = 'image_ids';
}else if($image_category == 2){ //h5图片
} else if ($image_category == 2) { //h5图片
$image_ids_field = 'h5_image_ids';
}
$image_ids = $coin_applicate->$image_ids_field;
if($image_ids){
$image_items = explode(',',$image_ids);
array_push($image_items,$image_id);
$image_ids = implode(",",$image_items);
}else{
if ($image_ids) {
$image_items = explode(',', $image_ids);
array_push($image_items, $image_id);
$image_ids = implode(",", $image_items);
} else {
$image_ids = $image_id;
}
$coin_applicate->$image_ids_field = $image_ids;
$coin_applicate->save();
return ['code' => 0,'msg' => '图片添加成功'];
}else{
return ['code' => 1,'msg' => '应用不存在'];
return ['code' => 0, 'msg' => '图片添加成功'];
} else {
return ['code' => 1, 'msg' => '应用不存在'];
}
}
public function delImage($image_id,$id,$image_category)
public function delImage($image_id, $id, $image_category)
{
$coin_applicate = CoinApplication::getApplicate($id);
if($coin_applicate){
if($image_category == 1){ //app图片
if ($coin_applicate) {
if ($image_category == 1) { //app图片
$image_ids_field = 'image_ids';
}else if($image_category == 2){ //h5图片
} else if ($image_category == 2) { //h5图片
$image_ids_field = 'h5_image_ids';
}
$image_ids = $coin_applicate->$image_ids_field;
$image_items = explode(',',$image_ids);
$image_items = array_diff($image_items,[$image_id]);
if($image_items){
$image_ids = implode(",",$image_items);
}else{
$image_items = explode(',', $image_ids);
$image_items = array_diff($image_items, [$image_id]);
if ($image_items) {
$image_ids = implode(",", $image_items);
} else {
$image_ids = '';
}
$coin_applicate->$image_ids_field = $image_ids;
$coin_applicate->save();
return ['code' => 0,'msg' => '图片删除成功'];
}else{
return ['code' => 1,'msg' => '应用不存在'];
return ['code' => 0, 'msg' => '图片删除成功'];
} else {
return ['code' => 1, 'msg' => '应用不存在'];
}
}
......
......@@ -14,6 +14,7 @@ class CoinForm extends Model
{
public $id;
public $name;
public $optional_name;
public $nickname;
public $sid;
public $icon;
......@@ -49,6 +50,7 @@ class CoinForm extends Model
return [
'id' => 'ID',
'name' => '名称',
'optional_name' => '可选简称',
'nickname' => '别称',
'sid' => '全称',
'icon' => '图标',
......@@ -74,6 +76,7 @@ class CoinForm extends Model
'add' => [
'id',
'name',
'optional_name',
'nickname',
'sid',
'icon',
......@@ -92,6 +95,7 @@ class CoinForm extends Model
'update' => [
'id',
'name',
'optional_name',
'nickname',
'sid',
'icon',
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午4:05
*/
namespace backend\models\coin;
use yii\base\Model;
class CoinPlatformForm extends Model
{
public $id;
public $name;
public $download_url;
public $introduce;
public function formName()
{
return '';
}
public function rules()
{
return [
[['name'], 'required', 'on' => 'add'],
[['id', 'name'], 'required', 'on' => 'update'],
];
}
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => '名称',
'download_url' => '下载链接',
'introduce' => '介绍'
];
}
public function scenarios()
{
return [
'add' => [
'id',
'name',
],
'update' => [
'id',
'name',
],
];
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@
namespace backend\models\coin;
use common\models\psources\MinerFee;
use yii\base\Model;
class MinerFeeForm extends Model
......@@ -18,6 +19,17 @@ class MinerFeeForm extends Model
public $min;
public $level;
public $type;
public $fee;
//定义场景
const SCENARIOS_WALLET_CREATE = 'wallet_create';
const SCENARIOS_WALLET_UPDATE = 'wallet_update';
const SCENARIOS_TRUSTEESHIP_CREATE = 'trusteeship_create';
const SCENARIOS_TRUSTEESHIP_UPDATE = 'trusteeship_update';
const TYPE_WALLET = 1; //币钱包
const TYPE_TRUSTEESHIP = 2; //托管钱包
public function formName()
{
......@@ -27,27 +39,39 @@ class MinerFeeForm extends Model
public function rules()
{
return [
[['id', 'min', 'max', 'level'], 'required', 'on' => 'edit'],
[['platform', 'min', 'max', 'level'], 'required', 'on' => 'add'],
[['platform', 'min', 'max', 'level', 'fee'], 'required'],
[['id', 'max', 'min', 'level'], 'number'],
['platform', 'isExist','on' => [self:: SCENARIOS_TRUSTEESHIP_CREATE]]
];
}
public function isExist($attribute, $params)
{
$count = MinerFee::find()->where(['platform' => $this->platform, 'type' => self::TYPE_TRUSTEESHIP])->count();
if($count > 0) {
$this->addError('platform', '该平台已存在');
}
}
public function scenarios()
{
return [
'add' => ['platform', 'min', 'max', 'level'],
'edit' => ['id', 'min', 'max', 'level'],
$scenarios = [
self:: SCENARIOS_WALLET_CREATE => ['platform', 'min', 'max', 'level'],
self:: SCENARIOS_WALLET_UPDATE => ['platform', 'min', 'max', 'level'],
self:: SCENARIOS_TRUSTEESHIP_CREATE => ['platform', 'type', 'fee'],
self:: SCENARIOS_TRUSTEESHIP_UPDATE => ['platform', 'type', 'fee'],
];
return array_merge(parent:: scenarios(), $scenarios);
}
public function attributeLabels()
{
return [
'platform' => '平台',
'min' => '最小值',
'max' => '最大值',
'level' => '分档',
'min' => '最小值',
'max' => '最大值',
'level' => '分档',
'fee' => '手续费'
];
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午6:23
*/
?>
<h4>添加应用分类</h4>
<style>
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md12">
<form class="layui-form" method="post" action="" id="application-category-edit">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input name="id" type="hidden" value="">
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" required lay-verify="required" placeholder=""
autocomplete="off" value=""
class="layui-input">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">排序</label>
<div class="layui-input-block" style="width: 250px">
<input type="text" name="sort" required lay-verify="required" placeholder=""
autocomplete="off" value=""
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">图标</label>
<div class="layui-input-block">
<img src="" style="margin-top: 11px; max-width: 32px; max-height: 32px"
id="icon1">
</div>
<input type="hidden" name="icon" value="">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload1" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">banner</label>
<div class="layui-input-block">
<img src="" style="margin-top: 11px; max-width: 32px; max-height: 32px" id="icon2">
</div>
<input type="hidden" name="banner" value="">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload2" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">banner链接</label>
<div class="layui-input-block" style="width: 500px">
<input type="text" name="banner_url" required lay-verify="required" placeholder=""
autocomplete="off" class="layui-input" value="">
</div>
</div>
<div class="layui-form-item">
<button class="layui-btn">提交</button>
</div>
</form>
</div>
</div>
<script>
var laydate = layui.laydate;
laydate.render({
elem: "#time1"
});
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/image/upload',
data: {_csrf: $_csrf},
done: function (res) {
if(res.code == 0){
$("input[name='icon']").val(res.data.image_id);
$("#icon1").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
uploader.render({
elem: "#upload2",
url: '/admin/image/upload',
data: {_csrf: $_csrf,image_type:2},
done: function (res) {
if(res.code == 0){
$("input[name='banner']").val(res.data.image_id);
$("#icon2").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
//form render
var form = layui.form;
form.render();
</script>
......@@ -11,7 +11,7 @@
width: 100px;
}
</style>
<h4>所属分类---<?= $applicate_category->name ?></h4>
<h4>所属分类---<?= $applicate_category->name["zh-CN"] ?></h4>
<div class="layui-row" style="padding: 5px;">
<div class="layui-tab layui-tab-card">
<ul class="layui-tab-title">
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午6:23
*/
?>
<style>
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md12">
<form class="layui-form" method="post" action="" id="application-category-edit">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input name="id" type="hidden" value="<?= $model['id'] ?>">
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="<?= $model['name_zh'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="<?= $model['name_en'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name[]" value="<?= $model['name_ja'] ?>">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">排序</label>
<div class="layui-input-block" style="width: 250px">
<input type="text" name="sort" required lay-verify="required" placeholder=""
autocomplete="off" value="<?= $model['sort'] ?>"
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">图标</label>
<div class="layui-input-block">
<img src="<?= $model['icon_url'] ?>" style="margin-top: 11px; max-width: 32px; max-height: 32px"
id="icon1">
</div>
<input type="hidden" name="icon" value="<?= $model['icon'] ?>">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload1" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">banner</label>
<div class="layui-input-block">
<img src="<?= $model['banner_image_url'] ?>" style="margin-top: 11px; max-width: 32px; max-height: 32px" id="icon2">
</div>
<input type="hidden" name="banner" value="<?= $model['banner'] ?>">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload2" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">banner链接</label>
<div class="layui-input-block">
<input type="text" name="banner_url" required lay-verify="required" placeholder=""
autocomplete="off" class="layui-input" value="<?= $model['banner_url'] ?>">
</div>
</div>
</form>
</div>
</div>
<script>
var laydate = layui.laydate;
laydate.render({
elem: "#time1"
});
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/image/upload',
data: {_csrf: $_csrf},
done: function (res) {
if(res.code == 0){
$("input[name='icon']").val(res.data.image_id);
$("#icon1").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
uploader.render({
elem: "#upload2",
url: '/admin/image/upload',
data: {_csrf: $_csrf,image_type:2},
done: function (res) {
if(res.code == 0){
$("input[name='banner']").val(res.data.image_id);
$("#icon2").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
//form render
var form = layui.form;
form.render();
</script>
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/11
* Time: 17:41
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午9:59
*/
?>
use backend\assets\applicationCategory\IndexAsset;
IndexAsset::register($this);
?>
<style>
.layui-table-tips-c {
padding: 0px;
}
</style>
<h4>应用分类列表</h4>
<div class="layui-row">
<div class="layui-col-md1">
<a href="/admin/application-category/add">
<button class="layui-btn layui-btn-default" id="add">添加应用分类</button>
</div>
<div class="layui-col-md8">
<form class="layui-form" method="get" action="">
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 120px;">应用分类名称</label>
<div class="layui-input-inline">
<input class="layui-input" name="category_name">
</div>
</div>
<div class="layui-inline">
<button class="layui-btn" lay-submit lay-filter="search">搜索</button>
</div>
</form>
</a>
</div>
</div>
<div class="layui-col-md10">
<div class="layui-row">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<!-- 添加页面 -->
<div class="layui-row add" style="display: none;padding: 5px;" id="_form">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form" action="javascript:void(0)" id="form1" 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 layui-form-text">
<label class="layui-form-label">名称</label>
<div class="layui-input-block">
<input type="text" name="name" required lay-verify="required" placeholder="" autocomplete="off"
class="layui-input">
</div>
</div>
<div class="layui-form-item layui-form-text">
<label class="layui-form-label">排序</label>
<div class="layui-input-block">
<input type="text" name="sort" required lay-verify="required" placeholder=""
autocomplete="off"
class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">图标</label>
<div class="layui-input-block">
<img src="" style="margin-top: 11px; max-width: 32px; max-height: 32px"
id="icon1">
</div>
<input type="hidden" name="icon" value="">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload1" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label" >banner</label>
<div class="layui-input-block">
<img src="" style="margin-top: 11px; max-width: 32px; max-height: 32px"
id="icon2">
</div>
<input type="hidden" name="banner" value="">
</div>
<div class="layui-inline" style="margin-left: 50px;">
<button type="button" class="layui-btn" id="upload2" style="">
<i class="layui-icon">&#xe67c;</i>上传新图片
</button>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label" >banner链接</label>
<div class="layui-input-block">
<input type="text" name="banner_url" required lay-verify="required" placeholder=""
autocomplete="off"
class="layui-input">
</div>
</div>
</form>
</div>
</div>
<script type="text/html" id="iconTpl">
<img src="{{d.icon_url}}" style="max-width: 32px; max-height: 32px;"/>
</script>
<script type="text/html" id="bannerTpl">
{{# if(d.banner>0){ }}
{{# } else { }}
{{# } }}
</script>
<!--<script type="text/html" id="operationTpl">-->
<!-- <a lay-event="edit">-->
<!-- <button class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;</i></button>-->
<!-- </a>-->
<!-- <a lay-event="delete">-->
<!-- <button class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>-->
<!-- </a>-->
<!--</script>-->
<script type="text/html" id="operationTpl">
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/application/list?id={{d.id}}" >应用列表</a>
<a class="layui-btn layui-btn-normal layui-btn-xs" href="/admin/application-category/banner-index?id={{d.id}}" >banner图管理</a>
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/application/list?id={{d.id}}" >应用列表</a>
<a class="layui-btn layui-btn-normal layui-btn-xs" href="/admin/application-category/banner-index?id={{d.id}}" >banner图管理</a>
</script>
<script type="text/html" id="recommendTpl">
<input type="checkbox" name="isrecommend" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="recommendDemo" {{ d.isrecommend == 1 ? 'checked' : '' }}>
......@@ -115,267 +53,4 @@
<script type="text/html" id="enableTpl">
<input type="checkbox" name="isenable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="enableDemo" {{ d.enable == 1 ? 'checked' : '' }}>
</script>
<script type="text/javascript">
var table = layui.table;
table.render({
elem: '#table1',
page: true,
limit: 10,
skin: 'row',
url: '/admin/application-category/index',
cols: [[
{
field: 'id',
title: 'ID'
},
{
field: 'name',
title: '名称',
},
{
field: 'coin_name',
title: '钱包',
},
{
field: 'app_count',
title: '应用',
},
{
field: 'icon_url',
title: '图标',
templet: '#iconTpl'
},
{
field: 'sort',
title: '排序',
edit: 'text'
},
{
field: 'banner',
title: 'banner',
templet: '#bannerTpl'
},
{
title: '操作',
templet: '#operationTpl',
width:300
},
{
title: '首页推荐',
field: 'isrecommend',
templet: '#recommendTpl',
width: 100
},
{
title: '状态',
field: 'enable',
templet: '#enableTpl',
width: 100
},
]],
});
var form = layui.form;
form.render();
table.on('tool(table1)', function(obj) {
var event = obj.event;
var data = obj.data;
if (event === 'edit') {
var index = layer.open({
title: '编辑应用分类',
area: '800px',
type: 1,
content: $("#_form"),
btn: ['保存', '取消'],
success: function() {
form.val("form1", {
id: data.id,
name: data.name,
icon: data.icon,
sort: data.sort,
banner: data.banner,
banner_url: data.banner_url
});
$("#icon1").attr('src', data.icon_url);
$("#icon2").attr('src', data.banner_image_url);
},
btn1: function() {
$.post('/admin/application-category/add-and-edit', $("#form1").serialize(), function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
$("#_form").css('display', 'none');
table.reload('table1', {
page: {
curr: 1
}
});
}
});
},
btn2: function() {
layer.close(index);
$("#_form").css('display', 'none');
},
cancel: function() {
layer.close(index);
$("#_form").css('display', 'none');
}
});
} else if ('del' === event) {
var index = layer.confirm("确认删除?", {icon: 3, title: '删除'}, function () {
$.get('/admin/application-category/delete', {id: data.id}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
table.reload('table1',{
page:{curr:1}
});
}
});
});
}
});
form.on('submit(search)', function (obj) {
console.log(obj.field);
table.reload("table1", {
where: obj.field,
page: {curr:1}
});
return false;
});
$('#add').click(function () {
var index = layer.open({
title: '添加应用分类',
area: '800px',
type: 1,
content: $("#_form"),
btn: ['保存', '取消'],
success: function() {
clearForm();
},
btn1: function() {
$.post('/admin/application-category/add-and-edit', $("#form1").serialize(), function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
$("#_form").css('display', 'none');
clearForm();
table.reload('table1', {
page: {
curr: 1
}
});
}
});
},
btn2: function() {
layer.close(index);
$("#_form").css('display', 'none');
},
cancel: function() {
layer.close(index);
$("#_form").css('display', 'none');
}
});
})
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/image/upload',
data: {_csrf: $_csrf},
done: function (res) {
if(res.code == 0){
$("input[name='icon']").val(res.data.image_id);
$("#icon1").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
uploader.render({
elem: "#upload2",
url: '/admin/image/upload',
data: {_csrf: $_csrf,image_type:2},
done: function (res) {
if(res.code == 0){
$("input[name='banner']").val(res.data.image_id);
$("#icon2").attr('src', res.data.image_src);
}
},
error: function (res) {
}
});
function clearForm(){
form.val("form1", {
id: '',
name: '',
icon: '',
sort: '',
banner: '',
banner_url: ''
});
$("#icon1").attr('src', '');
$("#icon2").attr('src', '');
}
form.on('switch(recommendDemo)', function(obj){
//layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);return;
if(obj.elem.checked){
$.get('/admin/applicate-recommend/add', {id:this.value,type:1}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
}
});
}else{
$.get('/admin/applicate-recommend/delete', {id:this.value,type:1}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
}
});
}
});
form.on('switch(enableDemo)', function(obj){
var enable = 1;
if(obj.elem.checked){
enable = 1
}else{
enable = 0;
}
$.get('/admin/application-category/set-enable', {id:this.value,enable:enable}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
}
});
});
//监听单元格编辑
table.on('edit(table1)', function(obj){
var value = obj.value; //得到修改后的值
var data = obj.data; //得到所在行所有键值
$.get('/admin/application-category/set-sort', {id:data.id,sort:value}, function(rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
table.reload('table1',{});
}else{
}
});
});
</script>
\ No newline at end of file
......@@ -46,9 +46,21 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">应用名称</label>
<label class="layui-form-label">中文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name" value="" lay-verify="required">
<input class="layui-input" name="name[]" value="" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
......
......@@ -48,9 +48,21 @@
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">应用名称</label>
<label class="layui-form-label">中文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name" value="<?= $item['name'] ?>" lay-verify="required">
<input class="layui-input" name="name[]" value="<?= $item['name_zh'] ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="<?= $item['name_en'] ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block">
<input class="layui-input" name="name[]" value="<?= $item['name_ja'] ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
......
......@@ -11,7 +11,7 @@
width: 100px;
}
</style>
<h4>所属分类---<?= $parent_category->name ?></h4>
<h4>所属分类---<?= $parent_category->name["zh-CN"] ?></h4>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md1">
<a href="/admin/application/add?category_id=<?= $parent_category->id ?>">
......@@ -27,7 +27,7 @@
<!-- 添加页面 -->
<div class="layui-row" style="display: none;padding: 5px;" id="_form">
<div class="layui-col-xs6 layui-col-sm6 layui-col-md11">
<form class="layui-form" action="javascript:void(0)" id="form1" method="post" lay-filter="form1">
<form class="layui-form" action="javascript:void(0)" id="form1" method="post" lay-filter="form1">
<input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input id="app_id" name="app_id" type="hidden" value="">
<div class="layui-form-item">
......@@ -58,13 +58,15 @@
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="add_category">添加所属分类</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/application/image-index?id={{d.id}}" >详情图管理</a>
<a class="layui-btn layui-btn-primary layui-btn-xs" href="/admin/application/image-index?id={{d.id}}">详情图管理</a>
</script>
<script type="text/html" id="recommendTpl">
<input type="checkbox" name="isrecommend" value="{{d.id}}" lay-skin="switch" lay-text="是|否" lay-filter="recommendDemo" {{ d.isrecommend == 1 ? 'checked' : '' }}>
<input type="checkbox" name="isrecommend" value="{{d.id}}" lay-skin="switch" lay-text="是|否"
lay-filter="recommendDemo" {{ d.isrecommend== 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="enableTpl">
<input type="checkbox" name="isenable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="enableDemo" {{ d.enable == 1 ? 'checked' : '' }}>
<input type="checkbox" name="isenable" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="enableDemo"
{{ d.enable== 1 ? 'checked' : '' }}>
</script>
<script type="text/javascript">
var form = layui.form;
......@@ -75,7 +77,7 @@
elem: '#table1',
page: true,
limit: 10,
url: '/admin/application/list?id='+category_id,
url: '/admin/application/list?id=' + category_id,
cols: [[
{
field: 'id',
......@@ -84,6 +86,11 @@
{
field: 'name',
title: '名称',
templet: function (data) {
var name = JSON.parse(data.name);
console.log(typeof (data.name), name.zh);
return name.zh
}
},
{
......@@ -94,26 +101,26 @@
{
field: 'sort',
title: '排序',
edit: 'text'
edit: 'text'
},
{
field: 'has_h5',
title: 'h5',
templet: function(d){
if(d.has_h5){
return "有";
}else{
return "无";
}
templet: function (d) {
if (d.has_h5) {
return "有";
} else {
return "无";
}
}
},
{
field: 'has_android',
title: '安卓',
templet: function(d){
if(d.has_android){
templet: function (d) {
if (d.has_android) {
return "有";
}else{
} else {
return "无";
}
}
......@@ -121,14 +128,14 @@
{
field: 'has_ios',
title: 'ios',
templet: function(d){
if(d.has_ios === 3){
templet: function (d) {
if (d.has_ios === 3) {
return "企业版/商店版";
}else if(d.has_ios === 2){
} else if (d.has_ios === 2) {
return "商店版";
}else if(d.has_ios === 1){
} else if (d.has_ios === 1) {
return "企业版";
}else{
} else {
return "无";
}
}
......@@ -153,15 +160,15 @@
]],
});
table.on('tool(table1)', function(obj) {
table.on('tool(table1)', function (obj) {
var data = obj.data;
var event = obj.event;
if (event === 'edit') {
$.get('/admin/application/edit', {id: data.id,category_id:category_id}, function (str) {
$.get('/admin/application/edit', {id: data.id, category_id: category_id}, function (str) {
var editIndex = layer.open({
type: 1,
title: '编辑: ' + data.name,
area: ['625px','800px'],
area: ['625px', '800px'],
content: str,
btn: ['保存', '取消'],
btn1: function () {
......@@ -182,31 +189,31 @@
});
} else if ('del' === event) {
var index = layer.confirm("确认删除?", {icon: 3, title: '删除'}, function () {
$.get('/admin/application/delete', {id: data.id,category_id:category_id}, function (rev) {
$.get('/admin/application/delete', {id: data.id, category_id: category_id}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
table.reload('table1',{
page:{curr:1}
if (0 == rev.code) {
table.reload('table1', {
page: {curr: 1}
});
}
});
});
}else if ('add_category' === event) {
} else if ('add_category' === event) {
$("#app_id").val(data.id);
var index = layer.open({
title: '添加应用分类',
area: ['500px','400px'],
area: ['500px', '400px'],
type: 1,
content: $("#_form"),
btn: ['保存', '取消'],
success: function() {
success: function () {
form.val("form1", {
cate_id: 0,
sort: '',
});
},
btn1: function() {
$.post('/admin/application/add-category', $("#form1").serialize(), function(rev) {
btn1: function () {
$.post('/admin/application/add-category', $("#form1").serialize(), function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
......@@ -214,63 +221,63 @@
}
});
},
btn2: function() {
btn2: function () {
layer.close(index);
$("#_form").css('display', 'none');
},
cancel: function() {
cancel: function () {
layer.close(index);
$("#_form").css('display', 'none');
}
});
}
});
form.on('switch(recommendDemo)', function(obj){
form.on('switch(recommendDemo)', function (obj) {
//layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);return;
if(obj.elem.checked){
$.get('/admin/applicate-recommend/add', {id:this.value,type:2}, function(rev) {
if (obj.elem.checked) {
$.get('/admin/applicate-recommend/add', {id: this.value, type: 2}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
} else {
}
});
}else{
$.get('/admin/applicate-recommend/delete', {id:this.value,type:2}, function(rev) {
} else {
$.get('/admin/applicate-recommend/delete', {id: this.value, type: 2}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
} else {
}
});
}
});
form.on('switch(enableDemo)', function(obj){
form.on('switch(enableDemo)', function (obj) {
var enable = 1;
if(obj.elem.checked){
if (obj.elem.checked) {
enable = 1
}else{
} else {
enable = 0;
}
$.get('/admin/application/set-enable', {id:this.value,enable:enable}, function(rev) {
$.get('/admin/application/set-enable', {id: this.value, enable: enable}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
}else{
} else {
}
});
});
//监听单元格编辑
table.on('edit(table1)', function(obj){
table.on('edit(table1)', function (obj) {
var value = obj.value; //得到修改后的值
var data = obj.data; //得到所在行所有键值
$.get('/admin/application/set-sort', {id:data.id,category_id:category_id,sort:value}, function(rev) {
$.get('/admin/application/set-sort', {id: data.id, category_id: category_id, sort: value}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
table.reload('table1',{});
}else{
table.reload('table1', {});
} else {
}
});
......
......@@ -19,25 +19,33 @@
<input name="id" type="hidden" value="<?= $model->id ?>">
<div class="layui-inline">
<label class="layui-form-label">简称</label>
<div class="layui-input-block">
<input class="layui-input" name="name" placeholder="请填写大写字母" value="<?= $model->name ?>" lay-verify="required">
<div class="layui-input-block" style="width: 250px">
<input class="layui-input" name="name" placeholder="请填写大写字母" value="<?= $model->name ?>"
lay-verify="required">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">可选简称</label>
<div class="layui-input-block"style="width: 250px">
<input class="layui-input" name="optional_name" placeholder="请填写大写字母"
value="<?= $model->optional_name ?>" lay-verify="required">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block" style="width: 250px">
<div class="layui-input-block" style="width: 190px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['zh-CN'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">英文名</label>
<div class="layui-input-block" style="width: 250px">
<div class="layui-input-block" style="width: 190px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['en-US'] ?>">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">日文名</label>
<div class="layui-input-block" style="width: 250px">
<div class="layui-input-block" style="width: 190px">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['ja'] ?>">
</div>
</div>
......
......@@ -20,7 +20,15 @@
<div class="layui-inline">
<label class="layui-form-label">简称</label>
<div class="layui-input-block">
<input class="layui-input" name="name" placeholder="请填写大写字母" value="<?= $model->name ?>" lay-verify="required">
<input class="layui-input" name="name" placeholder="请填写大写字母" value="<?= $model->name ?>"
lay-verify="required">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">可选简称</label>
<div class="layui-input-block">
<input class="layui-input" name="optional_name" placeholder="请填写大写字母" value="<?= $model->optional_name ?>"
lay-verify="required">
</div>
</div>
<div class="layui-inline">
......@@ -76,7 +84,7 @@
<div class="layui-input-block">
<input type="text" class="layui-input" name="address" value="<?= $model->address ?>">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">精度</label>
<div class="layui-input-block">
......@@ -121,10 +129,12 @@
<select name="treaty">
<option value="1" <?php if ($model->treaty == 1) {
echo "selected";
} ?>>token</option>
} ?>>token
</option>
<option value="2" <?php if ($model->treaty == 2) {
echo "selected";
} ?>>coins</option>
} ?>>coins
</option>
</select>
</div>
</div>
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午9:59
*/
use backend\assets\coin\IndexAsset;
IndexAsset::register($this);
?>
<style>
.layui-table-tips-c {
padding: 0px;
}
</style>
<h4>币种列表</h4>
<div class="layui-row">
<div class="layui-col-md1">
<a href="/admin/coin/add">
<button class="layui-btn layui-btn-default" id="add">添加币种</button>
</a>
</div>
<div class="layui-col-md8">
<form class="layui-form" method="get" action="">
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">币种名称</label>
<div class="layui-input-inline">
<input class="layui-input" name="name">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">平台</label>
<div class="layui-input-inline">
<select name="platform">
<option value="">全部</option>
<?php foreach ($platforms as $platform): ?>
<option value="<?= $platform ?>"><?= $platform ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">类型</label>
<div class="layui-input-inline">
<select name="chain">
<option value="">全部</option>
<?php foreach ($chains as $chain): ?>
<option value="<?= $chain ?>"><?= $chain ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">推介币种</label>
<div class="layui-input-inline">
<select name="recommend">
<option value="">全部</option>
<option value="0"></option>
<option value="1"></option>
</select>
</div>
</div>
<div class="layui-inline">
<button class="layui-btn" lay-submit lay-filter="form1">搜索</button>
</div>
</form>
</div>
</div>
<div class="layui-row">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<script type="text/html" id="iconTpl">
<a href="{{d.icon}}" target="_blank"><img src="{{d.icon}}" style="max-width: 32px; max-height: 32px;"/></a>
</script>
<script type="text/html" id="officialTpl">
{{# if(d.official){ }}
{{# layui.each(d.official.split(';'),function(index,item){ }}
{{# if(item){ }}
<a href="{{ item }}" class="layui-table-link" target="_blank">官网{{# if(index){ }}{{index}}{{# } }}</a>
{{# } }}
{{# }); }}
{{# }else{ }}
-
{{# } }}
</script>
<script type="text/html" id="paperTpl">
{{# if(d.paper){ }}
<a href="{{d.paper}}" class="layui-table-link" target="_blank">白皮书</a>
{{# }else{ }}
-
{{# } }}
</script>
<script type="text/html" id="operationTpl">
<a lay-event="edit">
<button class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;</i></button>
</a>
<a lay-event="delete">
<button class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>
</a>
</script>
<script type="text/html" id="exchangeTpl">
{{d.exchange}}
</script>
<script type="text/html" id="recommendTpl">
{{# if(d.recommend==0){ }}
{{# }else if(d.recommend==1){ }}
首页推荐
{{# }else{ }}
次页推荐
{{# } }}
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午9:59
*/
use backend\assets\coin\IndexAsset;
IndexAsset::register($this);
?>
<style>
.layui-table-tips-c {
padding: 0px;
}
</style>
<h4>币种列表</h4>
<div class="layui-row">
<div class="layui-col-md1">
<a href="/admin/coin/add">
<button class="layui-btn layui-btn-default" id="add">添加币种</button>
</a>
</div>
<div class="layui-col-md8">
<form class="layui-form" method="get" action="">
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">币种名称</label>
<div class="layui-input-inline">
<input class="layui-input" name="name">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">平台</label>
<div class="layui-input-inline">
<select name="platform">
<option value="">全部</option>
<?php foreach ($platforms as $platform): ?>
<option value="<?= $platform ?>"><?= $platform ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">类型</label>
<div class="layui-input-inline">
<select name="chain">
<option value="">全部</option>
<?php foreach ($chains as $chain): ?>
<option value="<?= $chain ?>"><?= $chain ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">推介币种</label>
<div class="layui-input-inline">
<select name="recommend">
<option value="">全部</option>
<option value="0"></option>
<option value="1"></option>
</select>
</div>
</div>
<div class="layui-inline">
<button class="layui-btn" lay-submit lay-filter="form1">搜索</button>
</div>
</form>
</div>
</div>
<div class="layui-row">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<script type="text/html" id="iconTpl">
<a href="{{d.icon}}" target="_blank"><img src="{{d.icon}}" style="max-width: 32px; max-height: 32px;"/></a>
</script>
<script type="text/html" id="officialTpl">
{{# if(d.official){ }}
{{# layui.each(d.official.split(';'),function(index,item){ }}
{{# if(item){ }}
<a href="{{ item }}" class="layui-table-link" target="_blank">官网{{# if(index){ }}{{index}}{{# } }}</a>
{{# } }}
{{# }); }}
{{# }else{ }}
-
{{# } }}
</script>
<script type="text/html" id="paperTpl">
{{# if(d.paper){ }}
<a href="{{d.paper}}" class="layui-table-link" target="_blank">白皮书</a>
{{# }else{ }}
-
{{# } }}
</script>
<script type="text/html" id="operationTpl">
<a lay-event="edit">
<button class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;</i></button>
</a>
<a lay-event="delete">
<button class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>
</a>
</script>
<script type="text/html" id="exchangeTpl">
{{d.exchange}}
</script>
<script type="text/html" id="recommendTpl">
{{# if(d.recommend==0){ }}
{{# }else if(d.recommend==1){ }}
首页推荐
{{# }else{ }}
次页推荐
{{# } }}
</script>
\ No newline at end of file
......@@ -8,4 +8,4 @@
?>
<h4>添加币种</h4>
<?= $this->render('form', ['model' => $model]) ?>
\ No newline at end of file
<?= $this->render('form', ['model' => $model, 'platforms' => $platforms, 'type' => $type]) ?>
\ No newline at end of file
......@@ -8,4 +8,4 @@
?>
<h4>修改信息</h4>
<?= $this->render('form', ['model' => $model]) ?>
<?= $this->render('form', ['model' => $model, 'platforms' => $platforms, 'type' => $type]) ?>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午3:28
*/
/**
* @var $model backend\models\coin\CoinForm;
*/
use common\models\psources\Coin;
$platforms = Coin::getChainList();
?>
<style>
.layui-form-label {
width: 100px;
......@@ -24,46 +8,51 @@ $platforms = Coin::getChainList();
<form class="layui-form" method="post" action="">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input name="id" type="hidden" value="<?= $model->id ?>">
<?php if($model->type == 2) :?>
<div class="layui-form-item">
<label class="layui-form-label">币种</label>
<div class="layui-input-block">
<input class="layui-input" name="platform" value="<?= $model->platform ?>">
<?php if ($type == 2) : ?>
<div class="layui-form-item">
<label class="layui-form-label">币种</label>
<div class="layui-input-block">
<input class="layui-input" name="platform" value="<?= $model->platform ?>">
</div>
</div>
</div>
<?php else :?>
<div class="layui-form-item">
<label class="layui-form-label">平台</label>
<div class="layui-input-block">
<select name="platform">
<?php foreach ($platforms as $platform): ?>
<option value="<?= $platform ?>" <?php if ($model->platform == $platform) {
echo "selected";
} ?>><?= $platform ?></option>
<?php endforeach; ?>
</select>
<div class="layui-form-item">
<label class="layui-form-label">手续费</label>
<div class="layui-input-block">
<input class="layui-input" name="fee" value="<?= $model->fee ?>">
</div>
</div>
</div>
<?php endif;?>
<div class="layui-form-item">
<label class="layui-form-label">最小值</label>
<div class="layui-input-block">
<input class="layui-input" name="min" value="<?= $model->min ?>">
<?php else : ?>
<div class="layui-form-item">
<label class="layui-form-label">平台</label>
<div class="layui-input-block">
<select name="platform">
<?php foreach ($platforms as $platform): ?>
<option value="<?= $platform ?>" <?php if ($model->platform == $platform) {
echo "selected";
} ?>><?= $platform ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">最大值</label>
<div class="layui-input-block">
<input class="layui-input" name="max" value="<?= $model->max ?>">
<div class="layui-form-item">
<label class="layui-form-label">最小值</label>
<div class="layui-input-block">
<input class="layui-input" name="min" value="<?= $model->min ?>">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分档</label>
<div class="layui-input-block">
<input class="layui-input" name="level" value="<?= $model->level ?>">
<div class="layui-form-item">
<label class="layui-form-label">最大值</label>
<div class="layui-input-block">
<input class="layui-input" name="max" value="<?= $model->max ?>">
</div>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">分档</label>
<div class="layui-input-block">
<input class="layui-input" name="level" value="<?= $model->level ?>">
</div>
</div>
<?php endif; ?>
<div class="layui-form-item">
<button class="layui-btn">提交</button>
</div>
......
......@@ -25,8 +25,12 @@
</div>
<div class="layui-tab-item">
<button class="layui-btn layui-btn-default" id="update-coin">更新币种库</button>
<table class="layui-table" id="table2" lay-filter="table2" ></table>
<a href="/admin/miner-fee/add?type=2">
<button class="layui-btn">添加矿工费</button>
</a>
<div class="layui-row">
<table class="layui-table" id="table2" lay-filter="table2"></table>
</div>
</div>
</div>
......@@ -56,9 +60,10 @@
cols: [[
{field: 'id', title: 'ID'},
{field: 'platform', title: '币种'},
{field: 'fee', title: '旷工费' ,edit: 'text'},
{field: 'fee', title: '旷工费', edit: 'text'},
{field: 'create_at', title: '创建时间'},
{field: 'update_at', title: '更新时间'},
{field: 'id', title: '操作', templet: "#operatorTpl"}
]],
url: '/admin/miner-fee/cost?type=2'
});
......@@ -66,7 +71,7 @@
$('#update-coin').click(function () {
$.get('/admin/miner-fee/update-coin', {}, function (rev) {
layer.msg(rev.msg);
if (0==rev.code) {
if (0 == rev.code) {
table.reload('table2', {
page: {
curr: 1
......@@ -76,14 +81,14 @@
});
});
//监听单元格编辑
table.on('edit(table2)', function(obj){
table.on('edit(table2)', function (obj) {
var value = obj.value; //得到修改后的值
var data = obj.data; //得到所在行所有键值
$.get('/admin/miner-fee/set-fee', {id:data.id,fee:value}, function(rev) {
$.get('/admin/miner-fee/set-fee', {id: data.id, fee: value}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
table.reload('table2',{});
}else{
table.reload('table2', {});
} else {
}
});
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午3:31
*/
?>
<h4>添加钱包</h4>
<style>
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md6">
<form class="layui-form" method="post" action="">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<div class="layui-inline">
<label class="layui-form-label">简称</label>
<div class="layui-input-block">
<input class="layui-input" name="name" value="<?= $model->name ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">下载地址</label>
<div class="layui-input-block">
<input class="layui-input" name="download_url" value="<?= $model->download_url ?>">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce"><?= $model->introduce?></textarea>
</div>
</div>
<div class="layui-form-item">
<button class="layui-btn">提交</button>
</div>
</form>
</div>
</div>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午6:23
*/
?>
<style>
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md12">
<form class="layui-form" method="post" action="" id="walletEdit">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input name="id" type="hidden" value="<?= $model->id ?>">
<div class="layui-inline">
<label class="layui-form-label">简称</label>
<div class="layui-input-block">
<input class="layui-input" name="name" value="<?= $model->name ?>" lay-verify="required">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">下载地址</label>
<div class="layui-input-block">
<input class="layui-input" name="download_url" value="<?= $model->download_url ?>">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">介绍</label>
<div class="layui-input-block">
<textarea class="layui-textarea" name="introduce"><?= $model->introduce?></textarea>
</div>
</div>
</form>
</div>
</div>
<script>
var laydate = layui.laydate;
laydate.render({
elem: "#time1"
});
//图片上传
var uploader = layui.upload;
$_csrf = $("input[name='_csrf']").val();
uploader.render({
elem: "#upload1",
url: '/admin/coin/upload',
data: {_csrf: $_csrf},
done: function (res) {
console.log(res.data.src);
$("input[name='icon']").val(res.data.src);
$("#icon1").attr('src', res.data.src);
},
error: function (res) {
}
});
//form render
var form = layui.form;
form.render();
</script>
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午9:59
*/
use backend\assets\wallet\IndexAsset;
IndexAsset::register($this);
?>
<style>
.layui-table-tips-c {
padding: 0px;
}
</style>
<h4>钱包列表</h4>
<div class="layui-row">
<div class="layui-col-md1">
<a href="/admin/wallet/add">
<button class="layui-btn layui-btn-default" id="add">添加钱包</button>
</a>
</div>
<div class="layui-col-md8">
<form class="layui-form" method="get" action="">
<div class="layui-inline">
<label class="layui-form-label" style="margin-bottom: 0; width: 100px;">钱包名称</label>
<div class="layui-input-inline">
<input class="layui-input" name="name">
</div>
</div>
<div class="layui-inline">
<button class="layui-btn" lay-submit lay-filter="form1">搜索</button>
</div>
</form>
</div>
</div>
<div class="layui-row">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<script type="text/html" id="operationTpl">
<a lay-event="edit">
<button class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe642;</i></button>
</a>
<a lay-event="delete">
<button class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i></button>
</a>
</script>
/**
* @author rlgyzhcn@qq.com
*/
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
form.render();
var tableIns = table.render({
elem: "#table1",
url: '/admin/application-category/index',
limit: 10,
page: 1,
loading: true,
cols: [[
{
field: 'coin_name', title: '名称', templet: function (data) {
var name = JSON.parse(data.name);
console.log(typeof (data.name), name.zh);
return name.zh
}
},
{field: 'icon_url', title: '图标', templet: '#iconTpl'},
{field: 'isrecommend', title: '首页推荐', templet: '#recommendTpl', width: 100},
{field: 'enable', title: '状态', templet: '#enableTpl', width: 100},
{field: 'id', title: '操作', templet: '#operationTpl'}
]],
});
form.on('submit(form1)', function (data) {
table.reload("table1", {
where: data.field,
page: {curr: 1},
});
return false;
});
//监听单元格事件
table.on('tool(table1)', function (obj) {
var data = obj.data;
if ('del' === obj.event) {
var index = layer.confirm("确认删除?", {icon: 3, title: '删除'}, function () {
$.get('/admin/application-category/delete', {id: data.id}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
table.reload('table1', {
page: {curr: 1}
});
}
});
});
} else if (obj.event == 'edit') {
$.get('/admin/application-category/edit', {id: data.id}, function (str) {
var editIndex = layer.open({
type: 1,
title: '编辑: ' + data.name,
area: '625px',
content: str,
btn: ['保存', '取消'],
btn1: function () {
// console.log();
$.post('/admin/application-category/edit', $("#application-category-edit").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
table.reload("table1", {
where: data.field,
});
layer.close(editIndex);
}
});
}
});
});
}
});
form.on('switch(recommendDemo)', function (obj) {
//layer.tips(this.value + ' ' + this.name + ':'+ obj.elem.checked, obj.othis);return;
if (obj.elem.checked) {
$.get('/admin/applicate-recommend/add', {id: this.value, type: 1}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
} else {
}
});
} else {
$.get('/admin/applicate-recommend/delete', {id: this.value, type: 1}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
} else {
}
});
}
});
form.on('switch(enableDemo)', function (obj) {
var enable = 1;
if (obj.elem.checked) {
enable = 1
} else {
enable = 0;
}
$.get('/admin/application-category/set-enable', {id: this.value, enable: enable}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
} else {
}
});
});
\ No newline at end of file
/**
* @author rlgyzhcn@qq.com
*/
var table = layui.table;
var form = layui.form;
var layer = layui.layer;
form.render();
var tableIns = table.render({
elem: "#table1",
url: '/admin/wallet/list',
limit: 10,
page: 1,
loading: true,
cols: [[
{field: 'id', title: 'ID'},
{field: 'name', title: '名称'},
{field: 'id', title: '操作', templet: '#operationTpl'}
]],
});
form.on('submit(form1)', function (data) {
table.reload("table1", {
where: data.field,
page: {curr: 1},
});
return false;
});
//监听单元格事件
table.on('tool(table1)', function (obj) {
var data = obj.data;
if (obj.event == 'delete') {
layer.confirm('真的要删除' + data.name + '吗?', {icon: 3, title: '删除'}, function (index) {
layer.close(index);
//向服务端发送删除指令
$.get('/admin/wallet/delete?id=' + obj.data.id, function (data, status) {
if (data.code == 0) {
obj.del(); //删除对应行(tr)的DOM结构
}
layer.msg(data.msg);
});
});
} else if (obj.event == 'edit') {
$.get('/admin/wallet/edit', {id: data.id}, function (str) {
var editIndex = layer.open({
type: 1,
title: '编辑: ' + data.name,
area: '625px',
content: str,
btn: ['保存', '取消'],
btn1: function () {
// console.log();
$.post('/admin/wallet/edit', $("#walletEdit").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
table.reload("table1", {
where: data.field,
});
layer.close(editIndex);
}
});
}
});
});
}
});
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/7/17
* Time: 11:11
*/
namespace common\base;
use yii\web\Request;
class BaseRequest extends Request
{
private $user_id = 0;
private $platform_id = 0;
public function getUserId()
{
return $this->user_id;
}
public function setUserId($value)
{
$this->user_id = $value;
}
public function getPlatformId()
{
return $this->platform_id;
}
public function setPlatformId($value)
{
$this->platform_id = $value;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/6/20
* Time: 11:11
*/
namespace common\behaviors;
use Yii;
use common\models\Admin;
use api\base\ResponseMsg;
use common\components\Response;
use yii\base\ActionFilter;
class LoginStatusAuthInterceptor extends ActionFilter
{
public function beforeAction($action)
{
$request_class = get_class($action->controller);
$request_action = $action->id;
if('login' == $request_action || 'user-sync' == $request_action){
return true;
}
$token_string = Yii::$app->request->headers->get('Token');
if(false == $token_string){
$msg = 'platform auth error';
$code = '40004';
goto doEnd;
}
$model = new Admin();
$user = $model->loginByAccessToken($token_string,'');
if(false == $user){
$msg = 'user auth error';
$code = '40004';
goto doEnd;
}
$user_id = $user->uid;
$platform_id = $user->platform_id;
Yii::$app->request->setUserId($user_id);
Yii::$app->request->setPlatformId($platform_id);
return true;
doEnd :
// 返回错误
$response_message = new ResponseMsg();
$content = $response_message->jsonError($msg, $code);
$content = $response_message->withHeaders($response_message->getHeaders())->withContent($content);
Yii::$app->response->data = $content;
Yii::$app->response->send();
return false;
}
public function frontAuth()
{
//验证用户token正确性
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: jiaming
* Date: 2019/6/20
* Time: 11:11
*/
namespace common\behaviors;
use api\base\ResponseMsg;
use yii\base\ActionFilter;
use common\models\Admin;
use Yii;
class UserAuthInterceptor extends ActionFilter
{
public function beforeAction($action)
{
if (!parent::beforeAction($action)) {
return false;
}
$request_class = get_class($action->controller);
$request_action = $action->id;
if('login' == $request_action || 'user-sync' == $request_action){
return true;
}
$token_string = Yii::$app->request->headers->get('Token');
$model = new Admin();
$user = $model->loginByAccessToken($token_string, '');
if (empty($user)) {
$code = '40001';
$msg = 'user auth error';
goto doEnd;
}
$user_id = $user->uid;
$platform_id = $user->platform_id;
Yii::$app->request->setUserId($user_id);
Yii::$app->request->setPlatformId($platform_id);
$user_auth = Yii::$app->params['user_auth']['user_auth'];
$user_auth_map = $user_auth[$platform_id] ?? null;
if (empty($user_auth_map)) {
$code = '40001';
$msg = 'platform auth error';
goto doEnd;
}
$user_auth_map = $user_auth_map[$user_id] ?? null;
if (empty($user_auth_map)) {
$code = '40001';
$msg = 'user auth error';
goto doEnd;
}
$auth_type_map = Yii::$app->params['user_auth'][$user_auth_map];
$auth_type_map = array_unique($auth_type_map, SORT_REGULAR);
$switch = false;
foreach ($auth_type_map as $key => $auth_type) {
if (empty($auth_type)) continue;
if ($request_class == $auth_type['class']) {
$action_map = $auth_type['actions'];
$switch = true;
break;
}
}
if (false == $switch) {
$code = '40003';
$msg = 'controller auth error';
goto doEnd;
}
if (empty($action_map)) {
return true;
}
if (in_array($request_action, $action_map)) {
return true;
} else {
$code = '40004';
$msg = 'action auth error';
goto doEnd;
}
doEnd :
// 返回错误
$response_message = new ResponseMsg();
$content = $response_message->jsonError($msg, $code);
$content = $response_message->withHeaders($response_message->getHeaders())->withContent($content);
Yii::$app->response->data = $content;
Yii::$app->response->send();
return false;
}
}
\ No newline at end of file
......@@ -131,6 +131,12 @@ class Chain33Business
return $service->getBlockHashByHeight($height);
}
public static function getProperFee()
{
$service = new Chain33Service();
return $service->getProperFee();
}
/**
* 获取coin地址下DAPP交易信息
* @param string $address
......@@ -153,13 +159,12 @@ class Chain33Business
* 获取游戏状态
* @return array
*/
public static function getGameStatus()
public static function getGameStatus($node_params = [])
{
$node_params = \Yii::$app->params['chain_parallel']['wasm'];
$service = new Chain33Service($node_params);
$execer = 'wasm';
$funcName = 'WasmGetContractTable';
$contractName = 'user.p.tschain.user.wasm.dice';
$contractName = $node_params['contractName'];
$items[] = [
'tableName' => 'gamestatus',
'key' => 'dice_statics'
......@@ -173,13 +178,12 @@ class Chain33Business
* @param integer $end
* @return array
*/
public static function getBetStatus($start, $end, $roundArr = [])
public static function getBetStatus($start, $end, $roundArr = [], $node_params = [])
{
$node_params = \Yii::$app->params['chain_parallel']['wasm'];
$service = new Chain33Service($node_params);
$execer = 'wasm';
$funcName = 'WasmGetContractTable';
$contractName = 'user.p.tschain.user.wasm.dice';
$contractName = $node_params['contractName'];
if (empty($roundArr)) {
for($i = $start + 1; $i <= $end; $i++){
$items[] = [
......@@ -205,9 +209,8 @@ class Chain33Business
* @param null
* @return array
*/
public static function getLastHeader()
public static function getLastHeader($node_params = [])
{
$node_params = \Yii::$app->params['chain_parallel']['wasm'];
$service = new Chain33Service($node_params);
return $service->getLastHeader();
}
......
......@@ -38,7 +38,8 @@ class ExchangeBusiness
9 => 'Go',
10 => 'Zhaobi',
11 => 'Gdpro',
12 => 'Boc'
12 => 'Boc',
13 => 'Ex'
];
/**
......@@ -51,17 +52,17 @@ class ExchangeBusiness
public static function getquatation($tag = 'btc')
{
$coin_quotation_disable_items = Yii::$app->params['coin_quotation_disable_items'];
if(strtoupper($tag) == 'CCNY'){
$exchange = ExchangeFactory::createExchange("Bty");
$rate = $exchange->getTicker("BTY", "USDT");
$rate = (float)$rate['rmb'] / $rate['last'];
if (strtoupper($tag) == 'CCNY') {
$exchange = ExchangeFactory::createExchange("Bty");
$rate = $exchange->getTicker("BTY", "USDT");
$rate = (float)$rate['rmb'] / $rate['last'];
$quotation['rmb'] = 1.00;
$quotation['low'] = 1.00;
$quotation['high'] = 1.00;
$quotation['last'] = (float)sprintf("%0.4f", $quotation['rmb']/$rate);
$quotation['last'] = (float)sprintf("%0.4f", $quotation['rmb'] / $rate);
goto doEnd;
}
if(strtoupper($tag) == 'BOSS'){
if (strtoupper($tag) == 'BOSS') {
$quotation = [
'low' => 2000,
'high' => 2000,
......@@ -71,7 +72,7 @@ class ExchangeBusiness
goto doEnd;
}
if(strtoupper($tag) == 'CPF'){
if (strtoupper($tag) == 'CPF') {
$quotation = [
'low' => 3.4,
'high' => 3.4,
......@@ -81,62 +82,82 @@ class ExchangeBusiness
goto doEnd;
}
if(in_array($tag,$coin_quotation_disable_items)){
if (strtoupper($tag) == 'TSC' || strtoupper($tag) == 'WL' || strtoupper($tag) == 'ETS' || strtoupper($tag) == 'LIMS' || strtoupper($tag) == 'AT' || strtoupper($tag) == 'BTJ') {
$quotation = [
'low' => 0,
'high' => 0,
'last' => 0,
'rmb' => 0,
];
goto doEnd;
}
if (in_array($tag, $coin_quotation_disable_items)) {
return false;
}
$f = false;
$f = false;
$quotation = [];
if(in_array(strtoupper($tag),['GM', 'BSTC'])){
if (in_array(strtoupper($tag), ['FOLI'])) {
$exchange = ExchangeFactory::createExchange("Ex");
$quotation = $exchange->getTicker($tag, 'USDT');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if (in_array(strtoupper($tag), ['GM', 'BSTC'])) {
$exchange = ExchangeFactory::createExchange("Token7");
$quotation = $exchange->getTicker($tag, 'HA');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if(in_array(strtoupper($tag),['BECC'])){
if (in_array(strtoupper($tag), ['BECC'])) {
$exchange = ExchangeFactory::createExchange("S");
$quotation = $exchange->getTicker($tag, 'ST');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if(in_array(strtoupper($tag),['GHP'])){
if (in_array(strtoupper($tag), ['GHP'])) {
$exchange = ExchangeFactory::createExchange("Zg");
$quotation = $exchange->getTicker($tag, 'CNZ');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if(in_array(strtoupper($tag),['SFT'])){
if (in_array(strtoupper($tag), ['SFT'])) {
$exchange = ExchangeFactory::createExchange("Zhaobi");
$quotation = $exchange->getTicker($tag, 'CNY');
$quotation['low'] = (float)sprintf("%0.4f", $quotation['low']);
$quotation['high'] = (float)sprintf("%0.4f", $quotation['high']);
$quotation['last'] = (float)sprintf("%0.4f", $quotation['last']);
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if(in_array(strtoupper($tag),['CTG'])){
if (in_array(strtoupper($tag), ['CTG'])) {
$exchange = ExchangeFactory::createExchange("Gdpro");
$quotation = $exchange->getTicker($tag, 'CNY');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if(in_array(strtoupper($tag),['USDT'])){
if (in_array(strtoupper($tag), ['USDT'])) {
$exchange = ExchangeFactory::createExchange("Go");
$quotation = $exchange->getTicker('CNY', 'USD');
$quotation['rmb'] = (float)sprintf("%0.2f", $quotation['last']);
goto doEnd;
}
if(in_array(strtoupper($tag),['SJPY'])){
if (in_array(strtoupper($tag), ['SJPY'])) {
$exchange = ExchangeFactory::createExchange("Boc");
$quotation = $exchange->getTicker('CNY', 'JPY');
$quotation = [
'low' => (float)sprintf("%0.4f", $quotation['low']/100),
'high' => (float)sprintf("%0.4f", $quotation['high']/100),
'last' => (float)sprintf("%0.4f", $quotation['last']/100),
'rmb' => (float)sprintf("%0.4f", $quotation['last']/100),
'low' => (float)sprintf("%0.4f", $quotation['low'] / 100),
'high' => (float)sprintf("%0.4f", $quotation['high'] / 100),
'last' => (float)sprintf("%0.4f", $quotation['last'] / 100),
'rmb' => (float)sprintf("%0.2f", $quotation['last'] / 100),
];
goto doEnd;
}
......@@ -148,7 +169,7 @@ class ExchangeBusiness
$exchange = ExchangeFactory::createExchange($exchange);
if ($exchange->symbolExists($tag)) {
$quotation = $exchange->getTicker($tag);
$f = true;
$f = true;
break;
}
}
......@@ -164,11 +185,11 @@ class ExchangeBusiness
if ($exchange->symbolExists($tag, 'btc')) {
$price_btc = $exchange->getTicker($tag, 'btc');
//获取btcusdt
$result = array_map(function ($a, $b) {
$result = array_map(function ($a, $b) {
return $a * $b;
}, $price_btc, $btc_usd);
$quotation = ['low' => $result[0], 'high' => $result[1], 'last' => $result[2]];
$f = true;
$f = true;
break;
}
}
......@@ -184,21 +205,26 @@ class ExchangeBusiness
/**
* @var $exchange \common\service\exchange\Exchange
*/
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$rate = $rate['last'] ?? '';
if(empty($rate)) {
$exchange = ExchangeFactory::createExchange("Bty");
$rate = $exchange->getTicker("BTY", "USDT");
$rate = (float)$rate['rmb'] / $rate['last'];
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$rate = $rate['last'] ?? '';
if (empty($rate)) {
$exchange = ExchangeFactory::createExchange("Bty");
$rate = $exchange->getTicker("BTY", "USDT");
$rate = (float)$rate['rmb'] / $rate['last'];
}
$quotation['rmb'] = (float)sprintf("%0.4f", $rate * $quotation['last']);
doEnd :
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$cny_usd_rate = 1 / $rate['last'];
$quotation['usd'] = (float)sprintf("%0.4f", $quotation['rmb'] * $cny_usd_rate);
$exchange = ExchangeFactory::createExchange("Go");
$rate = $exchange->getTicker("CNY", "USD");
$cny_usd_rate = 1 / $rate['last'];
if (in_array(strtoupper($tag), ['FOLI'])) {
$quotation['usd'] = (float)sprintf("%0.4f", $quotation['last']);
$quotation['rmb'] = (float)sprintf("%0.4f", $quotation['last'] / $cny_usd_rate);
} else {
$quotation['usd'] = (float)sprintf("%0.4f", $quotation['rmb'] * $cny_usd_rate);
}
return $quotation;
}
......@@ -240,12 +266,33 @@ class ExchangeBusiness
* @param array $condition 需要的币种sid列表
* @return array
*/
public static function getApiListForIndex($page = 1, $limit = 999, $condition = [], $fields=[])
public static function getApiListForIndex($page = 1, $limit = 999, $condition = [], $fields = [])
{
if(!$fields) {
$fields =['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain','address as contract_address', 'treaty'];
if (count($condition[0]) > 1) {
foreach ($condition as $val) {
if ('null' == $val[1] || 'coin' == $val[1]) {
$data[] = Coin::find()->select('id,sid,icon,name,optional_name,nickname,platform,chain,address as contract_address,treaty')
->where(['name' => $val[0]])
->asArray()
->one();
continue;
}
$data[] = Coin::find()->select('id,sid,icon,name,optional_name,nickname,platform,chain,address as contract_address,treaty')
->where(['name' => $val[0]])
->andWhere(['platform' => $val[1]])
->asArray()
->one();
}
} else {
$data = Coin::find()->select('id,sid,icon,name,optional_name,nickname,platform,chain,address as contract_address,treaty')
->where(['in', 'name', $condition])
->asArray()->all();
}
$rows = Coin::getSelectList($page, $limit, $fields,$condition);
$rows = [
'count' => count($data),
'data' => $data
];
$count = 0;
if (!empty($rows) && is_array($rows) && array_key_exists('count', $rows)) {
$count = $rows['count'];
......@@ -254,29 +301,29 @@ class ExchangeBusiness
$rows = $rows['data'];
foreach ($rows as $key => $row) {
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
$quotation = self::getquatation($row['name']);
$quotation = self::getquatation($row['name']);
if (!$quotation) {
$quotation = [];
if(in_array($row['name'], ['BTY', 'YCC'])){
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
$rows[$key]['rmb'] = $coinServer->getPrice();
if (in_array($row['name'], ['BTY', 'YCC'])) {
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
$rows[$key]['rmb'] = $coinServer->getPrice();
$rows[$key]['last'] = $coinServer->getDollar();
$rows[$key]['low'] = $coinServer->getLow();
$rows[$key]['low'] = $coinServer->getLow();
$rows[$key]['high'] = $coinServer->getHigh();
$coinServer->__destruct();
} else {
$rows[$key]['rmb'] = 0;
$rows[$key]['rmb'] = 0;
$rows[$key]['last'] = 0;
$rows[$key]['low'] = 0;
$rows[$key]['low'] = 0;
$rows[$key]['high'] = 0;
$rows[$key]['usd'] = 0;
}
}
if (strtoupper($row['platform']) == 'GUODUN') {
$rows[$key]['rmb'] = 0;
$rows[$key]['rmb'] = 0;
$rows[$key]['last'] = 0;
$rows[$key]['low'] = 0;
$rows[$key]['low'] = 0;
$rows[$key]['high'] = 0;
} else {
$rows[$key] = array_merge($rows[$key], $quotation);
......@@ -290,22 +337,22 @@ class ExchangeBusiness
/**
* 根据名称搜索
*
* @param int $page
* @param int $limit
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord|\yii\db\ActiveRecord[]
*/
public static function SearchByName($page = 1, $limit = 10, $condition = [])
{
$rows = Coin::getSelectList($page, $limit, ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain','address as contract_address', 'treaty'],
$rows = Coin::getSelectList($page, $limit, ['id', 'sid', 'icon', 'name', 'optional_name', 'nickname', 'platform', 'chain', 'address as contract_address', 'treaty'],
$condition);
if ($rows['count'] > 0) {
$total = $rows['count'];
$rows = $rows['data'];
$rows = $rows['data'];
foreach ($rows as $key => $row) {
$rows[$key]['sid'] = ucfirst($rows[$key]['sid']);
$platform = strtoupper($rows[$key]['platform']);
$platform_icon = Yii::$app->redis->hget('platform_image_info',$platform);
$platform_icon = Yii::$app->redis->hget('platform_image_info', $platform);
$rows[$key]['platform_icon'] = $platform_icon ?? '';
}
......@@ -323,16 +370,16 @@ class ExchangeBusiness
$quotation = [];
//使用Coin服务
try {
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$quotation['rmb'] = $coinServer->getPrice();
$coinServer = CoinFactory::createCoin($row['name'], $row['id'], $row['sid']);
$quotation['rmb'] = $coinServer->getPrice();
$quotation['last'] = $coinServer->getDollar();
$quotation['low'] = $coinServer->getLow();
$quotation['low'] = $coinServer->getLow();
$quotation['high'] = $coinServer->getHigh();
$coinServer->__destruct();
} catch (\Exception $exception) {
$quotation['rmb'] = 0;
$quotation['rmb'] = 0;
$quotation['last'] = 0;
$quotation['low'] = 0;
$quotation['low'] = 0;
$quotation['high'] = 0;
\Yii::error($exception->getMessage());
}
......
......@@ -517,6 +517,7 @@ class Curl
$curlOptions = $this->getOptions();
$this->curl = curl_init($this->getUrl());
curl_setopt_array($this->curl, $curlOptions);
curl_setopt($this->curl, CURLOPT_TIMEOUT,40);
$response = curl_exec($this->curl);
//check if curl was successful
if ($response === false) {
......
......@@ -13,12 +13,14 @@ use yii\web\IdentityInterface;
* @property string $uid
* @property string $username
* @property string $password
* @property string $access_token
* @property string $reg_time
* @property string $reg_ip
* @property string $last_login_time
* @property string $last_login_ip
* @property string $update_time
* @property integer $status
* @property integer $platform_id
*/
class Admin extends \common\modelsgii\Admin implements IdentityInterface
{
......@@ -34,14 +36,6 @@ class Admin extends \common\modelsgii\Admin implements IdentityInterface
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.');
}
/**
* 根据用户名获取账号信息
*
* @param string $username
......@@ -156,4 +150,43 @@ class Admin extends \common\modelsgii\Admin implements IdentityInterface
$this->password = null;
}
/**
* @inheritdoc
*/
public static function findIdentityByAccessToken($token, $type = null)
{
$user = static::find()->where(['access_token' => $token, 'status' => self::STATUS_ACTIVE])->one();
if (!$user) {
return false;
}
// if ($user->expire_at < time()) {
// throw new UnauthorizedHttpException('the access - token expired ', -1);
// } else {
// return $user;
// }
return $user;
}
public function loginByAccessToken($accessToken, $type) {
return static::findIdentityByAccessToken($accessToken, $type);
}
/**
* Generate accessToken string
* @return string
* @throws \yii\base\Exception
*/
public function generateAccessToken()
{
$this->access_token = Yii::$app->security->generateRandomString();
return $this->access_token;
}
public static function loadArray(array $data)
{
return self::getDb()->createCommand()->batchInsert(self::tableName(),
['bind_uid', 'username', 'salt', 'password', 'reg_time', 'reg_ip', 'last_login_time', 'last_login_ip', 'update_time', 'status', 'platform_id'],
$data)->execute();
}
}
......@@ -11,10 +11,13 @@ class LoginForm extends Model
{
public $username;
public $password;
public $token;
public $rememberMe = true;
private $_user;
//定义场景
const SCENARIOS_LOGIN = 'login';
/**
* @inheritdoc
......@@ -31,6 +34,13 @@ class LoginForm extends Model
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_LOGIN => ['username', 'password'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
/**
* Validates the password.
* This method serves as the inline validation for password.
......@@ -56,7 +66,12 @@ class LoginForm extends Model
public function login()
{
if ($this->validate()) {
return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
if ($this->getUser()) {
$access_token = $this->_user->generateAccessToken();
$this->_user->access_token = $access_token ;
$this->_user->save();
return $access_token;
}
}
return false;
......@@ -70,7 +85,21 @@ class LoginForm extends Model
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->username);
$this->_user = Admin::findByUsername($this->username);
}
return $this->_user;
}
/**
* Finds user by [[token]]
*
* @return User|null
*/
protected function getToken()
{
if ($this->_user === null) {
$this->_user = Admin::findIdentityByAccessToken($this->token);
}
return $this->_user;
......
......@@ -10,7 +10,7 @@ class CoinAirDropTrade extends BaseActiveRecord
{
const TYPE_GAME = 1;
const AMOUNT_GAME = 0.5;
const AMOUNT_GAME = 0.0001;
public static function getDb()
{
......
......@@ -92,6 +92,11 @@ class CoinApplicationCategory extends BaseActiveRecord
return self::find()->where(['id' => $id])->one();
}
public static function getAppCategory($id)
{
return self::find()->where(['id' => $id])->asArray()->one();
}
public static function getCateItemsArray($condition = [])
{
return self::find()->where($condition)->asArray()->all();
......
......@@ -63,7 +63,7 @@ class CoinGameBet extends BaseActiveRecord
public static function loadArray(array $data)
{
return self::getDb()->createCommand()->batchInsert(self::tableName(),
['round', 'player', 'amount', 'height', 'guess_num', 'rand_num', 'player_win'],
['round', 'player', 'amount', 'height', 'guess_num', 'rand_num', 'player_win', 'platform'],
$data)->execute();
}
}
<?php
namespace common\models\psources;
use Yii;
use common\core\BaseActiveRecord;
class CoinHashMemo extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_hash_memo}}';
}
//定义场景
const SCENARIOS_CREATE = 'create';
const SCENARIOS_UPDATE = 'update';
public function rules() {
return [
[['hash'], 'required'],
[['coins_fee','memo'],'safe']
];
}
public function scenarios() {
$scenarios = [
self:: SCENARIOS_CREATE => ['hash','memo', 'coins_fee'],
];
return array_merge( parent:: scenarios(), $scenarios);
}
}
\ No newline at end of file
......@@ -14,4 +14,63 @@ class CoinPlatform extends BaseActiveRecord
{
return '{{%coin_platform}}';
}
/**
* 获取钱包信息列表
*
* @param int $page
* @param int $limit
* @param array $condition
* @return array|\yii\db\ActiveRecord[]
*/
public static function getList($page = 1, $limit = 10, $condition = [])
{
$query = self::find();
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
return ['count' => $count, 'data' => $data];
}
public function addOne($params)
{
$params = array_filter($params, function ($value) {
if (null == $value) {
return false;
}
return true;
});
$this->setAttributes($params, false);
try {
return (bool)$this->save();
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
}
public function updateOne($params)
{
$params = array_filter($params, function ($value) {
if (null === $value) {
return false;
}
return true;
});
if (isset($params['id']) && !empty($params['id'])) {
$coin = self::findOne(['id' => $params['id']]);
if ($coin === null) {
return ['code' => 1, 'msg' => '币种不存在'];
}
unset($params['id']);
}
$coin->setAttributes($params, false);
try {
return (bool)$coin->save();
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'message' => $exception->getMessage()];
}
}
}
......@@ -6,7 +6,6 @@
* Time: 17:37
*/
namespace common\models\psources;
use Yii;
class CoinPlatformWithHold extends BaseActiveRecord
{
......
......@@ -84,7 +84,7 @@ class CoinRecommend extends BaseActiveRecord
$type = $params['type'] ?? 1;
$chain = $params['chain'] ?? '';
$coin = Coin::findOne(['name' => strtoupper($coin_name)]);
$coin = Coin::findOne(['name' => strtoupper($coin_name), 'platform' => strtoupper($chain)]);
if (empty($coin)) {
return ['code' => -1, 'msg' => '币种不存在'];
}
......
<?php
/**
* Created By Sublime text 3
* User: rlgyzhcn
* Date: 18-08-12
* Time: 下午14:17
*/
namespace common\models\pwallet;
use common\core\BaseActiveRecord;
use Yii;
class GameUserAddress extends BaseActiveRecord{
public static function getDb(){
return Yii::$app->get('db_pwallet');
}
public function formName()
{
return '';
}
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ use yii\helpers\HtmlPurifier;
* @property string $uid
* @property string $username
* @property string $password
* @property string $access_token
* @property string $salt
* @property string $reg_time
* @property string $reg_ip
......@@ -17,6 +18,7 @@ use yii\helpers\HtmlPurifier;
* @property string $last_login_ip
* @property string $update_time
* @property integer $status
* @property integer $platform_id
*/
class Admin extends \common\core\BaseActiveRecord
{
......@@ -42,10 +44,11 @@ class Admin extends \common\core\BaseActiveRecord
return HtmlPurifier::process($str);
}
],
[['reg_time', 'reg_ip', 'last_login_time', 'last_login_ip', 'update_time', 'status'], 'integer'],
[['reg_time', 'reg_ip', 'last_login_time', 'last_login_ip', 'update_time', 'status', 'platform_id'], 'integer'],
[['username'], 'string', 'max' => 32],
[['password'], 'string', 'min' => 6, 'max' => 60],
[['salt'], 'string', 'max' => 32],
['access_token', 'safe']
];
}
......@@ -65,6 +68,7 @@ class Admin extends \common\core\BaseActiveRecord
'last_login_ip' => 'Last Login Ip',
'update_time' => 'Update Time',
'status' => 'Status',
'platform_id' => 'platform_id',
'group' => 'group'
];
}
......
......@@ -313,6 +313,11 @@ class Chain33Service
return $this->send(['height' => $height], 'Chain33.GetBlockHash');
}
public function getProperFee($params = [])
{
return $this->send($params, 'Chain33.GetProperFee');
}
public function getTxByAddr($addr, $flag, $count, $direction, $height, $index)
{
$params = [
......
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-8-7
* Time: 上午11:30
*/
namespace common\service\exchange;
use linslin\yii2\curl\Curl;
class Ex extends Exchange implements ExchangeInterface
{
protected $supported_symbol = 'supported_symbol_zg';
protected $quotation_prefix = 'quotation_ex_';
protected $base_url = 'https://www.ex.pizza/api/v1/tickers';
public function symbolExists($tag = 'FOLI', $aim = "USDT")
{
$supported = $this->redis->smembers($this->supported_symbol);
if (is_array($supported) && in_array($this->formatSymbol($tag, $aim), $supported)) {
return true;
}
return false;
}
/**
* 转化交易对为请求变量
*
* @param string $tag
* @param string $aim
* @return mixed
*/
public function formatSymbol($tag = 'FOLI', $aim = 'USDT')
{
return strtoupper($tag .'_'. $aim);
}
/**
* 保存支持的交易对到redis数据库,使用crontab定时更新
*
* @return mixed|void
*/
public function setSupportedSymbol()
{
$this->redis->sadd($this->supported_symbol, 'FOLI_USDT');
}
/**
* 更新交易对行情保存到redis,使用crontab定时更新
*
* @return mixed|void
*/
public function setQuotation()
{
$curl = new Curl();
$curl->setHeaders([
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36',
]);
$content = $curl->get($this->base_url, false);
if (is_array($content) && isset($content['ticker'])) {
$data = $content['ticker'];
foreach ($data as $item) {
if (in_array($item['symbol'], ['FOLI_USDT'])) {
$data = $item;
$key = $this->quotation_prefix . $item['symbol'];
$this->redis->hmset($key, 'low', $data['low'], 'high', $data['high'], 'last', $data['last']);
$this->redis->sadd($this->supported_symbol, $item['symbol']);
}
}
}
}
}
\ No newline at end of file
<?php
namespace common\service\trusteeship;
use Yii;
use common\helpers\Curl;
class TrusteeShipService
{
private $node_params;
private $header;
public function __construct($parameter = [], $header = [])
{
$platform_id = Yii::$app->request->getPlatformId();
if (!empty($header)) {
$this->header = $header;
}
if (empty($parameter)) {
$this->node_params = Yii::$app->params['trusteeship']['node_' . $platform_id]['url'];
} else {
$this->node_params = $parameter['url'];
}
}
public function urlBuild($uri = '')
{
return $this->node_params . '/' . $uri;
}
public function send($method = 'GET', $uri, $params = [])
{
$ch = new Curl();
if (!empty($this->header)) {
$ch->setHeaders($this->header);
}
if (!empty($params)) {
$ch->setGetParams($params);
}
$result = $ch->$method($this->urlBuild($uri), false);
if (!$result) {
return ['code' => -1, 'msg' => $ch->errorText];
}
if (200 == $result['code']) {
return ['code' => $result['code'], 'msg' => $result['data']];
} else {
return ['code' => -1, 'msg' => $result['message']];
}
}
public function getUserList($params = [])
{
$uri = 'backend/user/user-list';
return $this->send("GET", $uri, $params);
}
public function getWalletBalance($params = [])
{
$uri = 'backend/account/wallet-balance';
return $this->send("GET", $uri, $params);
}
public function getUserAsset($params = [])
{
$uri = 'backend/user/asset';
return $this->send("GET", $uri, $params);
}
}
......@@ -16,105 +16,120 @@ class GameBetController extends Controller
*/
public function actionGameStatus()
{
$service = new Chain33Business();
$result = $service->getGameStatus();
if( 0 !== $result['code']){
echo date('Y-m-d H:i:s') . $result['msg'].PHP_EOL;
$nodes = \Yii::$app->params['chain_parallel']['wasm'];
if(empty($nodes)){
echo date('Y-m-d H:i:s') . '无节点'.PHP_EOL;
return 0;
}
foreach ($nodes as $key => $node) {
$service = new Chain33Business();
$result = $service->getGameStatus($node);
if (0 !== $result['code']) {
echo $key.':'.date('Y-m-d H:i:s') . $result['msg'].PHP_EOL;
continue;
}
$queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){
echo date('Y-m-d H:i:s') . 'error'.PHP_EOL;
return 0;
}
$queryResultItems = $result['result'] ?? [];
if (empty($queryResultItems)) {
echo $key.':'.date('Y-m-d H:i:s') . 'error'.PHP_EOL;
continue;
}
$resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'],true);
$current_round = $resultJSON['current_round'];
$cache_current_round = Yii::$app->redis->get('chain33_game_bet_status');
if(empty($cache_current_round)){
$cache_current_round = CoinGameBet::find()->max('round');
Yii::$app->redis->set('chain33_game_bet_status',$cache_current_round,'EX',300);
}
$cache_current_round = (false == $cache_current_round ? 0 : $cache_current_round);
if($cache_current_round >= $current_round){
echo date('Y-m-d H:i:s') . '数据已为最新'.PHP_EOL;
return 0;
}
Yii::$app->redis->set('chain33_game_bet_status',$current_round,'EX',300);
$resultJSON = json_decode($queryResultItems['queryResultItems'][0]['resultJSON'], true);
$current_round = $resultJSON['current_round'];
$cache_current_round = Yii::$app->redis->get('chain33_game_bet_status_'.$key);
if (empty($cache_current_round)) {
$cache_current_round = CoinGameBet::find()->where(['platform' => $key])->max('round');
Yii::$app->redis->set('chain33_game_bet_status_'.$key, $cache_current_round, 'EX', 300);
}
$cache_current_round = (false == $cache_current_round ? 0 : $cache_current_round);
if ($cache_current_round >= $current_round) {
echo $key.':'.date('Y-m-d H:i:s') . '数据已为最新' . PHP_EOL;
continue;
}
Yii::$app->redis->set('chain33_game_bet_status_'.$key, $current_round, 'EX', 300);
$result = $service->getBetStatus($cache_current_round, $current_round);
if( 0 !== $result['code']){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
return 0;
}
$result = $service->getBetStatus($cache_current_round, $current_round, '', $node);
if (0 !== $result['code']) {
echo $key.':'.date('Y-m-d H:i:s') . '数据错误' . PHP_EOL;
continue;
}
$queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
return 0;
$queryResultItems = $result['result'] ?? [];
if (empty($queryResultItems)) {
echo $key.':'.date('Y-m-d H:i:s') . '数据错误' . PHP_EOL;
continue;
}
$platform = $key;
foreach ($queryResultItems['queryResultItems'] as $key => $val) {
if (false == $val['found']) continue;
$resultArr = json_decode($val['resultJSON'], true);
$datas[] = [
$resultArr['round'], $resultArr['player'], $resultArr['amount'], $resultArr['height'], $resultArr['guess_num'], $resultArr['rand_num'], $resultArr['player_win'], $platform
];
}
CoinGameBet::loadArray($datas);
echo $platform.':'.date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
continue;
}
foreach ($queryResultItems['queryResultItems'] as $key => $val){
if( false == $val['found'] ) continue;
$resultArr = json_decode($val['resultJSON'],true);
$datas[] = [
$resultArr['round'], $resultArr['player'], $resultArr['amount'], $resultArr['height'], $resultArr['guess_num'], $resultArr['rand_num'], $resultArr['player_win']
];
}
CoinGameBet::loadArray($datas);
echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
return 0;
}
public function actionBetUpdate()
{
$service = new Chain33Business();
$result = $service->getLastHeader();
$result = $result['result'] ?? [];
if(empty($result)){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
return 0;
}
$height = $result['height'];
$models = CoinGameBet::find()->select('round')->where([
'and',
['valid' => CoinGameBet::VAILD_FALSE],
['<', 'height', $height - 12]
])->all();
if(empty($models)){
echo date('Y-m-d H:i:s') . '无需更新的数据'.PHP_EOL;
return 0;
}
$valid_arr = [];
foreach ($models as $model) {
$valid_arr[] = $model->round;
}
$result = $service->getBetStatus('', '', $valid_arr);
if( 0 !== $result['code']){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
$nodes = \Yii::$app->params['chain_parallel']['wasm'];
if(empty($nodes)){
echo date('Y-m-d H:i:s') . '无节点'.PHP_EOL;
return 0;
}
foreach ($nodes as $key => $node) {
$service = new Chain33Business();
$result = $service->getLastHeader($node);
$height = $result['result']['height'];
$models = CoinGameBet::find()->select('round')->where([
'and',
['valid' => CoinGameBet::VAILD_FALSE],
['<', 'height', $height - 12],
['platform' => $key]
])->all();
if(empty($models)){
echo $key.':'.date('Y-m-d H:i:s') . '无需更新的数据'.PHP_EOL;
continue;
}
$valid_arr = [];
foreach ($models as $model) {
$valid_arr[] = $model->round;
}
$result = $service->getBetStatus('', '', $valid_arr, $node);
if( 0 !== $result['code']){
echo $key.':'.date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
continue;
}
$queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){
echo date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
return 0;
}
foreach ($queryResultItems['queryResultItems'] as $key => $val){
if (false == $val['found']) continue;
$resultArr = json_decode($val['resultJSON'],true);
CoinGameBet::updateAll([
'amount' => $resultArr['amount'],
'height' => $resultArr['height'],
'guess_num' => $resultArr['guess_num'],
'rand_num' => $resultArr['rand_num'],
'player_win' => $resultArr['player_win'],
'valid' => CoinGameBet::VAILD_TRUE
],[
'round' => $resultArr['round']
]);
$queryResultItems = $result['result'] ?? [];
if(empty($queryResultItems)){
echo $key.':'.date('Y-m-d H:i:s') . '数据错误'.PHP_EOL;
continue;
}
$platform = $key;
foreach ($queryResultItems['queryResultItems'] as $key => $val){
if (false == $val['found']) continue;
$resultArr = json_decode($val['resultJSON'],true);
CoinGameBet::updateAll([
'amount' => $resultArr['amount'],
'height' => $resultArr['height'],
'guess_num' => $resultArr['guess_num'],
'rand_num' => $resultArr['rand_num'],
'player_win' => $resultArr['player_win'],
'valid' => CoinGameBet::VAILD_TRUE
],[
'round' => $resultArr['round'],
'platform' => $platform
]);
}
echo $platform.':'.date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
continue;
}
echo date('Y-m-d H:i:s') . '数据更新成功'.PHP_EOL;
return 0;
}
}
\ No newline at end of file
......@@ -61,7 +61,7 @@ class CoinController extends BaseController
if (!is_array($names)) {
$names = [$names];
}
$condition = [['in', 'name', $names]];
$condition = $names;
$fields = ['id', 'sid', 'icon', 'name', 'nickname', 'platform', 'chain','address as contract_address','introduce'];
$result = ExchangeBusiness::getApiListForIndex(1, 999, $condition,$fields);
if ($result) {
......
<?php
namespace wallet\base;
class BaseConstant
{
const ERROR = 'error';
const MSG = 'msg';
const MESSAGE = 'message';
const CODE = 'code';
const VAL = 'val';
const DATA = 'data';
const OK = 'ok';
const FINALTAG = 'finaltag';
}
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 上午10:29
*/
namespace wallet\base;
use Yii;
use yii\helpers\Url;
use yii\web\Response;
use yii\base\Controller;
use yii\base\InlineAction;
use yii\web\BadRequestHttpException;
class BaseController extends Controller
{
public function behaviors()
{
$request_controller = Yii::$app->controller->id;
$request_action = Yii::$app->controller->action->id;
$interceptor_global = array_unique(Yii::$app->params['interceptor']['global']);
$interceptor_default = array_unique(Yii::$app->params['interceptor']['default']);
$interceptor_mapping = isset(Yii::$app->params['interceptor'][$request_controller]) ? array_unique(Yii::$app->params['interceptor'][$request_controller]) : null;
$controller_enable = $interceptor_mapping ?? false;
$behaviors = [];
$final_interceptor = array_keys(array_flip(array_merge($interceptor_global, $interceptor_default)));
if ($controller_enable) {
$interceptor_map = $interceptor_mapping['interceptors'];
if ($interceptor_map) {
$switch = array_shift($interceptor_map);
if (false == $switch) {
$deny_interceptor = $interceptor_map;
$final_interceptor = array_diff($interceptor_default, $deny_interceptor);
} else {
$final_interceptor = array_unique($interceptor_map);
}
}
$action_mapping = $interceptor_mapping['actions'] ?? false;
if ($action_mapping) { //指定方法使用哪些拦截器
foreach ($action_mapping as $val) {
$action_id = array_shift($val); //拦截器配置文件中的action
$interceptor_map = $val[0];
$switch = array_shift($interceptor_map); //拦截器配置文件中action对应的拦截开关
if ($action_id == $request_action) {
if (false == $switch) {
$final_interceptor = array_unique(array_merge($interceptor_map, $interceptor_global));
$final_interceptor = array_diff($interceptor_default, array_diff($final_interceptor, $interceptor_global));
} else {
$final_interceptor = array_unique($interceptor_map);
}
}
}
}
}
foreach ($final_interceptor as $key => $item) {
$behaviors[$key] = [
'class' => $item,
];
}
return $behaviors;
}
/**
* @var bool whether to enable CSRF validation for the actions in this controller.
* CSRF validation is enabled only when both this property and [[\yii\web\Request::enableCsrfValidation]] are true.
*/
public $enableCsrfValidation = true;
/**
* @var array the parameters bound to the current action.
*/
public $actionParams = [];
/**
* Renders a view in response to an AJAX request.
*
* This method is similar to [[renderPartial()]] except that it will inject into
* the rendering result with JS/CSS scripts and files which are registered with the view.
* For this reason, you should use this method instead of [[renderPartial()]] to render
* a view to respond to an AJAX request.
*
* @param string $view the view name. Please refer to [[render()]] on how to specify a view name.
* @param array $params the parameters (name-value pairs) that should be made available in the view.
* @return string the rendering result.
*/
public function renderAjax($view, $params = [])
{
return $this->getView()->renderAjax($view, $params, $this);
}
/**
* Send data formatted as JSON.
*
* This method is a shortcut for sending data formatted as JSON. It will return
* the [[Application::getResponse()|response]] application component after configuring
* the [[Response::$format|format]] and setting the [[Response::$data|data]] that should
* be formatted. A common usage will be:
*
* ```php
* return $this->asJson($data);
* ```
*
* @param mixed $data the data that should be formatted.
* @return Response a response that is configured to send `$data` formatted as JSON.
* @since 2.0.11
* @see Response::$format
* @see Response::FORMAT_JSON
* @see JsonResponseFormatter
*/
public function asJson($data)
{
$response = Yii::$app->getResponse();
$response->format = Response::FORMAT_JSON;
$response->data = $data;
return $response;
}
/**
* Send data formatted as XML.
*
* This method is a shortcut for sending data formatted as XML. It will return
* the [[Application::getResponse()|response]] application component after configuring
* the [[Response::$format|format]] and setting the [[Response::$data|data]] that should
* be formatted. A common usage will be:
*
* ```php
* return $this->asXml($data);
* ```
*
* @param mixed $data the data that should be formatted.
* @return Response a response that is configured to send `$data` formatted as XML.
* @since 2.0.11
* @see Response::$format
* @see Response::FORMAT_XML
* @see XmlResponseFormatter
*/
public function asXml($data)
{
$response = Yii::$app->getResponse();
$response->format = Response::FORMAT_XML;
$response->data = $data;
return $response;
}
/**
* Binds the parameters to the action.
* This method is invoked by [[\yii\base\Action]] when it begins to run with the given parameters.
* This method will check the parameter names that the action requires and return
* the provided parameters according to the requirement. If there is any missing parameter,
* an exception will be thrown.
* @param \yii\base\Action $action the action to be bound with parameters
* @param array $params the parameters to be bound to the action
* @return array the valid parameters that the action can run with.
* @throws BadRequestHttpException if there are missing or invalid parameters.
*/
public function bindActionParams($action, $params)
{
if ($action instanceof InlineAction) {
$method = new \ReflectionMethod($this, $action->actionMethod);
} else {
$method = new \ReflectionMethod($action, 'run');
}
$args = [];
$missing = [];
$actionParams = [];
foreach ($method->getParameters() as $param) {
$name = $param->getName();
if (array_key_exists($name, $params)) {
if ($param->isArray()) {
$args[] = $actionParams[$name] = (array)$params[$name];
} elseif (!is_array($params[$name])) {
$args[] = $actionParams[$name] = $params[$name];
} else {
throw new BadRequestHttpException(Yii::t('yii', 'Invalid data received for parameter "{param}".', [
'param' => $name,
]));
}
unset($params[$name]);
} elseif ($param->isDefaultValueAvailable()) {
$args[] = $actionParams[$name] = $param->getDefaultValue();
} else {
$missing[] = $name;
}
}
if (!empty($missing)) {
throw new BadRequestHttpException(Yii::t('yii', 'Missing required parameters: {params}', [
'params' => implode(', ', $missing),
]));
}
$this->actionParams = $actionParams;
return $args;
}
/**
* {@inheritdoc}
*/
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
if ($this->enableCsrfValidation && Yii::$app->getErrorHandler()->exception === null && !Yii::$app->getRequest()->validateCsrfToken()) {
throw new BadRequestHttpException(Yii::t('yii', 'Unable to verify your data submission.'));
}
return true;
}
return false;
}
/**
* Redirects the browser to the specified URL.
* This method is a shortcut to [[Response::redirect()]].
*
* You can use it in an action by returning the [[Response]] directly:
*
* ```php
* // stop executing this action and redirect to login page
* return $this->redirect(['login']);
* ```
*
* @param string|array $url the URL to be redirected to. This can be in one of the following formats:
*
* - a string representing a URL (e.g. "http://example.com")
* - a string representing a URL alias (e.g. "@example.com")
* - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`)
* [[Url::to()]] will be used to convert the array into a URL.
*
* Any relative URL that starts with a single forward slash "/" will be converted
* into an absolute one by prepending it with the host info of the current request.
*
* @param int $statusCode the HTTP status code. Defaults to 302.
* See <https://tools.ietf.org/html/rfc2616#section-10>
* for details about HTTP status code
* @return Response the current response object
*/
public function redirect($url, $statusCode = 302)
{
return Yii::$app->getResponse()->redirect(Url::to($url), $statusCode);
}
/**
* Redirects the browser to the home page.
*
* You can use this method in an action by returning the [[Response]] directly:
*
* ```php
* // stop executing this action and redirect to home page
* return $this->goHome();
* ```
*
* @return Response the current response object
*/
public function goHome()
{
return Yii::$app->getResponse()->redirect(Yii::$app->getHomeUrl());
}
/**
* Redirects the browser to the last visited page.
*
* You can use this method in an action by returning the [[Response]] directly:
*
* ```php
* // stop executing this action and redirect to last visited page
* return $this->goBack();
* ```
*
* For this function to work you have to [[User::setReturnUrl()|set the return URL]] in appropriate places before.
*
* @param string|array $defaultUrl the default return URL in case it was not set previously.
* If this is null and the return URL was not set previously, [[Application::homeUrl]] will be redirected to.
* Please refer to [[User::setReturnUrl()]] on accepted format of the URL.
* @return Response the current response object
* @see User::getReturnUrl()
*/
public function goBack($defaultUrl = null)
{
return Yii::$app->getResponse()->redirect(Yii::$app->getUser()->getReturnUrl($defaultUrl));
}
/**
* Refreshes the current page.
* This method is a shortcut to [[Response::refresh()]].
*
* You can use it in an action by returning the [[Response]] directly:
*
* ```php
* // stop executing this action and refresh the current page
* return $this->refresh();
* ```
*
* @param string $anchor the anchor that should be appended to the redirection URL.
* Defaults to empty. Make sure the anchor starts with '#' if you want to specify it.
* @return Response the response object itself
*/
public function refresh($anchor = '')
{
return Yii::$app->getResponse()->redirect(Yii::$app->getRequest()->getUrl() . $anchor);
}
protected function initParams($p = [], $fields = [], $isFilter = false)
{
$params = [];
if (!empty($fields)) {
foreach ($fields as $key => $value) {
if (isset($p[$value]) && (!empty($p[$value]) || $p[$value] == 0)) {
$params[$value] = $p[$value];
} else {
if (!$isFilter) $params[$value] = null;
}
}
}
return $params;
}
protected function getSign($params, $appkey, $appSecret, $time)
{
ksort($params);
$string = http_build_query($params);
$result = md5($appkey . $string . $appSecret . $time);
$sign = strtoupper($result);
return $sign;
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-31
* Time: 下午1:28
*/
namespace wallet\base;
use yii\web\Response;
class BaseResponse extends Response
{
public function send()
{
//错误处理
$excpetion = \Yii::$app->errorHandler->exception;
if ($excpetion !== null) {
$this->data = [
'code' => $excpetion->getCode(),
'msg' => $excpetion->getMessage(),
'line' => $excpetion->getLine(),
'file' => $excpetion->getFile(),
];
}
//TODO 在这里对数据进行format,这样控制器中可以直接return一个array,保存到数据域data中即可,eg:['code'=>0,'data'=>$data]
$data = \Yii::$app->response->data;
if (empty($data)) {
$return['code'] = 1;
$return['msg'] = '数据为空';
} elseif (is_array($data) && !isset($data['code'])) {
$return['code'] = 0;
$return['count'] = count($data);
$return['data'] = $data;
} else {
$return = $data;
}
if (YII_ENV_DEV) {
#$return['time'] = \Yii::$app->controller->end - \Yii::$app->controller->start;
}
\Yii::$app->response->data = $return;
parent::send();
}
}
\ No newline at end of file
<?php
namespace wallet\base;
use yii\helpers\Html;
use yii\web\Response;
class ResponseMsg
{
public $is_support_jsonp = false;
public $header_list = [];
private static $default_header_list = [];
public function __construct()
{
// if ('cli' !== php_sapi_name()){
// $this->header_list = self::$default_header_list;
// $this->fzmCrossHeader();
// }
}
public function fzmCrossHeader()
{
$allow_list = \Yii::$app->params['allow_options_domain']['common'];
$origin = \Yii::$app->request->headers->get('Origin');
if (!in_array($origin, $allow_list)) {
$origin = implode(',', $allow_list);
}
$this->header('Access-Control-Allow-Origin', $origin);
$this->header('Access-Control-Allow-Methods', 'POST,GET,OPTIONS');
$this->header('Access-Control-Allow-Credentials', 'true');
$this->header('Access-Control-Allow-Headers', 'Authorization,FZM-REQUEST-OS,FZM-USER-IP,FZM-REQUEST-UUID,Content-Type,Content-Length');
}
public static function setDefaultHeader($default_header_list)
{
foreach ($default_header_list as $key => $header) {
self::$default_header_list[$key] = $header;
}
}
public static function getDefaultHeader()
{
return self::$default_header_list;
}
public function arrSuccess($data = BaseConstant::OK, $code = 200)
{
return [BaseConstant::ERROR => false, BaseConstant::MESSAGE => $data, BaseConstant::CODE => $code];
}
public function arrFail($data, $code = -1)
{
return [BaseConstant::ERROR => true, BaseConstant::MESSAGE => $data, BaseConstant::CODE => $code];
}
/**
* 失败返回接口
* @param string $msg
* @param int $code
* @return string
*/
public function jsonError($msg = '', $code = -1)
{
if (empty($msg)) {
$msg = 'unknown error';
}
$view = [
BaseConstant::CODE => $code,
BaseConstant::MESSAGE => $msg,
];
$json = json_encode($view);
return $this->dumpJsonData($json);
}
/**
* 成功返回接口
* @param string $msg
* @param int $code
* @return string
*/
public function jsonSuccess($data = '', $code = 200)
{
$view = [
BaseConstant::CODE => $code,
BaseConstant::MESSAGE => BaseConstant::OK,
BaseConstant::DATA => $data
];
$json = json_encode($view);
return $this->dumpJsonData($json);
}
/**
* 直接处理接口数据
* @param $ret
*/
public function dealRet($ret)
{
if (true === $ret[BaseConstant::ERROR]) {
$this->jsonError($ret[BaseConstant::MESSAGE] ? : 'unknown error');
} else {
$this->jsonSuccess($ret[BaseConstant::MESSAGE] ? : BaseConstant::OK);
}
}
/**
* 根据是否为JSONP做特殊处理输出
* @param $json
* @return string
*/
public function dumpJsonData($json)
{
$callback = '';
if (true === $this->is_support_jsonp) {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
$callback_key = 'jsonpcallback';
$callback = $_GET[$callback_key];
if ($callback) {
$callback = Html::encode($callback_key);
$json = $callback . '(' . $json . ')';
}
}
if (!$callback && !$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return $json;
}
/**
* @param $json_str
* @param string $callback_key
* @return string
*/
public function printByJson($json_str, $callback_key = '')
{
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . $json_str . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return $json_str;
}
}
/**
* @param $arr
* @param string $callback_key
* @return string
*/
public function printByArr($arr, $callback_key = '')
{
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
public function printOldFail($code, $code_msg, $detail_code, $detail_msg, $callback_key = '')
{
$this->fzmCrossHeader();
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
$arr = ['code' => $code, 'error' => $code_msg, 'ecode' => $detail_code, 'message' => $detail_msg, 'data' => []];
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
/**
* @param $success_data
* @param string $callback_key
* @return string
*/
public function printOldSuccess($success_data, $callback_key = '')
{
$this->fzmCrossHeader();
$callback = '';
if ($callback_key) {
$callback = $_GET[$callback_key] ?? '';
}
$arr = ['code' => 200, 'ecode' => 200, 'error' => 'OK', 'message' => 'OK', 'data' => $success_data];
if ($callback) {
$callback = Html::encode($callback_key);
if (!$this->isDebug()) {
$this->header('Content-type', 'application/javascript');
}
return $callback . '(' . json_encode($arr) . ')';
} else {
if (!$this->isDebug()) {
$this->header('Content-type', 'application/json');
}
return json_encode($arr);
}
}
/**
* 解决xdebug cookie设置不了的问题
*/
private function isDebug()
{
if (defined('SERVICE_ENV') && (SERVICE_ENV === 'test' || SERVICE_ENV === 'local') && isset($_GET['debug'])) {
return true;
}
return false;
}
public function header($key, $value)
{
$this->header_list[$key] = $value;
}
public function getHeaders()
{
return $this->header_list;
}
public function withHeaders($header_arr)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
foreach ($header_arr as $key => $val) {
\Yii::$app->response->headers->add($key, $val);
}
return $this;
}
public function withContent($content)
{
return $content;
}
}
namespace: backend\tests
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
modules:
config:
Yii2:
configFile: 'config/test-local.php'
main-local.php
params-local.php
\ No newline at end of file
<?php
$params = array_merge(
require __DIR__ . '/../../common/config/params.php',
require __DIR__ . '/../../common/config/params-local.php',
require __DIR__ . '/params.php',
require __DIR__ . '/params-local.php'
);
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'timeZone' => 'Etc/GMT-8',
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'defaultRoute' => 'site/index',
'layout' => 'main',
'modules' => [],
'components' => [
'request' => [
'class' => 'common\core\Request',
'baseUrl' => '/admin',
'cookieValidationKey' => 'Yr4XDePew55tutE3CVZ7vBUqVO3iorN6',
//'csrfParam' => '_csrf-backend',
],
'session' => [
'name' => 'manage-backend',
],
'errorHandler' => [
'errorAction' => 'public/error',
],
'urlManager' => [
'class' => 'common\core\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
]
],
'params' => $params,
];
<?php
return [
'adminEmail' => 'admin@example.com',
/* 后台错误页面模板 */
'action_error' => '@backend/views/public/error.php', // 默认错误跳转对应的模板文件
'action_success' => '@backend/views/public/success.php', // 默认成功跳转对应的模板文件
];
<?php
namespace wallet\controllers;
use common\models\psources\CoinPlatformWithHold;
use common\service\chain33\Chain33Service;
use Yii;
use wallet\base\BaseController;
use yii\data\Pagination;
class MonitorController extends BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function actionList()
{
$msg = 'ok';
$code = 0;
$page = Yii::$app->request->get('page', 1);
$query = CoinPlatformWithHold::find()->select('id, platform, address')->asArray();
$count = $query->count();
if( 0 == $count ) {
$msg = '数据不存在';
$code = -1;
$data = null;
goto doEnd;
}
$models = $query->offset(($page - 1) * 10)->limit(10)->asArray()->all();
$countQuery = clone $query;
$pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => '10']);
$address = [];
foreach ($models as $model){
$address[] = $model['address'];
}
if(empty($address)){
$data = null;
goto doEnd;
}
$service = new Chain33Service();
$execer = 'coins';
$result = $service->getBalance($address, $execer);
if(0 != $result['code']){
$msg = $result['msg'];
$code = -1;
goto doEnd;
}
$result_balance = $result['result'];
$balance_arr = [];
foreach ($result_balance as $key => $val){
$balance_arr[$val['addr']] = $val;
}
foreach ($models as &$model){
$model['balance'] = $balance_arr[$model['address']]['balance'];
}
$data = [
'list' => $models,
'page' => [
'pageCount' => $pages->pageCount,
'pageSize' => 10,
'currentPage' => $page,
]
];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
}
\ No newline at end of file
<?php
namespace wallet\controllers;
use Yii;
use common\models\Admin;
use common\models\LoginForm;
use wallet\base\BaseController;
use common\service\trusteeship\TrusteeShipService;
class UserController extends BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function actionLogin()
{
$msg = 'ok';
$code = 0;
$model = new LoginForm();
$model->setScenario(LoginForm::SCENARIOS_LOGIN);
$model->load(Yii::$app->request->post(), '');
if (!$model->login()) {
$msg = implode(", ", \yii\helpers\ArrayHelper::getColumn($model->errors, 0, false)); // Model's Errors string
$data = null;
$code = -1;
goto doEnd;
}
$data = ['access_token' => $model->login()];
doEnd :
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
public function actionUserInfo()
{
$msg = 'ok';
$code = 0;
$token_string = Yii::$app->request->headers->get('Token');
$user = Admin::findIdentityByAccessToken($token_string);
$data = [
'username' => $user->username,
'uid' => isset($user->bind_uid) ? $user->bind_uid : $user->uid,
'type' => isset($user->bind_uid) ? 2 : 1,
'platform_id' => $user->platform_id
];
return ['code' => $code, 'msg' => $msg, 'data' => $data];
}
/**
* 用户同步
*/
public function actionUserSync()
{
$items = Yii::$app->request->post();
if (count($items['items']) > 10) {
return ['code' => -1, 'data' => [], 'msg' => '一次最多同步20条数据'];
}
$duplicate = 0;
foreach ($items['items'] as $key => $item) {
$model = Admin::find()->where(['username' => $item['username']])->andWhere(['platform_id' => (int)$item['platform']])->one();
if ($model) {
$duplicate++;
continue;
}
$datas[] = [
$item['bind_uid'],
$item['username'],
Yii::$app->security->generateRandomString(),
Yii::$app->security->generatePasswordHash('123456'),
time(),
ip2long('127.0.0.1'),
0,
ip2long('127.0.0.1'),
0,
1,
$item['platform']
];
}
if (!empty($datas)) {
Admin::loadArray($datas);
}
return ['code' => 1, 'data' => [], 'msg' => '数据更新成功,共有 ' . $duplicate . ' 条重复'];
$header = Yii::$app->request->headers;
$platform_id = $header['platform_id'] ?? 17;
$post = Yii::$app->request->post();
$data = [
'bind_uid' => $post['bind_uid'],
'username' => $post['username'],
'salt' => Yii::$app->security->generateRandomString(),
'password' => Yii::$app->security->generatePasswordHash('123456'),
'reg_time' => time(),
'reg_ip' => ip2long('127.0.0.1'),
'last_login_time' => 0,
'last_login_ip' => ip2long('127.0.0.1'),
'update_time' => 0,
'status' => 1,
'platform_id' => $platform_id
];
$role = Yii::$app->request->post('role', 'GHPwallet');
$model = new Admin();
if ($model->load($data, '') && $model->save()) {
$auth = Yii::$app->authManager;
$role = $auth->getRole($role);
$auth->assign($role, $model->uid);
exit;
} else {
var_dump($model->errors);
exit;
}
}
/**
* 用户列表
*/
public function actionUserList()
{
$current_platform_id = Yii::$app->request->getPlatformId();
if(1 === $current_platform_id) {
$platform_id = Yii::$app->request->get('platform_id', 1);
$platform_id = empty($platform_id) ? 1 : $platform_id;
} else {
$platform_id = Yii::$app->request->getPlatformId();
}
if(!isset(Yii::$app->params['trusteeship']['node_'. $platform_id])){
return ['code' => -1, 'data' => [], 'msg' => '此钱包节点尚未开通'];
}
$node_params = Yii::$app->params['trusteeship']['node_'. $platform_id];
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 15);
$real_type = Yii::$app->request->get('real_type', '');
$search_type = Yii::$app->request->get('search_type', 'user');
$search = Yii::$app->request->get('search', '');
$start_time = Yii::$app->request->get('start_time', '');
$end_time = Yii::$app->request->get('end_time', '');
$params = [
'page' => $page,
'size' => $size,
'real_type' => $real_type,
'search_type' => $search_type,
'search' => $search,
'start_time' => $start_time,
'end_time' => $end_time
];
$time = time();
$appKey = isset($node_params['appKey']) ? $node_params['appKey'] : null;
$appSecret = isset($node_params['appSecret']) ? $node_params['appSecret'] : null;
$signature = self::getSign($params, $appKey, $appSecret, $time);
$headers = [
'FZM-Wallet-Signature' => $signature,
'FZM-Wallet-Timestamp' => $time,
'FZM-Wallet-AppKey' => $appKey,
'FZM-Wallet-AppIp' => Yii::$app->request->userIP
];
$service = new TrusteeShipService($node_params, $headers);
$result = $service->getUserList($params);
if (200 !== $result['code']) {
return ['code' => $result['code'], 'data' => [], 'msg' => $result['msg']];
}
return ['code' => 1, 'data' => $result['msg'], 'msg' => 'success'];
}
}
\ No newline at end of file
<?php
namespace wallet\controllers;
use common\service\trusteeship\TrusteeShipService;
use Yii;
use common\models\Admin;
use wallet\base\BaseController;
use common\models\psources\CoinPlatform;
class WalletController extends BaseController
{
/**
* landing
* @return array
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function actionList()
{
$platform_id = Yii::$app->request->getPlatformId();
if (1 === $platform_id) {
$platforms = CoinPlatform::find()->select('id, name')->asArray()->all();
} else {
$platforms = CoinPlatform::find()->select('id, name')->where(['id' => $platform_id])->asArray()->all();
}
return ['code' => 0, 'msg' => 'ok', 'data' => $platforms];
}
public function actionWalletBallance()
{
$current_platform_id = Yii::$app->request->getPlatformId();
if(1 === $current_platform_id) {
$platform_id = Yii::$app->request->get('platform_id', 1);
$platform_id = empty($platform_id) ? 1 : $platform_id;
} else {
$platform_id = Yii::$app->request->getPlatformId();
}
if(!isset(Yii::$app->params['trusteeship']['node_'. $platform_id])){
return ['code' => -1, 'data' => [], 'msg' => '此钱包节点尚未开通'];
}
$node_params = Yii::$app->params['trusteeship']['node_'. $platform_id];
$type = Yii::$app->request->get('type', 1);
$page = Yii::$app->request->get('page', 1);
$size = Yii::$app->request->get('size', 15);
$currency = Yii::$app->request->get('currency ', '');
$params = [
'type' => $type,
'page' => $page,
'size' => $size,
'currency' => $currency
];
$time = time();
$appKey = isset($node_params['appKey']) ? $node_params['appKey'] : null;
$appSecret = isset($node_params['appSecret']) ? $node_params['appSecret'] : null;
$signature = self::getSign($params, $appKey, $appSecret, $time);
$headers = [
'FZM-Wallet-Signature' => $signature,
'FZM-Wallet-Timestamp' => $time,
'FZM-Wallet-AppKey' => $appKey,
'FZM-Wallet-AppIp' => Yii::$app->request->userIP
];
$service = new TrusteeShipService($node_params, $headers);
$result = $service->getWalletBalance($params);
if (200 !== $result['code']) {
return ['code' => $result['code'], 'data' => [], 'msg' => $result['msg']];
}
return ['code' => 1, 'data' => $result['msg'], 'msg' => 'success'];
}
public function actionUserAsset()
{
$platform_id = Yii::$app->request->getPlatformId();
$node_params = Yii::$app->params['trusteeship']['node_'. $platform_id];
$uid = Yii::$app->request->get('uid', '');
$params = [
'uid' => $uid
];
$time = time();
$appKey = isset($node_params['appKey']) ? $node_params['appKey'] : null;
$appSecret = isset($node_params['appSecret']) ? $node_params['appSecret'] : null;
$signature = self::getSign($params, $appKey, $appSecret, $time);
$headers = [
'FZM-Wallet-Signature' => $signature,
'FZM-Wallet-Timestamp' => $time,
'FZM-Wallet-AppKey' => $appKey,
'FZM-Wallet-AppIp' => Yii::$app->request->userIP
];
$service = new TrusteeShipService($node_params, $headers);
$result = $service->getUserAsset($params);
if (200 !== $result['code']) {
return ['code' => $result['code'], 'data' => [], 'msg' => $result['msg']];
}
return ['code' => 1, 'data' => $result['msg'], 'msg' => 'success'];
}
}
\ No newline at end of file
*
!.gitignore
\ No newline at end of file
<?php
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'test');
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../');
require_once YII_APP_BASE_PATH . '/vendor/autoload.php';
require_once YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php';
require_once YII_APP_BASE_PATH . '/common/config/bootstrap.php';
require_once __DIR__ . '/../config/bootstrap.php';
<?php
return [
[
'username' => 'erau',
'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
// password_0
'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
'created_at' => '1392559490',
'updated_at' => '1392559490',
'email' => 'sfriesen@jenkins.info',
],
];
<?php
namespace backend\tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class FunctionalTester extends \Codeception\Actor
{
use _generated\FunctionalTesterActions;
/**
* Define custom actions here
*/
}
<?php
namespace backend\tests;
/**
* Inherited Methods
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
*/
class UnitTester extends \Codeception\Actor
{
use _generated\UnitTesterActions;
/**
* Define custom actions here
*/
}
class_name: FunctionalTester
modules:
enabled:
- Yii2
<?php
namespace backend\tests\functional;
use backend\tests\FunctionalTester;
use common\fixtures\UserFixture;
/**
* Class LoginCest
*/
class LoginCest
{
/**
* Load fixtures before db transaction begin
* Called in _before()
* @see \Codeception\Module\Yii2::_before()
* @see \Codeception\Module\Yii2::loadFixtures()
* @return array
*/
public function _fixtures()
{
return [
'user' => [
'class' => UserFixture::className(),
'dataFile' => codecept_data_dir() . 'login_data.php'
]
];
}
/**
* @param FunctionalTester $I
*/
public function loginUser(FunctionalTester $I)
{
$I->amOnPage('/site/login');
$I->fillField('Username', 'erau');
$I->fillField('Password', 'password_0');
$I->click('login-button');
$I->see('Logout (erau)', 'form button[type=submit]');
$I->dontSeeLink('Login');
$I->dontSeeLink('Signup');
}
}
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Cests.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Cests
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/
\ No newline at end of file
class_name: UnitTester
<?php
/**
* Here you can initialize variables via \Codeception\Util\Fixtures class
* to store data in global array and use it in Tests.
*
* ```php
* // Here _bootstrap.php
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
* ```
*
* In Tests
*
* ```php
* \Codeception\Util\Fixtures::get('user1');
* ```
*/
/index-test.php
/robots.txt
/upload
\ No newline at end of file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-5-3
* Time: 下午12:53
*/
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require __DIR__ . '/../../vendor/autoload.php';
require __DIR__ . '/../../vendor/yiisoft/yii2/Yii.php';
require __DIR__ . '/../../common/config/bootstrap.php';
$config = yii\helpers\ArrayHelper::merge(
require __DIR__ . '/../../common/config/main.php',
require __DIR__ . '/../../common/config/main-local.php',
require __DIR__ . '/../config/main.php',
require __DIR__ . '/../config/main-local.php'
);
(new yii\web\Application($config))->run();
\ No newline at end of file
/**
* 自定义刷新提示
*/
var whenShowLoading=null;
var showMyLoading=function () {
if (typeof(layer) === 'object' && whenShowLoading === null) {
whenShowLoading = layer.load(2, {shade: false});
}
return true;
};
var hideMyLoading=function () {
if (typeof(layer) === 'object' && whenShowLoading !== null) {
layer.close(whenShowLoading);
whenShowLoading = null;
}
return true;
};
/**
* Bootstrap Table Chinese translation
*/
(function ($) {
'use strict';
$.fn.bootstrapTable.locales['zh-CN'] = {
contentType: "application/x-www-form-urlencoded",
striped: true, //设置为 true 会有隔行变色效果
cache: false, //设置为 false 禁用 AJAX 数据缓存
silent: true, //静默刷新方式 refresh {silent: true}
dataType: "json", //服务器返回的数据类型
queryParamsType:'', //queryParams {pageSize, pageNumber, searchText, sortName, sortOrder}
undefinedText: '', //当数据为 undefined 时显示的字符
sidePagination: "server", //服务器分页
pagination: true, //设置为 true 会在表格底部显示分页条
paginationLoop: false, //设置为 true 启用分页条无限循环的功能
/*fixedColumns: true,
fixedNumber: 2,*/
paginationPreText: '上一页',
paginationNextText: '下一页',
ajaxOptions: function () {
if (typeof(request_token) === 'string') {
return {
headers: {"Authorization": 'Bearer ' + request_token}
};
} else {
return {};
}
},
formatLoadingMessage: function () {
return '';
},
formatRecordsPerPage: function (pageNumber) {
return '';//'每页显示 ' + pageNumber + ' 条记录';
},
formatShowingRows: function (pageFrom, pageTo, totalRows) {
return '<span style="font-size: 11px">第 <b>'+pageFrom+'</b>-<b>'+pageTo+'</b> 条,共 <b>'+totalRows+'</b> 条数据. </span>';
//return '显示第 ' + pageFrom + ' 到第 ' + pageTo + ' 条记录,总共 ' + totalRows + ' 条记录';
},
formatSearch: function () {
return '搜索';
},
formatNoMatches: function () {
return '<span style="color: #9e9e9e">没有找到匹配的记录</span>';
},
formatPaginationSwitch: function () {
return '隐藏/显示分页';
},
formatRefresh: function () {
return '刷新';
},
formatToggle: function () {
return '切换';
},
formatColumns: function () {
return '列';
},
formatExport: function () {
return '导出';
},
formatClearFilters: function () {
return '清空过滤';
},
onLoadSuccess: function () {
return hideMyLoading();
},
onLoadError: function () {
return hideMyLoading();
},
onRefresh: function () {
return showMyLoading();
},
onPageChange: function () {
return showMyLoading();
}
};
$.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales['zh-CN']);
})(jQuery);
\ 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