Commit 5e1d66cf authored by shajiaiming's avatar shajiaiming

优化币种搜索条件

parent 1ad2d8a6
...@@ -301,7 +301,7 @@ class CoinController extends BaseController ...@@ -301,7 +301,7 @@ class CoinController extends BaseController
$query = Coin::find() $query = Coin::find()
->select('id, sid, icon, name, optional_name, nickname, platform, chain, address as contract_address, treaty') ->select('id, sid, icon, name, optional_name, nickname, platform, chain, address as contract_address, treaty')
->where(['>', "find_in_set($platform_id, platform_id)", 0]) ->where("JSON_CONTAINS(platform_id,'$platform_id')")
->orderBy('id'); ->orderBy('id');
if (false != $chain) { if (false != $chain) {
...@@ -355,13 +355,7 @@ class CoinController extends BaseController ...@@ -355,13 +355,7 @@ class CoinController extends BaseController
$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) { if ($platform_ids) {
/* $platform_id_arr = explode(',', $platform_ids); $condition[] = ("JSON_CONTAINS(platform_id,'$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];
} }
$result = ExchangeBusiness::SearchByName($page, $limit, $condition); $result = ExchangeBusiness::SearchByName($page, $limit, $condition);
......
...@@ -51,7 +51,7 @@ class WalletCoinController extends BaseController ...@@ -51,7 +51,7 @@ class WalletCoinController extends BaseController
if (is_array($val)) { if (is_array($val)) {
$model = WalletCoin::find()->select('id,icon,name,nickname,optional_name,introduce,platform,chain,address as contract_address,treaty') $model = WalletCoin::find()->select('id,icon,name,nickname,optional_name,introduce,platform,chain,address as contract_address,treaty')
->where(['name' => $val[0], 'platform' => $val[1]]) ->where(['name' => $val[0], 'platform' => $val[1]])
->andWhere(['>', "find_in_set($platform_id, platform_id)", 0]) ->andWhere("JSON_CONTAINS(platform_id,'$platform_id')")
->asArray() ->asArray()
->one(); ->one();
} }
...@@ -59,7 +59,7 @@ class WalletCoinController extends BaseController ...@@ -59,7 +59,7 @@ class WalletCoinController extends BaseController
if (is_string($val)) { if (is_string($val)) {
$model = WalletCoin::find()->select('id,icon,name,nickname,optional_name,introduce,platform,chain,address as contract_address,treaty') $model = WalletCoin::find()->select('id,icon,name,nickname,optional_name,introduce,platform,chain,address as contract_address,treaty')
->where(['name' => $val]) ->where(['name' => $val])
->andWhere(['>', "find_in_set($platform_id, platform_id)", 0]) ->andWhere("JSON_CONTAINS(platform_id,'$platform_id')")
->asArray() ->asArray()
->one(); ->one();
} }
...@@ -134,7 +134,7 @@ class WalletCoinController extends BaseController ...@@ -134,7 +134,7 @@ class WalletCoinController extends BaseController
$query = WalletCoin::find() $query = WalletCoin::find()
->select('id, icon, name, nickname, platform, chain, address as contract_address, treaty') ->select('id, icon, name, nickname, platform, chain, address as contract_address, treaty')
->where(['>', "find_in_set($platform_id, platform_id)", 0]) ->where("JSON_CONTAINS(platform_id,'$platform_id')")
->orderBy('id'); ->orderBy('id');
if (false != $chain) { if (false != $chain) {
...@@ -186,7 +186,7 @@ class WalletCoinController extends BaseController ...@@ -186,7 +186,7 @@ class WalletCoinController extends BaseController
} }
$this->data = WalletCoin::find() $this->data = WalletCoin::find()
->where(['id' => $id]) ->where(['id' => $id])
->andWhere(['>', "find_in_set($platform_id, platform_id)", 0]) ->andWhere("JSON_CONTAINS(platform_id,'$platform_id')")
->one(); ->one();
if (empty($this->data)) { if (empty($this->data)) {
goto doEnd; goto doEnd;
......
...@@ -53,7 +53,7 @@ class CoinController extends BaseController ...@@ -53,7 +53,7 @@ class CoinController extends BaseController
} }
if (Yii::$app->user->id != Yii::$app->params['admin']) { if (Yii::$app->user->id != Yii::$app->params['admin']) {
$platform_id = Yii::$app->user->identity->platform_id; $platform_id = Yii::$app->user->identity->platform_id;
$condition[] = ['>', "find_in_set($platform_id, platform_id)", 0]; $condition[] = ("JSON_CONTAINS(platform_id,'$platform_id')");
} }
if (!empty($recommend)) { if (!empty($recommend)) {
//使用连表查询推荐币种 //使用连表查询推荐币种
...@@ -156,7 +156,7 @@ class CoinController extends BaseController ...@@ -156,7 +156,7 @@ class CoinController extends BaseController
$can = false; $can = false;
if (Yii::$app->params['admin'] != Yii::$app->user->id) { if (Yii::$app->params['admin'] != Yii::$app->user->id) {
$coin = Coin::find()->where(['id' => $req->post('id')])->andWhere(['>', "find_in_set($platform_id, platform_id)", 0])->createCommand()->getRawSql(); $coin = Coin::find()->where(['id' => $req->post('id')])->andWhere("JSON_CONTAINS(platform_id,'$platform_id')");
if ($coin) { if ($coin) {
$can = true; $can = true;
} }
...@@ -325,7 +325,7 @@ class CoinController extends BaseController ...@@ -325,7 +325,7 @@ class CoinController extends BaseController
} }
if ($platform_id) { if ($platform_id) {
$condition[] = ['>', "find_in_set($platform_id, platform_id)", 0]; $condition[] = ("JSON_CONTAINS(platform_id,'$platform_id')");
} }
$data = Coin::getSelectList($page, $limit, ['id', 'name', 'nickname', 'platform', 'chain'], $condition); $data = Coin::getSelectList($page, $limit, ['id', 'name', 'nickname', 'platform', 'chain'], $condition);
......
...@@ -170,7 +170,7 @@ class Coin extends BaseActiveRecord ...@@ -170,7 +170,7 @@ class Coin extends BaseActiveRecord
if (!ctype_alnum($id)) { if (!ctype_alnum($id)) {
return false; return false;
} }
$query = self::find()->andWhere(['>', "find_in_set($id, platform_id)", 0]); $query = self::find()->andWhere("JSON_CONTAINS(platform_id,'$id')");
$count = $query->count(); $count = $query->count();
if ($count) { if ($count) {
$data = $query->limit($limit)->offset(($page - 1) * $limit)->asArray()->all(); $data = $query->limit($limit)->offset(($page - 1) * $limit)->asArray()->all();
......
...@@ -19,7 +19,7 @@ class CoinRelationController extends BaseController ...@@ -19,7 +19,7 @@ class CoinRelationController extends BaseController
$platform_id = \Yii::$app->request->get('platform_id', ''); $platform_id = \Yii::$app->request->get('platform_id', '');
$query = WalletCoin::find() $query = WalletCoin::find()
->select('id, name, nickname, icon, introduce, official, paper, platform, chain, release, area_search, publish_count, circulate_count, decimals, address, treaty, platform_id') ->select('id, name, nickname, icon, introduce, official, paper, platform, chain, release, area_search, publish_count, circulate_count, decimals, address, treaty, platform_id')
->where(['>', "find_in_set($platform_id, platform_id)", 0]); ->where("JSON_CONTAINS(platform_id,'$platform_id')");
if (false != $name) { if (false != $name) {
$query->andWhere(['name' => $name]); $query->andWhere(['name' => $name]);
} }
......
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