Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
56dcefed
Commit
56dcefed
authored
Apr 14, 2021
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix
parent
343e2798
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
129 additions
and
2 deletions
+129
-2
PlatformCoinsController.php
api/controllers/PlatformCoinsController.php
+42
-2
Tools.php
common/components/Tools.php
+29
-0
CoinAddress.php
common/models/psources/CoinAddress.php
+58
-0
No files found.
api/controllers/PlatformCoinsController.php
View file @
56dcefed
...
@@ -2,10 +2,12 @@
...
@@ -2,10 +2,12 @@
namespace
api\controllers
;
namespace
api\controllers
;
use
common\components\Tools
;
use
Yii
;
use
api\base\BaseController
;
use
api\base\BaseController
;
use
common\models\psources\CoinA
irDropTransfer
;
use
common\models\psources\CoinA
ddress
;
use
common\models\psources\CoinPlatformCoins
;
use
common\models\psources\CoinPlatformCoins
;
use
Yii
;
use
common\models\psources\CoinAirDropTransfer
;
class
PlatformCoinsController
extends
BaseController
class
PlatformCoinsController
extends
BaseController
{
{
...
@@ -164,4 +166,41 @@ class PlatformCoinsController extends BaseController
...
@@ -164,4 +166,41 @@ class PlatformCoinsController extends BaseController
return
[
'code'
=>
0
,
'data'
=>
null
,
'msg'
=>
'数据导入成功'
];
return
[
'code'
=>
0
,
'data'
=>
null
,
'msg'
=>
'数据导入成功'
];
}
}
public
function
actionRelation
()
{
$data
=
Yii
::
$app
->
request
->
post
();
if
(
empty
(
$data
))
{
$this
->
code
=
-
1
;
$this
->
msg
=
'参数错误'
;
goto
doEnd
;
}
$item_array
=
[];
foreach
(
$data
as
$val
)
{
$address
=
$val
[
'address'
]
??
null
;
$mobile
=
$val
[
'mobile'
]
??
null
;
if
(
empty
(
$address
)
||
empty
(
$mobile
))
continue
;
$count
=
CoinAddress
::
find
()
->
where
([
'address'
=>
$address
,
'mobile'
=>
$mobile
])
->
count
();
if
(
$count
>
0
)
continue
;
$item_array
[]
=
[
$address
,
$mobile
,
];
}
if
(
empty
(
$item_array
))
{
goto
doEnd
;
}
$result
=
CoinAddress
::
batchImport
(
Tools
::
super_unique
(
$item_array
));
if
(
!
$result
)
{
$this
->
code
=
-
1
;
$this
->
msg
=
'数据导入失败'
;
goto
doEnd
;
}
doEnd
:
return
[
'code'
=>
$this
->
code
,
'data'
=>
$this
->
data
,
'msg'
=>
$this
->
msg
];
}
}
}
\ No newline at end of file
common/components/Tools.php
View file @
56dcefed
...
@@ -157,6 +157,35 @@ class Tools
...
@@ -157,6 +157,35 @@ class Tools
return
$array
;
return
$array
;
}
}
public
static
function
assoc_unique
(
$arr
,
$key
)
{
$tmp_arr
=
array
();
foreach
(
$arr
as
$k
=>
$v
)
{
if
(
in_array
(
$v
[
$key
],
$tmp_arr
))
{
unset
(
$arr
[
$k
]);
}
else
{
$tmp_arr
[]
=
$v
[
$key
];
}
}
$arr
=
array_values
(
$arr
);
//sort函数对数组进行排序
return
$arr
;
}
public
static
function
super_unique
(
$array
,
$recursion
=
false
)
{
// 序列化数组元素,去除重复
$result
=
array_map
(
'unserialize'
,
array_unique
(
array_map
(
'serialize'
,
$array
)));
// 递归调用
if
(
$recursion
)
{
foreach
(
$result
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
{
$result
[
$key
]
=
super_unique
(
$value
);
}
}
}
return
$result
;
}
public
static
function
getDatesFromRange
(
$start
,
$end
,
$format
=
'Y-m-d'
)
public
static
function
getDatesFromRange
(
$start
,
$end
,
$format
=
'Y-m-d'
)
{
{
// Declare an empty array
// Declare an empty array
...
...
common/models/psources/CoinAddress.php
0 → 100644
View file @
56dcefed
<?php
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
CoinAddress
extends
BaseActiveRecord
{
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_address}}'
;
}
public
function
rules
()
{
return
[
[[
'address'
,
'mobile'
],
'required'
],
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'address'
,
'mobile'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
/**
* 导入数据
*
* @param array $datas
* @return boolean
*/
public
static
function
batchImport
(
array
$datas
)
{
if
(
!
is_array
(
$datas
))
{
return
false
;
}
try
{
$result
=
self
::
getDb
()
->
createCommand
()
->
batchInsert
(
self
::
tableName
(),
[
'address'
,
'mobile'
],
$datas
)
->
execute
();
return
$result
;
}
catch
(
\Exception
$e
)
{
var_dump
(
$e
->
getMessage
());
exit
;
}
return
false
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment