Commit 57f76bcd authored by shajiaiming's avatar shajiaiming

api request header

parent 5d981bc1
......@@ -30,7 +30,7 @@ class BaseController extends Controller
public function fzmCrossHeader()
{
$this->lang = \Yii::$app->request->headers->get('lang') ?? 'zh';
$this->lang = \Yii::$app->request->headers->get('lang') ?? 'zh-CN';
}
public function beforeAction($action)
......
......@@ -39,7 +39,12 @@ class CoinController extends BaseController
if ($id) {
$ret = CoinBusiness::getCoinAllById($id);
if ($ret) {
return $ret[0];
$data = $ret[0];
$nickname = json_decode($data['nickname'], true);
$introduce = json_decode($data['introduce'], true);
$data['nickname'] = $nickname[$this->lang];
$data['introduce'] = $introduce[$this->lang];
return $data;
}
}
return [];
......@@ -134,6 +139,10 @@ class CoinController extends BaseController
$coin_ids = array_column($coin_recommends, 'cid');
//获取币种信息
$coin_infos = Coin::getCoinInfoByIds($coin_ids, $select, 'id');
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'));
......@@ -231,6 +240,8 @@ class CoinController extends BaseController
$chain_quotation[$value] = ExchangeBusiness::getquatation($value);
}
foreach ($result['data'] as $key => &$value) {
$nickname = json_decode($value['nickname'], true);
$value['nickname'] = $nickname[$this->lang];
$value['chain_quotation'] = $chain_quotation[$value['chain']] ?: null;
}
return $result;
......@@ -279,6 +290,10 @@ class CoinController extends BaseController
foreach ($result as $key => $value) {
$result[$key]['chain_quotation'] = $chain_quotation[$value['chain']] ?: null;
}
foreach ($result as $key => &$value) {
$nickname = json_decode($value['nickname'], true);
$value['nickname'] = $nickname[$this->lang];
}
return ['code' => 0, 'count' => $total, 'data' => $result];
}
}
......
......@@ -92,6 +92,24 @@ class CoinController extends BaseController
$data['name'] = strtoupper($data['name']);
$data['platform'] = strtolower($data['platform']);
$data['chain'] = strtoupper($data['chain']);
$lang = [
'zh-CN',
'en-US',
'ja'
];
$nickname_arr = $data['nickname'];
$introduce_arr = $data['introduce'];
$nickname = [];
$introduce = [];
foreach ($nickname_arr as $key => $val){
$nickname[$lang[$key]] = $val;
}
foreach ($introduce_arr as $key => $val){
$introduce[$lang[$key]] = $val;
}
unset($data['nickname']);
$data['nickname'] = $nickname;
$data['introduce'] = $introduce;
$result = $coin->addOne($data);
if ($result === true) {
$this->success('添加成功', '/admin/coin/index');
......@@ -142,6 +160,24 @@ class CoinController extends BaseController
$can = true;
}
if ($can) {
$lang = [
'zh-CN',
'en-US',
'ja'
];
$nickname_arr = $data['nickname'];
$introduce_arr = $data['introduce'];
$nickname = [];
$introduce = [];
foreach ($nickname_arr as $key => $val){
$nickname[$lang[$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());
$result = $coin->updateOne($data);
if ($result === true) {
......
......@@ -25,8 +25,20 @@
</div>
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block">
<input class="layui-input" name="nickname" value="<?= $model->nickname ?>">
<div class="layui-input-block" style="width: 250px">
<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">
<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">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['ja'] ?>">
</div>
</div>
<div class="layui-form-item">
......@@ -113,9 +125,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">
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['zh-CN'] ?></textarea>
</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['en-US'] ?></textarea>
</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>
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['ja'] ?></textarea>
</div>
</div>
<div class="layui-inline">
......
......@@ -25,8 +25,20 @@
</div>
<div class="layui-inline">
<label class="layui-form-label">中文名</label>
<div class="layui-input-block">
<input class="layui-input" name="nickname" value="<?= $model->nickname ?>">
<div class="layui-input-block" style="width: 250px">
<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">
<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">
<input class="layui-input" name="nickname[]" value="<?= $model->nickname['ja'] ?>">
</div>
</div>
<div class="layui-form-item">
......@@ -117,9 +129,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">
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['zh-CN'] ?></textarea>
</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['en-US'] ?></textarea>
</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>
<textarea class="layui-textarea" name="introduce[]"><?= $model->introduce['ja'] ?></textarea>
</div>
</div>
<div class="layui-inline">
......
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