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
10d8c5b2
Commit
10d8c5b2
authored
Oct 26, 2019
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
订单相关接口
parent
1c9462b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
194 additions
and
0 deletions
+194
-0
OrderController.php
api/controllers/OrderController.php
+148
-0
CoinCTocTransfer.php
common/models/psources/CoinCTocTransfer.php
+46
-0
No files found.
api/controllers/OrderController.php
0 → 100644
View file @
10d8c5b2
<?php
namespace
api\controllers
;
use
Yii
;
use
yii\data\Pagination
;
use
api\base\BaseController
;
use
common\models\psources\CoinCTocTransfer
;
class
OrderController
extends
BaseController
{
public
function
actionIndex
()
{
$code
=
-
1
;
$request
=
Yii
::
$app
->
request
;
if
(
!
$request
->
isPost
)
{
$msg
=
'请求错误!'
;
goto
doEnd
;
}
$post
=
$request
->
post
();
if
(
2
!=
count
(
$post
[
'txs'
]))
{
$msg
=
'交易笔数错误!'
;
goto
doEnd
;
}
$data
[
'is_sell'
]
=
(
false
==
$post
[
'isSell'
])
?
0
:
1
;
$data
[
'type'
]
=
$post
[
'type'
];
$data
[
'address'
]
=
$post
[
'address'
];
$data
[
'token_name'
]
=
$post
[
'token_name'
];
$data
[
'market_name'
]
=
$post
[
'market_name'
];
$data
[
'price'
]
=
$post
[
'price'
];
$data
[
'amount'
]
=
$post
[
'amount'
];
$data
[
'transfer_number'
]
=
date
(
'YmdHis'
)
.
self
::
getrandnums
();
$redis
=
Yii
::
$app
->
redis
;
if
(
$redis
->
exists
(
'C2C_'
.
$post
[
'address'
]
.
'_'
.
$data
[
'is_sell'
]))
{
$msg
=
'尚存在一笔未完成的交易!'
;
goto
doEnd
;
}
$redis
->
set
(
'C2C_'
.
$post
[
'address'
]
.
'_'
.
$data
[
'is_sell'
],
time
());
foreach
(
$post
[
'txs'
]
as
$key
=>
$val
)
{
$model
=
new
CoinCTocTransfer
();
$data
[
'txhex'
]
=
$val
[
'tx'
];
$data
[
'transfer_url'
]
=
$val
[
'url'
];
$data
[
'step'
]
=
$val
[
'step'
];
$model
->
load
(
$data
,
''
);
$model
->
save
();
}
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
public
function
actionFixOrder
()
{
$code
=
-
1
;
$request
=
Yii
::
$app
->
request
;
if
(
!
$request
->
isPost
)
{
$msg
=
'请求错误!'
;
goto
doEnd
;
}
$post
=
$request
->
post
();
$data
[
'is_sell'
]
=
(
false
==
$post
[
'isSell'
])
?
0
:
1
;
$data
[
'type'
]
=
$post
[
'type'
];
$data
[
'address'
]
=
$post
[
'address'
];
foreach
(
$post
[
'txs'
]
as
$key
=>
$val
)
{
$model
=
CoinCTocTransfer
::
find
()
->
where
([
'is_sell'
=>
$data
[
'is_sell'
]])
->
andWhere
([
'type'
=>
$data
[
'type'
]])
->
andWhere
([
'address'
=>
$data
[
'address'
]])
->
andWhere
([
'step'
=>
$val
[
'step'
]])
->
andWhere
([
'<>'
,
'msg'
,
'success'
])
->
one
();
$model
->
txhex
=
$val
[
'tx'
];
$model
->
transfer_url
=
$val
[
'url'
];
$model
->
send_result
=
0
;
$model
->
query_result
=
0
;
$model
->
msg
=
0
;
$model
->
save
();
continue
;
}
$redis
=
Yii
::
$app
->
redis
;
$redis
->
set
(
'C2C_'
.
$post
[
'address'
]
.
'_'
.
$data
[
'is_sell'
],
time
());
$code
=
0
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
];
}
public
function
actionOrderList
()
{
$address
=
Yii
::
$app
->
request
->
get
(
'address'
,
''
);
$is_sell
=
Yii
::
$app
->
request
->
get
(
'isSell'
,
-
1
);
$type
=
Yii
::
$app
->
request
->
get
(
'type'
,
''
);
$page
=
Yii
::
$app
->
request
->
get
(
'page'
,
1
);
if
(
empty
(
$address
)){
$msg
=
'请求参数错误'
;
$code
=
-
1
;
$data
=
null
;
goto
doEnd
;
}
$query
=
CoinCTocTransfer
::
find
()
->
where
(
'address= :address'
,[
':address'
=>
$address
])
->
orderBy
(
'create_time desc'
)
->
groupBy
(
'address, is_sell'
);
if
(
$is_sell
>
-
1
)
{
$query
->
andWhere
(
'is_sell= :is_sell'
,[
':is_sell'
=>
$is_sell
]);
}
if
(
false
!=
$type
)
{
$query
->
andWhere
(
'type= :type'
,[
':type'
=>
$type
]);
}
$data
=
$query
->
offset
((
$page
-
1
)
*
20
)
->
limit
(
20
)
->
asArray
()
->
all
();
$countQuery
=
clone
$query
;
$pages
=
new
Pagination
([
'totalCount'
=>
$countQuery
->
count
(),
'pageSize'
=>
20
]);
$data
=
[
'list'
=>
$data
,
'page'
=>
[
'pageCount'
=>
$pages
->
pageCount
,
'pageSize'
=>
20
,
'currentPage'
=>
$page
,
]
];
$code
=
1
;
$msg
=
'success'
;
doEnd
:
return
[
'code'
=>
$code
,
'msg'
=>
$msg
,
'data'
=>
$data
];
}
public
static
function
getrandnums
()
{
$arr
=
array
();
while
(
count
(
$arr
)
<
6
)
{
$arr
[]
=
rand
(
0
,
9
);
$arr
=
array_unique
(
$arr
);
}
return
implode
(
""
,
$arr
);
}
}
\ No newline at end of file
common/models/psources/CoinCTocTransfer.php
0 → 100644
View file @
10d8c5b2
<?php
namespace
common\models\psources
;
use
Yii
;
use
common\core\BaseActiveRecord
;
class
CoinCTocTransfer
extends
BaseActiveRecord
{
const
TYPE_SELL
=
1
;
//卖单
const
TYPE_BUY
=
0
;
//买单
const
TYPE_ORDER
=
1
;
//挂单
const
TYPE_TRANSFER
=
2
;
//交易
const
TYPE_REVOKE
=
3
;
//撤消
public
static
function
getDb
()
{
return
Yii
::
$app
->
get
(
'p_sources'
);
}
public
static
function
tableName
()
{
return
'{{%coin_ctoc_transfer}}'
;
}
//定义场景
const
SCENARIOS_CREATE
=
'create'
;
public
function
rules
()
{
return
[
[[
'is_sell'
,
'type'
,
'address'
,
'token_name'
,
'market_name'
,
'price'
,
'amount'
,
'step'
,
'txhex'
,
'transfer_url'
,
'transfer_number'
],
'required'
],
[[
'send_result'
,
'query_result'
,
'msg'
],
'safe'
]
];
}
public
function
scenarios
()
{
$scenarios
=
[
self
::
SCENARIOS_CREATE
=>
[
'is_sell'
,
'type'
,
'address'
,
'token_name'
,
'market_name'
,
'price'
,
'amount'
,
'step'
,
'txhex'
,
'transfer_url'
,
'transfer_number'
],
];
return
array_merge
(
parent
::
scenarios
(),
$scenarios
);
}
}
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