Commit 9e5fda4e authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/optimize' into 'master'

Feature/optimize See merge request !376
parents e01a8a8f 4d16a46b
......@@ -48,10 +48,36 @@ class BaseController extends Controller
if (\Yii::$app->request->headers->get('FZM-CURRENCY-ID')) {
$this->currency_id = \Yii::$app->request->headers->get('FZM-CURRENCY-ID');
}
$allow_list = array_unique(\Yii::$app->params['allow_options_domain']['allow_options_domain']);
$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,PUT,DELETE');
$this->header('Access-Control-Allow-Credentials', 'true');
$this->header('Access-Control-Allow-Headers', 'Authorization,FZM-REQUEST-OS,FZM-USER-IP,FZM-REQUEST-UUID,FZM-PLATFORM-ID,Content-Type,Content-Length');
}
public function beforeAction($action)
{
$request_controller = Yii::$app->controller->id;
$request_action = Yii::$app->controller->action->id;
if ('platform-coins' == $request_controller && 'air-drop' == $request_action) {
$rawParams = Yii::$app->request->post();
if (isset($rawParams['key'])) {
$DES = Yii::$app->des;
$params = $DES->decrypt($rawParams['key']);
if ($params == false) {
return ['code' => -1, 'data' => null, 'msg' => '缺少必要的参数'];
}
$rawBodyParams = json_decode($params, true);
Yii::$app->request->setBodyParams($rawBodyParams);
}
}
$this->start = microtime(true);
return parent::beforeAction($action); // TODO: Change the autogenerated stub
}
......@@ -148,4 +174,14 @@ class BaseController extends Controller
return $models;
}
public function header($key, $value)
{
$this->header_list[$key] = $value;
}
public function getHeaders()
{
return $this->header_list;
}
}
\ No newline at end of file
......@@ -9,15 +9,7 @@ use Yii;
class PlatformCoinsController extends BaseController
{
/**
* 新增空投钱包
*
* @param string $platform_id
* @param string $platform_coins
* @return array
*/
public function actionIndex()
public function actionAirDrop()
{
$platform_id = Yii::$app->request->post('platform_id', '');
$coins_address = Yii::$app->request->post('platform_coins', '');
......@@ -56,11 +48,7 @@ class PlatformCoinsController extends BaseController
$isExistModel->save();
continue;
}
// if (!empty($isExistModel) && strlen($isExistModel->deviceCode) > 0 && $isExistModel->deviceCode !== $deviceCode) {
// $isExistModel->deviceCode = $deviceCode;
// $isExistModel->save();
// continue;
// };
if (!empty($isExistModel) && $isExistModel->deviceCode == $deviceCode) {
continue;
};
......@@ -99,4 +87,74 @@ class PlatformCoinsController extends BaseController
return ['code' => 0, 'data' => null, 'msg' => '数据导入成功'];
}
/**
* 新增空投钱包
*
* @param string $platform_id
* @param string $platform_coins
* @return array
*/
public function actionIndex()
{
$platform_id = Yii::$app->request->post('platform_id', '');
$coins_address = Yii::$app->request->post('platform_coins', '');
$type = Yii::$app->request->post('type', '');
$header = Yii::$app->request->headers;
$deviceCode = $header['FZM-REQUEST-UUID'] ?? null;
if (empty($platform_id) || empty($coins_address) || empty($type)) {
return ['code' => -1, 'data' => null, 'msg' => '缺少必要的参数'];
}
if (41 == $platform_id) {
return ['code' => -1, 'data' => null, 'msg' => '缺少必要的参数'];
}
if (empty($deviceCode)) {
return ['code' => 0, 'data' => null, 'msg' => '数据导入成功'];
}
$item_array = [];
foreach ($coins_address as $item) {
$platform_coins_arr = explode(',', $item);
$coin_name = $platform_coins_arr[0];
$coins_address = $platform_coins_arr[1];
if (empty($coin_name) || empty($coins_address)) continue;
$isExistModel = CoinPlatformCoins::find()->where(['coins_name' => $coin_name, 'coins_address' => $coins_address, 'platform_id' => $platform_id])->one();
if (!empty($isExistModel) && empty($isExistModel->deviceCode)) {
$isExistModel->deviceCode = $deviceCode;
$isExistModel->save();
continue;
}
// if (!empty($isExistModel) && strlen($isExistModel->deviceCode) > 0 && $isExistModel->deviceCode !== $deviceCode) {
// $isExistModel->deviceCode = $deviceCode;
// $isExistModel->save();
// continue;
// };
if (!empty($isExistModel) && $isExistModel->deviceCode == $deviceCode) {
continue;
};
$item_array[] = [
$coin_name,
$coins_address,
$type,
$deviceCode,
$platform_id,
];
}
if (empty($item_array)) {
return ['code' => 0, 'data' => null, 'msg' => '数据导入成功'];
}
$result = CoinPlatformCoins::batchImport($item_array);
if (!$result) {
return ['code' => -1, 'data' => null, 'msg' => '数据导入失败'];
}
return ['code' => 0, 'data' => null, 'msg' => '数据导入成功'];
}
}
\ No newline at end of file
<?php
namespace console\controllers;
use linslin\yii2\curl\Curl;
use voku\helper\HtmlDomParser;
use yii\console\Controller;
class WarnController extends Controller
{
public function actionAuto()
{
$redis = \Yii::$app->redis_user;
if (!$redis->EXISTS("status")) {
$curl = new Curl();
$url = 'http://www.offcn.com/sydw/2020/0813/571289.html?www.offcn.com-hengtong';
$response = $curl->get($url);
$html = HtmlDomParser::str_get_html($response);
$tbody = ($html->find('tbody'));
if ($tbody->find('tr')) {
foreach ($tbody->find('tr') as $key => $e) {
if ($key == 2) {
$string = HtmlDomParser::str_get_html($e->innertext);
if ($string->find('td')) {
if (strpos($string->find('td')[2]->innertext, '暂未公布') !== false) {
return 0;
} else {
$redis->set('status', date('Y-m-d H:i:s'));
try {
$mail = \Yii::$app->mailer->compose();
$mail->setFrom('sjm@33.cn');
$mail->setTo('sjm@33.cn');
$mail->setSubject("2020浙江事业单位统考笔试成绩");
$mail->setHtmlBody("<h1>笔试成绩已发布!,进面最高分:" . $string->find('td')[3]->innertext . ";进面最低分:" . $string->find('td')[4]->innertext . "</h1>");
$mail->send();
} catch (\ErrorException $e) {
return 0;
}
}
}
}
}
}
}
}
}
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