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
7f2e58c0
Commit
7f2e58c0
authored
Sep 13, 2018
by
rlgy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
币种库
parent
96a66170
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
363 additions
and
3 deletions
+363
-3
CoinController.php
backend/controllers/CoinController.php
+147
-0
package.php
backend/views/coin/package.php
+213
-0
Coin.php
common/models/psources/Coin.php
+3
-3
No files found.
backend/controllers/CoinController.php
View file @
7f2e58c0
...
...
@@ -11,8 +11,10 @@ namespace backend\controllers;
use
backend\models\coin\CoinForm
;
use
common\business\CoinBusiness
;
use
common\models\psources\Coin
;
use
common\models\psources\CoinPlatform
;
use
Yii
;
use
yii\validators\ImageValidator
;
use
yii\web\Response
;
use
yii\web\UploadedFile
;
/**
...
...
@@ -212,4 +214,149 @@ class CoinController extends BaseController
$this
->
layout
=
false
;
return
$this
->
render
(
'exchange'
,
[
'exchanges'
=>
$exchanges
]);
}
public
function
actionPackage
()
{
$user_platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
if
(
Yii
::
$app
->
request
->
isAjax
)
{
$get
=
Yii
::
$app
->
request
->
get
();
$page
=
$get
[
'page'
]
??
1
;
$limit
=
$get
[
'limit'
]
??
10
;
$name
=
$get
[
'name'
]
??
''
;
$platform
=
$get
[
'platform'
]
??
''
;
$chain
=
$get
[
'chain'
]
??
''
;
$condition
=
[];
if
(
$name
)
{
$condition
[]
=
[
'like'
,
'name'
,
$name
];
}
if
(
$platform
)
{
$condition
[]
=
[
'platform'
=>
$platform
];
}
if
(
$chain
)
{
$condition
[]
=
[
'chain'
=>
$chain
];
}
if
(
Yii
::
$app
->
user
->
id
==
Yii
::
$app
->
params
[
'admin'
])
{
$platform_id
=
$get
[
'platform_id'
]
??
''
;
}
else
{
$platform_id
=
$user_platform_id
;
}
if
(
$platform_id
)
{
$condition
[]
=
[
'>'
,
"find_in_set(
$platform_id
, platform_id)"
,
0
];
}
$data
=
Coin
::
getSelectList
(
$page
,
$limit
,
[
'id'
,
'name'
,
'nickname'
,
'platform'
,
'chain'
],
$condition
);
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
if
(
!
empty
(
$data
))
{
$data
[
'code'
]
=
0
;
}
return
$data
;
}
//获取币种平台
$coin_platforms
=
Coin
::
getPlatformList
();
//获取主链
$chains
=
Coin
::
getChainList
();
if
(
Yii
::
$app
->
user
->
id
==
Yii
::
$app
->
params
[
'admin'
])
{
$platforms
=
CoinPlatform
::
find
()
->
asArray
()
->
all
();
}
else
{
$platforms
=
CoinPlatform
::
find
()
->
where
([
'id'
=>
$user_platform_id
])
->
asArray
()
->
all
();
}
return
$this
->
render
(
'package'
,
[
'platforms'
=>
$platforms
,
'chains'
=>
$chains
,
'coin_platforms'
=>
$coin_platforms
,
]);
}
public
function
actionPackageDel
()
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$id
=
Yii
::
$app
->
request
->
get
(
'id'
,
''
);
$platform_id
=
Yii
::
$app
->
request
->
get
(
'platform_id'
,
''
);
if
(
empty
(
$platform_id
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
'请选择钱包'
];
}
$user_platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
$coin
=
Coin
::
findOne
(
$id
);
if
(
$coin
)
{
$can
=
false
;
$platform_ids
=
explode
(
','
,
$coin
->
platform_id
);
if
(
Yii
::
$app
->
user
->
id
==
Yii
::
$app
->
params
[
'admin'
])
{
$can
=
true
;
}
else
{
if
(
in_array
(
$user_platform_id
,
$platform_ids
)
&&
$platform_id
==
$user_platform_id
)
{
$can
=
true
;
}
}
if
(
$can
)
{
//删除
$platform_ids
=
array_diff
(
$platform_ids
,
[
$platform_id
]);
$platform_ids
=
implode
(
','
,
$platform_ids
);
$coin
->
platform_id
=
$platform_ids
;
if
(
$coin
->
save
())
{
return
[
'code'
=>
0
,
'msg'
=>
'删除成功'
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'删除失败'
];
}
else
{
return
[
'code'
=>
-
1
,
'msg'
=>
'没有权限修改'
];
}
}
else
{
return
[
'code'
=>
-
1
,
'msg'
=>
'币种不存在'
];
}
}
}
public
function
actionPackageAdd
()
{
if
(
Yii
::
$app
->
request
->
isAjax
)
{
Yii
::
$app
->
response
->
format
=
Response
::
FORMAT_JSON
;
$get
=
Yii
::
$app
->
request
->
get
();
$platform_id
=
$get
[
'platform_id'
]
??
''
;
$name
=
$get
[
'name'
]
??
''
;
$chain
=
$get
[
'chain'
]
??
''
;
foreach
([
'platform_id'
=>
'平台'
,
'name'
=>
'币种名称'
,
'chain'
=>
'币种主链'
]
as
$key
=>
$value
)
{
if
(
empty
(
$$key
))
{
return
[
'code'
=>
-
1
,
'msg'
=>
$value
.
'不能为空'
];
}
}
$coin
=
Coin
::
find
()
->
where
([
'name'
=>
$name
,
'chain'
=>
$chain
])
->
One
();
if
(
$coin
)
{
$can
=
false
;
$user_platform_id
=
Yii
::
$app
->
user
->
identity
->
platform_id
;
$platform_ids
=
explode
(
','
,
$coin
->
platform_id
);
if
(
$user_platform_id
==
Yii
::
$app
->
params
[
'admin'
])
{
$can
=
true
;
}
else
{
if
(
in_array
(
$user_platform_id
,
$platform_ids
)
&&
$platform_id
==
$user_platform_id
)
{
$can
=
true
;
}
}
if
(
$can
)
{
$platform_ids
=
implode
(
','
,
array_unique
(
array_merge
(
$platform_ids
,
[
$platform_id
])));
$coin
->
platform_id
=
$platform_ids
;
if
(
$coin
->
save
())
{
return
[
'code'
=>
0
,
'msg'
=>
'添加成功'
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'添加失败'
];
}
return
[
'code'
=>
-
1
,
'msg'
=>
'没有权限修改'
];
}
return
[
'coin'
=>
-
1
,
'msg'
=>
'币种不存在'
];
}
}
}
backend/views/coin/package.php
0 → 100644
View file @
7f2e58c0
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-9-11
* Time: 下午5:45
*/
;
?>
<style
type=
"text/css"
>
.layui-form-label
{
width
:
100px
;
}
</style>
<div
class=
"layui-row"
>
<form
class=
"layui-form"
lay-filter=
"form2"
>
<div
class=
"layui-inline"
>
<div
class=
"layui-input-inline"
>
<select
class=
"layui-select"
name=
"platform_id"
>
<option
value=
""
>
选择一个钱包
</option>
<?php
foreach
(
$platforms
as
$key
=>
$value
)
:
?>
<option
value=
"
<?=
$value
[
'id'
]
?>
"
>
<?=
$value
[
'name'
]
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
<div
class=
"layui-inline"
>
<div
class=
"layui-input-inline"
>
<input
type=
"text"
name=
"name"
placeholder=
"币种名称"
class=
"layui-input"
>
</div>
</div>
<div
class=
"layui-inline"
>
<div
class=
"layui-input-inline"
>
<select
name=
"platform"
class=
"layui-select"
>
<option
value=
""
>
选择币种平台
</option>
<?php
foreach
(
$coin_platforms
as
$key
=>
$value
)
:
?>
<option
value=
"
<?=
strtoupper
(
$value
)
?>
"
>
<?=
strtoupper
(
$value
)
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
<div
class=
"layui-inline"
>
<div
class=
"layui-input-inline"
>
<select
name=
"chain"
class=
"layui-select"
>
<option
value=
""
>
选择币种主链
</option>
<?php
foreach
(
$chains
as
$key
=>
$value
)
:
?>
<option
value=
"
<?=
strtoupper
(
$value
)
?>
"
>
<?=
strtoupper
(
$value
)
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
<div
class=
"layui-inline"
>
<button
class=
"layui-btn layui-btn-normal"
lay-submit
lay-filter=
"search"
>
筛选
</button>
<button
class=
"layui-btn layui-btn-normal"
type=
"reset"
>
重置
</button>
</div>
</form>
</div>
<div
class=
"layui-col-md8"
>
<table
class=
"layui-table"
id=
"table1"
lay-filter=
"table1"
></table>
</div>
<div
style=
"display: none; padding: 5px 5px;"
id=
"_form"
>
<form
class=
"layui-form"
id=
"form1"
lay-filter=
"form1"
>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
币种名称
</label>
<div
class=
"layui-input-block"
>
<input
name=
"name"
class=
"layui-input"
type=
"text"
>
</div>
</div>
<div
class=
"layui-form-item"
>
<label
class=
"layui-form-label"
>
币种主链
</label>
<div
class=
"layui-input-block"
>
<select
name=
"chain"
class=
"layui-select"
lay-ingore
>
<option
value=
""
>
选择币种主链
</option>
<?php
foreach
(
$chains
as
$key
=>
$value
)
:
?>
<option
value=
"
<?=
strtoupper
(
$value
)
?>
"
>
<?=
strtoupper
(
$value
)
?>
</option>
<?php
endforeach
;
?>
</select>
</div>
</div>
</form>
</div>
<script
type=
"text/html"
id=
"toolBar"
>
<
button
class
=
"layui-btn layui-btn-xs layui-btn-danger"
lay
-
event
=
"del"
>
删除
<
/button
>
</script>
<script
type=
"text/html"
id=
"toolBarTop"
>
<
div
class
=
"layui-btn-container"
>
<
button
class
=
"layui-btn layui-btn-sm"
lay
-
event
=
"recommend_add"
>
添加
<
/button
>
<
/div
>
</script>
<script
type=
"text/javascript"
>
var
table
=
layui
.
table
;
table
.
render
({
elem
:
'#table1'
,
toolbar
:
'#toolBarTop'
,
page
:
true
,
limit
:
10
,
url
:
'/admin/coin/package'
,
cols
:
[[
{
field
:
'id'
,
title
:
'ID'
},
{
field
:
'name'
,
title
:
'名称'
},
{
field
:
'nickname'
,
title
:
'别称'
},
{
field
:
'platform'
,
title
:
'平台'
},
{
field
:
'chain'
,
title
:
'主链'
},
{
title
:
'操作'
,
toolbar
:
'#toolBar'
},
]]
});
var
form
=
layui
.
form
;
form
.
render
();
table
.
on
(
'toolbar(table1)'
,
function
(
obj
)
{
var
event
=
obj
.
event
;
if
(
event
==
'recommend_add'
)
{
var
index
=
layer
.
open
({
title
:
'添加推介币种'
,
type
:
1
,
zindex
:
1
,
content
:
$
(
"#_form"
),
btn
:
[
'保存'
,
'取消'
],
scrollbar
:
false
,
success
:
function
(
layero
,
index
)
{
var
platform_id
=
$
(
"select[name='platform_id']"
).
val
();
if
(
platform_id
==
''
)
{
layer
.
close
(
index
);
layer
.
msg
(
'请先选择一个钱包'
);
$
(
"#_form"
).
css
(
'display'
,
'none'
);
}
form
.
val
(
'form1'
,{
name
:
''
,
chain
:
''
});
},
btn1
:
function
()
{
var
data
=
{
name
:
$
(
"#form1 input[name='name'"
).
val
(),
chain
:
$
(
"#form1 select[name='chain']"
).
val
(),
platform_id
:
$
(
"select[name='platform_id']"
).
val
()
};
$
.
get
(
'/admin/coin/package-add'
,
data
,
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
layer
.
close
(
index
);
$
(
"#_form"
).
css
(
'display'
,
'none'
);
table
.
reload
(
'table1'
,
{
page
:
{
curr
:
1
}
});
}
});
},
end
:
function
(){
$
(
"#_form"
).
css
(
'display'
,
'none'
);
}
});
}
});
table
.
on
(
'tool(table1)'
,
function
(
obj
)
{
var
event
=
obj
.
event
;
var
data
=
obj
.
data
;
if
(
'del'
==
event
)
{
var
index
=
layer
.
confirm
(
"确认删除?"
,
{
icon
:
3
,
title
:
'删除'
},
function
()
{
$
.
get
(
'/admin/coin/package-del'
,
{
id
:
data
.
id
,
platform_id
:
$
(
"select[name='platform_id']"
).
val
()
},
function
(
rev
)
{
layer
.
msg
(
rev
.
msg
);
if
(
0
==
rev
.
code
)
{
// layer.close(index);
table
.
reload
(
'table1'
,
{
page
:
{
curr
:
1
}
});
}
});
});
}
});
form
.
on
(
'submit(search)'
,
function
(
obj
)
{
table
.
reload
(
"table1"
,
{
where
:
obj
.
field
,
page
:
{
curr
:
1
}
});
return
false
;
});
</script>
common/models/psources/Coin.php
View file @
7f2e58c0
...
...
@@ -130,7 +130,7 @@ class Coin extends BaseActiveRecord
public
static
function
getPlatformList
()
{
$data
=
self
::
find
()
->
select
(
'platform'
)
->
asArray
()
->
all
();
$data
=
array_unique
(
array_
column
(
$data
,
'platform'
));
$data
=
array_unique
(
array_
map
(
'strtoupper'
,
array_column
(
$data
,
'platform'
)
));
return
$data
;
}
...
...
@@ -141,7 +141,7 @@ class Coin extends BaseActiveRecord
public
static
function
getChainList
()
{
$data
=
self
::
find
()
->
select
(
'chain'
)
->
asArray
()
->
all
();
$data
=
array_unique
(
array_
column
(
$data
,
'chain'
));
$data
=
array_unique
(
array_
map
(
'strtoupper'
,
array_column
(
$data
,
'chain'
)
));
return
$data
;
}
...
...
@@ -208,7 +208,7 @@ class Coin extends BaseActiveRecord
foreach
(
$condition
as
$item
)
{
$query
=
$query
->
andWhere
(
$item
);
}
$query
=
$query
->
rightJoin
(
'coin_recommend'
,
'coin.id=coin_recommend.cid'
);
$query
=
$query
->
rightJoin
(
'coin_recommend'
,
'coin.id=coin_recommend.cid'
);
$count
=
$query
->
count
();
$data
=
$query
->
offset
((
$page
-
1
)
*
10
)
->
limit
(
$limit
)
->
asArray
()
->
all
();
foreach
(
$data
as
$key
=>
$item
)
{
...
...
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