| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace backend\modules\user\controllers;
- use backend\models\MemberIdentity;
- use backend\models\Mt4tradeApi;
- use Yii;
- class DashboardController extends BaseController
- {
- /**
- * @return string
- */
- public function actionIndex()
- {
- /** @var MemberIdentity $identity */
- $identity = Yii::$app->getUser()->getIdentity(false);
- $login = Yii::$app->getRequest()->get('login');
- if ($login != null) {
- // 切换mt4账号
- $identity->switchMt4user($login);
- }
- $api = new Mt4tradeApi();
- $result = $api->getHistoryTotalCount($identity->getMain_login());
- $historyTotalCount = isset($result['data']) ? intval($result['data']) : 0;
- $result = $api->getHistoryWinCount($identity->getMain_login());
- $historyWinCount = isset($result['data']) ? intval($result['data']) : 0;
- $result = $api->getHistoryLossCount($identity->getMain_login());
- $historyLossCount = isset($result['data']) ? intval($result['data']) : 0;
- $historyWinPercent = $historyTotalCount == 0 ? 0 : round($historyWinCount / $historyTotalCount * 100, 5);
- $historyLossPercent = $historyTotalCount == 0 ? 0 : round($historyLossCount / $historyTotalCount * 100, 5);
- $result = $api->sumProfitByDay($identity->getMain_login());
- $sumProfitByDay = isset($result['data']) ? (array)$result['data'] : [];
- $result = $api->volumeSumByDay($identity->getMain_login());
- $volumeSumByDay = isset($result['data']) ? (array) $result['data'] : [];
- $result = $api->symbolCount($identity->getMain_login());
- $symbolCount = isset($result['data']) ? (array) $result['data'] : [];
- $result = $api->reasonCount($identity->getMain_login());
- $reasonCount = isset($result['data']) ? (array) $result['data'] : [];
-
- // 交易手数
- foreach ($volumeSumByDay as $k => $v) {
- $volumeSumByDay[$k][1] = number_format($v[1] / 100, 2, '.', '');
- }
- // 交易货币分布
- $symbolCount2 = [];
- foreach ($symbolCount as $k => $v) {
- $symbolCount2[$k]['label'] = $v['SYMBOL'];
- $symbolCount2[$k]['data'] = $v['cnt'];
- }
- // 交易来源分布
- $reasonCount2 = [];
- foreach ($reasonCount as $k => $v) {
- $reasonCount2[$k]['label'] = $v['REASON'];
- $reasonCount2[$k]['data'] = $v['cnt'];
- }
- return $this->render('index', [
- 'historyTotalCount' => $historyTotalCount,
- 'historyWinCount' => $historyWinCount,
- 'historyLossCount' => $historyLossCount,
- 'historyWinPercent' => $historyWinPercent,
- 'historyLossPercent' => $historyLossPercent,
- 'sumProfitByDay' => json_encode($sumProfitByDay),
- 'volumeSumByDay' => json_encode($volumeSumByDay),
- 'symbolCount' => json_encode($symbolCount2),
- 'reasonCount' => json_encode($reasonCount2),
- ]);
- }
- }
|