Commit 7151a999 authored by rlgy's avatar rlgy

空投管理

parent d563234d
......@@ -21,17 +21,21 @@ class InvestmentController extends BaseController
$page = $request->get('page', 1);
$limit = $request->get('limit', 10);
$status = $request->get('status', 0);
$tid = $request->get('tid', 0);
$uid = $request->get('uid', 0);
$coin = $request->get('coin', '');
$where = [];
if ($uid) {
$where[] = ['uid' => $uid];
$where[] = ['a.uid' => $uid];
}
if ($status) {
$where[] = ['status' => $status];
$where[] = ['a.status' => $status];
}
if ($tid) {
$where[] = ['a.tid' => $tid];
}
if ($coin) {
$where[] = ['coin' => $coin];
$where[] = ['a.coin' => $coin];
}
Yii::$app->response->format = 'json';
return Investment::getList($page, $limit, $where);
......@@ -50,9 +54,12 @@ class InvestmentController extends BaseController
if ($model->load($post) && $model->validate()) {
$model->create_at = date('Y-m-d H:i:s');
$model->update_at = date('Y-m-d H:i:s');
if ($model->save()) {
return ['code' => 0, 'msg' => 'succeed'];
try {
$model->save();
} catch (\Exception $e) {
return ['code' => $e->getCode(), 'msg' => $e->getMessage()];
}
return ['code' => 0, 'msg' => 'succeed'];
}
$error = $model->errors;
if ($error) {
......
......@@ -26,9 +26,10 @@ $type = InvestmentType::getList(1, 999, []);
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 55px;margin-bottom: 0; padding-left: 10px;text-align: left">类型</label>
<label class="layui-form-label"
style="width: 55px;margin-bottom: 0; padding-left: 10px;text-align: left">类型</label>
<div class="layui-input-inline">
<select name="type">
<select name="tid">
<option value="0">全部</option>
<?php if ($type['count'] > 0): ?>
<?php foreach ($type['data'] as $item): ?>
......@@ -49,7 +50,7 @@ $type = InvestmentType::getList(1, 999, []);
</div>
</div>
<div class="layui-inline">
<button class="layui-btn">搜索</button>
<button class="layui-btn" lay-filter="form1" lay-submit>搜索</button>
<button class="layui-btn" type="reset">重置</button>
<button class="layui-btn" id="add1">添加数据</button>
<button class="layui-btn" id="add2">导入文件</button>
......
......@@ -14,11 +14,11 @@ table.render({
{field: 'nickname', title: "昵称"},
{field: 'coin', title: "币种"},
{field: 'count', title: "数量"},
{field: 'tid', title: "类型"},
{field: 'type', title: "类型"},
{field: 'status', title: "状态"},
{field: 'address', title: "地址"},
{field: 'create_at', title: "添加时间"},
{field: 'dealwith_at', title: "处理时间"}
{field: 'update_at', title: "处理时间"}
]]
});
$("#add1").click(function () {
......@@ -58,4 +58,12 @@ $("#add1").click(function () {
});
$("#add2").click(function () {
return false;
});
form.on('submit(form1)', function (data) {
table.reload('table1', {
where: data.field,
page: {curr: 1}
});
return false;
});
\ No newline at end of file
......@@ -44,10 +44,24 @@ class Investment extends BaseActiveRecord
return [
[['id', 'uid', 'tid'], 'integer'],
[['coin', 'address'], 'string'],
[['count'],'default']
[['count'], 'default']
];
}
/**
* @param bool $runValidation
* @param null $attributeNames
* @return bool
* @throws \Exception
*/
public function save($runValidation = true, $attributeNames = null)
{
$uid = $this->uid;
if (!Member::userExists($uid)) {
throw new \Exception('用户不存在', '2300');
}
return parent::save($runValidation, $attributeNames); // TODO: Change the autogenerated stub
}
public function attributeLabels()
{
......@@ -63,4 +77,36 @@ class Investment extends BaseActiveRecord
'update_at' => '更新时间',
];
}
public static function getList($page = 1, $limit = 10, $condition = [])
{
$query = self::find()->from('investment as a')->select([
'a.id',
'a.uid',
'c.nickname',
'a.coin',
'a.count',
'b.name as type',
'a.status',
'a.address',
'a.create_at',
'a.update_at',
])->leftJoin('investment_type as b', 'a.tid=b.id')->leftJoin('member as c', 'a.uid=c.uid');
foreach ($condition as $item) {
$query = $query->andWhere($item);
}
$count = $query->count();
$data = $query->offset(($page - 1) * 10)->limit($limit)->asArray()->all();
// $sql = $query->createCommand()->getSql();
$data = ['count' => $count, 'data' => $data];
if ($count > 0) {
$data['code'] = 0;
} else {
$data['code'] = 1;
$data['msg'] = '数据为空';
}
return $data;
}
}
\ No newline at end of file
......@@ -169,4 +169,9 @@ class Member extends BaseActiveRecord
$this->save(false);
}
public static function userExists($uid)
{
return (bool)self::findOne($uid);
}
}
\ No newline at end of file
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