Commit ae9f58a8 authored by rlgyzhcn's avatar rlgyzhcn

国盾锁仓

parent f176d299
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinPublish;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-publish';
public $js = [
'list.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinPublishRule;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-publish-rule';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinPublishRule;
use yii\web\AssetBundle;
use yii\web\View;
class ListAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-publish-rule';
public $js = [
'list.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinReleaseCheck;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-release-check';
public $js = [
'index.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 17:31:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\assets\coinReleaseMember;
use yii\web\AssetBundle;
use yii\web\View;
class IndexAsset extends AssetBundle
{
public $sourcePath = '@backend/web/js/coin-release-member';
public $js = [
'list.js',
];
public $jsOptions = [
'position' => View::POS_END,
];
}
......@@ -65,21 +65,21 @@ class AuthController extends BaseController
if (Yii::$app->request->isPost) {
$auth = Yii::$app->authManager;
$self_role = current($auth->getRolesByUser(Yii::$app->user->id));
$data = Yii::$app->request->post('param');
$data = Yii::$app->request->post('param');
$data['name'] = trim($data['name']);
if (!$data['name']) {
$this->error('请输入要添加的角色名!');
} else {
$role_name = $self_role->name . '.' . $data['name'];
$role_name = $data['name'];
if (Yii::$app->authManager->getRole($role_name) != null) {
$this->error('该角色名已存在!');
} else {
/* 创建角色 */
$role = Yii::$app->authManager->createRole($role_name);
$role->type = 1;
$role = Yii::$app->authManager->createRole($role_name);
$role->type = 1;
$role->description = $data['description'];
if (Yii::$app->authManager->add($role)) {
$auth = Yii::$app->authManager;
$auth = Yii::$app->authManager;
$auth->addChild($self_role, $role);
$this->success('添加成功!', $this->getForward());
}
......@@ -105,7 +105,7 @@ class AuthController extends BaseController
$role = Yii::$app->authManager->getRole($item_name);
if (Yii::$app->request->isPost) {
$data = Yii::$app->request->post('param');
$data = Yii::$app->request->post('param');
$data['name'] = trim($data['name']);
if (!$data['name']) {
......@@ -114,7 +114,7 @@ class AuthController extends BaseController
if (Yii::$app->authManager->getRole($data['name']) != null) {
$this->error('该角色名已存在!');
} else {
$role->name = $data['name'];
$role->name = $data['name'];
$role->description = $data['description'];
if (Yii::$app->authManager->update($item_name, $role)) {
$this->success('更新成功!', $this->getForward());
......@@ -197,14 +197,14 @@ class AuthController extends BaseController
}
/* 获取栏目节点 */
$node_list = Menu::returnNodes();
$node_list = Menu::returnNodes();
$auth_rules = Yii::$app->authManager->getChildren($role);
$auth_rules = array_keys($auth_rules);
return $this->render('auth', [
'node_list' => $node_list,
'node_list' => $node_list,
'auth_rules' => $auth_rules,
'role' => $role,
'role' => $role,
]);
}
......@@ -230,7 +230,7 @@ class AuthController extends BaseController
return $this->render('user', [
'dataProvider' => $this->lists1(new Admin(), $_where),
'role' => Yii::$app->request->get('role', 'administrator'),
'role' => Yii::$app->request->get('role', 'administrator'),
]);
}
......
......@@ -2,18 +2,20 @@
namespace backend\controllers;
use Yii;
use common\core\Controller;
use yii\helpers\Url;
use yii\data\Pagination;
use Yii;
use yii\data\ActiveDataProvider;
use yii\data\Pagination;
use yii\helpers\Url;
use common\modelsgii\Admin;
/**
* ---------------------------------------
* 后台父类控制器
* 后台所有控制器都继承自该类
* @author longfei phphome@qq.com
* ---------------------------------------
* @author longfei phphome@qq.com
*/
class BaseController extends Controller
{
......@@ -26,13 +28,13 @@ class BaseController extends Controller
{
/* 判断是否登录 */
/*if (\Yii::$app->user->getIsGuest()) {
$this->redirect(Url::toRoute(['/login/login']));
Yii::$app->end();
$this->redirect(Url::toRoute(['/login/login']));
Yii::$app->end();
}*/
/*if (!Yii::$app->request->isGet) {
AdminLog::saveLog($this);
}*/
AdminLog::saveLog($this);
}*/
}
/**
......@@ -48,9 +50,9 @@ class BaseController extends Controller
/**
* ---------------------------------------
* 获取之前标记的cookie位置
* @param string $default
* @return mixed
* ---------------------------------------
* @param string $default
* @return mixed
*/
public function getForward($default = '')
{
......@@ -65,11 +67,11 @@ class BaseController extends Controller
/**
* ---------------------------------------
* 传统分页列表数据集获取方法
* @param \yii\db\ActiveRecord $model 模型名或模型实例
* @param array $where where查询条件
* @param array|string $order 排序条件
* @return array|false
* ---------------------------------------
* @param \yii\db\ActiveRecord $model 模型名或模型实例
* @param array $where where查询条件
* @param array|string $order 排序条件
* @return array|false
*/
public function lists($model, $where = [], $order = '')
{
......@@ -79,7 +81,7 @@ class BaseController extends Controller
'totalCount' => $countQuery->count(),
'defaultPageSize' => 10,
]);
$data = $query->orderBy($order)->offset($pages->offset)
$data = $query->orderBy($order)->offset($pages->offset)
->limit($pages->limit)
->all();
......@@ -89,11 +91,11 @@ class BaseController extends Controller
/**
* ---------------------------------------
* dataProvider列表数据集获取方法
* @param \yii\db\ActiveRecord $model 模型名或模型实例
* @param array $where where查询条件
* @param array|string $order 排序条件
* @return \yii\data\ActiveDataProvider
* ---------------------------------------
* @param \yii\db\ActiveRecord $model 模型名或模型实例
* @param array $where where查询条件
* @param array|string $order 排序条件
* @return \yii\data\ActiveDataProvider
*/
public function lists1($model, $where = [], $order = '')
{
......@@ -111,10 +113,10 @@ class BaseController extends Controller
/**
* ---------------------------------------
* 修改数据表一条记录的一条值
* @param \yii\db\ActiveRecord $model 模型名称
* @param array $data 数据
* @return \yii\db\ActiveRecord|boolean
* ---------------------------------------
* @param \yii\db\ActiveRecord $model 模型名称
* @param array $data 数据
* @return \yii\db\ActiveRecord|boolean
*/
public function saveRow($model, $data)
{
......@@ -136,15 +138,15 @@ class BaseController extends Controller
/**
* ---------------------------------------
* 由表主键删除数据表中的多条记录
* @param \yii\db\ActiveRecord $model 模型名称,供M函数使用的参数
* @param string $pk 修改的数据
* @return boolean
* ---------------------------------------
* @param \yii\db\ActiveRecord $model 模型名称,供M函数使用的参数
* @param string $pk 修改的数据
* @return boolean
*/
public function delRow($model, $pk = 'id')
{
$ids = Yii::$app->request->param($pk, 0);
$ids = implode(',', array_unique((array)$ids));
$ids = implode(',', array_unique((array) $ids));
if (empty($ids)) {
return false;
......@@ -162,11 +164,11 @@ class BaseController extends Controller
* ----------------------------------------------
* 操作错误跳转的快捷方法
* @access protected
* @param string $message 错误信息
* @param string $jumpUrl 页面跳转地址
* @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间
* @return void
* -----------------------------------------------
* @param string $message 错误信息
* @param string $jumpUrl 页面跳转地址
* @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间
* @return void
*/
protected function error($message = '', $jumpUrl = '', $ajax = false)
{
......@@ -177,11 +179,11 @@ class BaseController extends Controller
* ----------------------------------------------
* 操作成功跳转的快捷方法
* @access protected
* @param string $message 提示信息
* @param string $jumpUrl 页面跳转地址
* @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间
* @return void
* ----------------------------------------------
* @param string $message 提示信息
* @param string $jumpUrl 页面跳转地址
* @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间
* @return void
*/
protected function success($message = '', $jumpUrl = '', $ajax = false)
{
......@@ -193,18 +195,19 @@ class BaseController extends Controller
* 默认跳转操作 支持错误导向和正确跳转
* 调用模板显示 默认为public目录下面的success页面
* 提示页面为可配置 支持模板标签
* @param string $message 提示信息
* @param int $status 状态
* @param string $jumpUrl 页面跳转地址
* @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间
* @access private
* @return void
* ----------------------------------------------
* @param string $message 提示信息
* @param int $status 状态
* @param string $jumpUrl 页面跳转地址
* @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间
* @return void
*/
private function dispatchJump($message, $status = 1, $jumpUrl = '', $ajax = false)
{
$jumpUrl = !empty($jumpUrl) ? (is_array($jumpUrl) ? Url::toRoute($jumpUrl) : $jumpUrl) : '';
if (true === $ajax || Yii::$app->request->isAjax) {// AJAX提交
if (true === $ajax || Yii::$app->request->isAjax) {
// AJAX提交
$data = is_array($ajax) ? $ajax : array();
$data['info'] = $message;
$data['status'] = $status;
......@@ -214,8 +217,9 @@ class BaseController extends Controller
// 成功操作后默认停留1秒
$waitSecond = 3;
if ($status) { //发送成功信息
$message = $message ? $message : '提交成功';// 提示信息
if ($status) {
//发送成功信息
$message = $message ? $message : '提交成功'; // 提示信息
// 默认操作成功自动返回操作前页面
echo $this->renderFile(Yii::$app->params['action_success'], [
'message' => $message,
......@@ -223,7 +227,7 @@ class BaseController extends Controller
'jumpUrl' => $jumpUrl,
]);
} else {
$message = $message ? $message : '发生错误了';// 提示信息
$message = $message ? $message : '发生错误了'; // 提示信息
// 默认发生错误的话自动返回上页
$jumpUrl = "javascript:history.back(-1);";
echo $this->renderFile(Yii::$app->params['action_error'], [
......@@ -241,9 +245,9 @@ class BaseController extends Controller
* ------------------------------------------------
* Ajax方式返回数据到客户端
* @access protected
* @param mixed $data 要返回的数据
* @return void
* ------------------------------------------------
* @param mixed $data 要返回的数据
* @return void
*/
protected function ajaxReturn($data)
{
......@@ -254,4 +258,25 @@ class BaseController extends Controller
exit;
}
/**
* 获取所有可以访问action的用户
*
* @return array
*/
public function getAccessAdmins($permission_name = '')
{
//获取所有管理员
if (empty($permission_name)) {
$permission_name = Yii::$app->controller->module->requestedRoute;
}
$auth = Yii::$app->authManager;
$admins = Admin::find()->select(['uid', 'username'])->asArray()->all();
foreach ($admins as $key => $value) {
if (!$auth->checkAccess($value['uid'], $permission_name)) {
unset($admins[$key]);
}
}
$admins = array_column($admins, 'username', 'uid');
return $admins;
}
}
<?php
/**
* Created By Sublime Text 3
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
namespace backend\controllers;
use Yii;
use backend\models\coin\CoinPublishForm;
use common\models\psources\CoinPublish;
use common\models\psources\Coin;
class CoinPublishController extends BaseController
{
public function actionList()
{
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
$get = Yii::$app->request->get();
$page = $get['page'] ?? 1;
$limit = $get['limit'] ?? 10;
$auth = Yii::$app->authManager;
$role_self = current($auth->getRolesByUser(Yii::$app->user->id));
$child_roles = $auth->getChildRoles($role_self->name);
$userful_roles = array_keys($child_roles);
// var_dump($userful_roles);die();
$condition[] = ['in', 'owner', $userful_roles];
$data = CoinPublish::getList($page, $limit, $condition);
return $data;
}
return $this->render('list');
}
public function actionAdd()
{
if (Yii::$app->request->isGet) {
$this->layout = false;
$id = Yii::$app->request->get('id', null);
if ($id) {
$model = CoinPublish::findOne($id);
} else {
$model = new CoinPublishForm();
}
$auth = Yii::$app->authManager;
$role = current($auth->getRolesByUser(Yii::$app->user->id));
$childRoles = array_keys($auth->getChildRoles($role->name));
// $coins = Coin::getAllByPlatformId(Yii::$app->user->identity->platform_id, 0, 999);
return $this->render('form', ['model' => $model, 'roles' => $childRoles]);
} elseif (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$post = Yii::$app->request->post();
$model = new CoinPublishForm();
if (isset($post['id']) && !empty($post['id'])) {
$model->scenario = CoinPublishForm::SCENARIOS_UPDATE;
} else {
$model->scenario = CoinPublishForm::SCENARIOS_ADD;
}
if ($model->load($post) && $model->validate()) {
if ($model->id) {
$CoinPublish = CoinPublish::findOne($model->id);
} else {
$CoinPublish = new CoinPublish();
}
$CoinPublish->company_name = $model->company_name;
$CoinPublish->coin_name_zh = $model->coin_name_zh;
$CoinPublish->coin_name_en = $model->coin_name_en;
$CoinPublish->address = $model->address;
$CoinPublish->owner = $model->owner;
$CoinPublish->platform_id = Yii::$app->user->identity->platform_id;
if ($CoinPublish->save(false)) {
return ['code' => 0, 'msg' => 'succeed', 'data' => ''];
} else {
return ['code' => -1, 'msg' => 'failed'];
}
} else {
return ['code' => -1, 'msg' => current($model->firstErrors)];
}
}
}
public function actionDel()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id', null);
if ($id) {
$model = CoinPublish::findOne(['id' => $id]);
if ($model->delete()) {
return ['code' => 0, 'msg' => 'succeed'];
}
}
return ['code' => -1, 'msg' => 'failed'];
}
}
\ No newline at end of file
<?php
/**
* Created By Sublime Test 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
namespace backend\controllers;
use backend\jobs\FreezeJob;
use common\models\psources\CoinPublish;
use common\models\psources\CoinPublishRule;
use common\models\psources\CoinReleaseMember;
use Yii;
class CoinPublishRuleController extends BaseController
{
const DATE_FORMAT = [
'Y-m-d H:i:s',
'm月d号 H:i:s', //每年
'd号 H:i:s', //每月
];
const SHOW_FORMAT = [
'Y-m-d H:i:s',
'm月d号 H:i:s', //每年
'd号 H:i:s', //每月
];
public function actionIndex()
{
if (Yii::$app->request->isAjax) {
$auth = Yii::$app->authManager;
$user_identity = Yii::$app->user->identity;
$get = Yii::$app->request->get();
$page = $get['page'] ?? 1;
$limit = $page['limit'] ?? 10;
$role = current($auth->getRolesByUser($user_identity->id));
Yii::$app->response->format = 'json';
// 获取用户组的所有锁仓规则
if (!$role) {
return ['code' => -1, 'msg' => 'failed'];
}
$condition = [['owner' => $role->name]];
$datas = CoinPublish::getList($page, $limit, $condition);
return $datas;
}
return $this->render('index');
}
public function actionList()
{
$get = Yii::$app->request->get();
$page = $get['page'] ?? 1;
$limit = $get['limit'] ?? 10;
$id = $get['id'] ?? null;
$pid = $get['pid'] ?? $this->getPid();
$condition = [];
if ($pid) {
$condition[] = ['pid' => $pid];
}
if ($id) {
$condition[] = ['id' => $id];
}
if (Yii::$app->request->isAjax) {
$data = CoinPublishRule::getList($page, $limit, $condition);
Yii::$app->response->format = 'json';
$models = $data['data'];
// 获取锁仓人数
$ids = array_column($models, 'id');
$member_count = CoinReleaseMember::getCountByRuleIds($ids);
foreach ($models as $key => &$model) {
$model['release_time'] = date(self::SHOW_FORMAT[$model['repeat']], strtotime($model['release_time']));
$model['amount'] = $member_count[$model['id']] ?? 0;
}
$data['data'] = $models;
return $data;
}
$coin = CoinPublish::findOne($pid);
return $this->render('list',
[
'coin_name' => $coin->coin_name_en ?? '',
'amount' => 100090000,
'release_amount' => CoinPublishRule::getReleaseAmountThisMonthById($pid),
'address' => $coin->address ?? '',
]);
}
public function actionSet()
{
if (Yii::$app->request->isGet) {
$this->layout = false;
return $this->render('form');
} elseif (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$post = Yii::$app->request->post();
if (isset($post['id']) && !empty($post['id'])) {
$model = CoinPublishRule::findOne($post['id']);
$model->scenario = CoinPublishRule::SCENARIOS_UPDAET;
unset($post['id']);
} else {
$model = new CoinPublishRule();
$model->scenario = CoinPublishRule::SCENARIOS_ADD;
// 编号
$prefix = date('Ymd', time());
$form_database = CoinPublishRule::find()
->where(['like', 'sid', $prefix])
->orderBy(['sid' => SORT_DESC])
->asArray()
->One();
if ($form_database) {
$sid = (int) $form_database['sid'] + 1;
} else {
$sid = $prefix . '001';
}
$model->platform_id = 3;
}
if ($model->load($post) && $model->validate()) {
if (CoinPublishRule::SCENARIOS_ADD == $model->scenario) {
$model->sid = (string) $sid;
}
$model->release_time = date_create_from_format(self::DATE_FORMAT[$model->repeat],
$model->release_time)->format('Y-m-d H:i:s');
$model->pid = $this->getPid();
if ($model->save()) {
if ($model->qid) {
//删除原有的任务
Yii::$app->queue->remove($model->qid);
}
// 计算延时
$now = time();
$delay_time = CoinPublishRule::getDelay($now, $model->repeat, strtotime($model->release_time));
// 保存数据到任务队列
$id = Yii::$app->queue->delay($delay_time)->push(new FreezeJob(['id' => $model->id]));
if (!$id) {
$model->delete();
Yii::info("CoinPublishRule_id[{$model->id}]: queue id[$id] , push failed!", __CLASS__);
return ['code' => -1, 'msg' => '保存失败'];
} else {
$model->qid = $id;
$model->save();
Yii::info("CoinPublishRule_id[{$model->id}]: queue id[$id] , push succeed!", __CLASS__);
}
return ['code' => 0, 'msg' => 'succeed'];
}
} else {
return ['code' => -1, 'msg' => current($model->firstErrors)];
}
return ['code' => -1, 'msg' => '保存失败'];
}
}
public function actionDel()
{
$id = Yii::$app->request->get('id', null);
Yii::$app->response->format = 'json';
if ($id) {
$model = CoinPublishRule::findOne($id);
if ($model) {
if ($model->getMemberCount() > 0) {
return ['code' => -1, 'msg' => '规则内有用户,不能删除!'];
} else {
// 删除队列任务
Yii::$app->queue->remove($model->qid);
if ($model->delete()) {
return ['code' => 0, 'msg' => 'succeed'];
}
}
}
}
return ['code' => -1, 'msg' => '删除失败'];
}
/**
* 获取id
* @return int
*/
private function getPid()
{
$referer = Yii::$app->request->getReferrer();
$referer = parse_url($referer, PHP_URL_QUERY);
parse_str($referer, $query);
if (!isset($query['pid']) || empty($query['pid'])) {
return false;
}
return $query['pid'];
}
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-05 17:13:46
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\controllers;
use common\models\psources\CoinExtract;
use common\models\psources\CoinPublish;
use common\models\psources\CoinReleaseCheck;
use Yii;
class CoinReleaseCheckController extends BaseController
{
const STEP_CHECK_FIRST = 1; //初审
const STEP_CHECK_SECOND = 2; //复核
const STEP_CANCEL = 3; //撤提
public $enableCsrfValidation = false;
public function actionIndex()
{
$admins = $this->getAccessAdmins();
//获取所有币种
$coins = CoinPublish::find()->select('coin_name_en')->asArray()->all();
$coins = array_column(array_unique($coins), 'coin_name_en');
return $this->render('index', [
'coins' => $coins,
'check_firsts' => $admins,
'check_seconds' => $admins,
]);
}
public function actionCheckList()
{
Yii::$app->response->format = 'json';
$get = Yii::$app->request->get();
$model = new CoinReleaseCheck();
$model->scenario = CoinReleaseCheck::SCENARIOS_CHECK;
if ($model->load($get) && $model->validate()) {
$page = $get['page'] ?? 1;
$limit = $page['limit'] ?? 10;
$datas = CoinReleaseCheck::find()
->andFilterWhere(['status' => 0, 'coin' => $model->coin, 'mobile' => $model->mobile]);
if ($model->start_time) {
$datas = $datas->andFilterWhere(['>=', 'create_time', $model->start_time]);
}
if ($model->end_time) {
$datas = $datas->andFilterWhere(['<=', 'create_time', $model->end_time]);
}
$count = $datas->count();
$datas = $datas->limit($limit)
->offset(($page - 1) * $limit)
->asArray()
->all();
//获取操作次数
//提出地址
$addresses = array_values(array_unique(array_column($datas, 'to_address')));
$address_datas = CoinExtract::getAllByAddress($addresses);
foreach ($datas as $key => &$value) {
$value['today'] = $address_datas[$value['to_address']]['today'];
$value['total'] = $address_datas[$value['to_address']]['total'];
}
return ['code' => 0, 'count' => $count, 'data' => $datas];
} else {
return ['code' => -1, 'msg' => current($model->firstErrors)];
}
}
public function actionSearchList()
{
Yii::$app->response->format = 'json';
$get = Yii::$app->request->get();
$model = new CoinReleaseCheck();
$model->scenario = CoinReleaseCheck::SCENARIOS_SEARCH;
if ($model->load($get) && $model->validate()) {
$page = $get['page'] ?? 1;
$limit = $page['limit'] ?? 10;
$query = CoinReleaseCheck::find()
->andFilterWhere(['!=', 'status', 0])
->andFilterWhere([
'status' => $model->status,
'coin' => $model->coin,
'check_first_uid' => $model->check_first_uid,
'check_second_uid' => $model->check_second_uid,
]);
if ($model->start_time) {
$query = $query->andFilterWhere(['>=', 'create_time', $model->start_time]);
}
if ($model->end_time) {
$query = $query->andFilterWhere(['<=', 'create_time', $model->end_time]);
}
$count = $query->count();
$datas = $query->limit($limit)->offset(($page - 1) * $limit)->asArray()->all();
//获取审核员id
$check_ids = array_column($datas, 'check_first_uid');
$check_ids = array_unique(array_values(array_merge($check_ids, array_column($datas, 'check_second_uid'))));
//获取所有管理员
$admins = $this->getAccessAdmins();
foreach ($datas as $key => &$value) {
$value['check_first_uid'] = $admins[$value['check_first_uid']];
$value['check_second_uid'] = $admins[$value['check_second_uid']];
}
return ['code' => 0, 'count' => $count, 'data' => $datas];
} else {
return ['code' => -1, 'msg' => current($model->firstErrors)];}
}
public function actionCheck()
{
Yii::$app->response->format = 'json';
$id = Yii::$app->request->get('id', null);
$status = Yii::$app->request->get('status', null);
$step = Yii::$app->request->get('step', null);
if (!empty($id) && !empty($status) && !empty($step)) {
if (ctype_digit($id) && ctype_digit($status) && ctype_digit($step)) {
if (($status == 2 || $status == 3) && ($step >= 1 || $step <= 3)) {
$model = CoinReleaseCheck::findOne($id);
if ($model) {
if (CoinReleaseCheck::STATUS_NORMAL != $model->status) {
return ['code' => -1, 'msg' => '不允许进行审核!'];
}
if (self::STEP_CHECK_FIRST == $step) {
if ($model->check_second_status != CoinReleaseCheck::CHECK_SECOND_STATUS_NORMAL) {
return ['code' => -1, 'msg' => '已经复核的申请不允许初审!'];
}
$model->check_first_uid = Yii::$app->user->id;
$model->check_first_status = $status;
} elseif (self::STEP_CHECK_SECOND == $step) {
if (CoinReleaseCheck::CHECK_FIRST_STATUS_SUCCEED == $model->check_first_status) {
$model->check_second_uid = Yii::$app->user->id;
$model->check_second_status = $status;
//改变status
$model->status = CoinReleaseCheck::STATUS_PADDING;
} else {
return ['code' => -1, 'msg' => '初审未通过'];
}
} elseif (self::STEP_CANCEL == $step) {
$model->status = CoinReleaseCheck::STATUS_CANCEL;
}
if ($model->save(false)) {
if ($step == self::STEP_CHECK_SECOND && CoinReleaseCheck::CHECK_SECOND_STATUS_SUCCEED == $model->check_second_status) {
//TODO 提币
}
return ['code' => 0, 'msg' => '操作成功'];
}
}
}
}
}
return ['code' => 0, 'msg' => '操作失败'];
}
}
<?php
/**
* Created By Sublime Test 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
namespace backend\controllers;
use Yii;
use yii\web\UploadedFile;
use common\models\psources\CoinReleaseMember;
use common\models\psources\CoinPublishRule;
/**
* CoinReleaseMember
*/
class CoinReleaseMemberController extends BaseController
{
public $enableCsrfValidation = false;
public function actionList()
{
$get = Yii::$app->request->get();
$page = $get['page'] ?? 1;
$limit = $get['limit'] ?? 10;
if (Yii::$app->request->isAjax) {
Yii::$app->response->format = 'json';
// 获取rule_id
$rule_id = $this->getRuleId();
if (empty($rule_id)) {
return ['code' => -1, 'msg' => 'failed'];
}
$condition = [['rule_id' => $rule_id]];
$datas = CoinReleaseMember::getList($page, $limit, $condition);
return $datas;
}
return $this->render('list');
}
public function actionSet()
{
if (Yii::$app->request->isGet) {
$this->layout = false;
return $this->render('form');
} else {
if (Yii::$app->request->isPost) {
Yii::$app->response->format = 'json';
$post = Yii::$app->request->post();
// 获取rule_id
$rule_id = $this->getRuleId();
if ($rule_id) {
$post['rule_id'] = $rule_id;
$coin_publish_rule = CoinPublishRule::findOne($rule_id);
if ($coin_publish_rule) {
$post['release'] = $post['amount'] * (100 - $coin_publish_rule->lock) / 100;
$post['freeze'] = $post['amount'] * $coin_publish_rule->lock / 100;
} else {
return ['code' => -1, 'msg' => '规则不存在'];
}
} else {
return ['code' => -1, 'msg' => '规则不存在'];
}
if (isset($post['id']) && !empty($post['id'])) {
$model = CoinReleaseMember::findOne($post['id']);
$model->scenario = CoinReleaseMember::SCENARIOS_UPDATE;
} else {
$model = new CoinReleaseMember();
$model->scenario = CoinReleaseMember::SCENARIOS_ADD;
}
if ($model->load($post) && $model->validate()) {
if ($model->save()) {
return ['code' => 0, 'msg' => '添加成功'];
}
} else {
return ['code' => -1, 'msg' => current($model->firstErrors)];
}
return ['code' => -1, 'msg' => '添加失败'];
}
}
}
/**
* 名单导入
*/
public function actionImplode()
{
Yii::$app->response->format = 'json';
$file = UploadedFile::getInstanceByName('file');
try {
$fd = fopen($file->tempName, 'r');
$data = [];
$rule_id = $this->getRuleId();
if ($rule_id) {
$coin_publish_rule = CoinPublishRule::findOne($rule_id);
$present = $coin_publish_rule->lock;
if (!$coin_publish_rule) {
return ['code' => -1, 'msg' => '规则不存在'];
}
while (($row = fgetcsv($fd)) !== false) {
array_unshift($row, $rule_id);
$data[] = $row;
}
if (empty($data)) {
return ['code' => -1, 'msg' => '导入失败'];
}
if (ctype_digit($data[0][0])) {
array_shift($data);
}
foreach ($data as $key => &$value) {
$value[] = $value[3] * (100 - $present) / 100;
$value[] = $value[3] * $present / 100;
}
$result = CoinReleaseMember::implode($data);
if ($result) {
return ['code' => 0, 'msg' => '导入成功'];
}
} else {
return ['code' => -1, 'msg' => '规则不存在'];
}
} catch (\Exception $e) {
return ['code' => $e->getCode(), 'msg' => $e->getMessage()];
}
return ['code' => 0, 'msg' => '导入失败'];
}
/**
* 获取rule_id
* @return int
*/
private function getRuleId()
{
$referer = Yii::$app->request->getReferrer();
$referer = parse_url($referer, PHP_URL_QUERY);
parse_str($referer, $query);
if (!isset($query['rid']) || empty($query['rid'])) {
return false;
}
return $query['rid'];
}
}
\ No newline at end of file
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-04 10:43:18
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace backend\jobs;
use common\models\psources\CoinPublishRule;
use common\models\psources\CoinReleaseMember;
use Yii;
use yii\base\BaseObject;
use yii\queue\JobInterface;
use yii\queue\Queue;
class FreezeJob extends BaseObject implements JobInterface
{
public $id;
/**
* @param Queue $queue which pushed and is handling the job
* @return integer
*/
public function execute($queue)
{
$coin_publish_rule = CoinPublishRule::findOne($this->id);
if (!$coin_publish_rule) {
// 计划任务已经被删除
return 0;
}
//修改用户的币种冻结信息
$members = CoinReleaseMember::getMemberByRuleIds($this->id);
foreach ($members as $key => &$value) {
//获取改的币种数量
$change = CoinPublishRule::calReleaseAmount($coin_publish_rule->lock, $coin_publish_rule->release, $coin_publish_rule->type, $value['amount'], $value['freeze'], 0);
if ($change > $value['freeze']) {
$change = $value['freeze'];
}
$value['release'] += $change;
$value['freeze'] -= $change;
}
unset($key, $value);
// 记录解冻操作
Yii::info(sprintf('Coin Freeze Job Start: sid[%s] lock[%s] release[%s]',
$coin_publish_rule->sid, $coin_publish_rule->lock, $coin_publish_rule->release), __CLASS__);
foreach ($members as $key => $value) {
$models = CoinReleaseMember::findOne($value['id']);
$models->release = $value['release'];
$models->freeze = $value['freeze'];
$models->save();
// 记录解冻操作
Yii::info(sprintf('member[Id=%s] release amount: %s, freeze still: %s', $value['id'], $change, $value['freeze']), __CLASS__);
}
// 执行下一次任务
if ($coin_publish_rule->repeat) {
$delay_time = CoinPublishRule::getDelay('', $coin_publish_rule->repeat, strtotime($coin_publish_rule->release_time));
$qid = Yii::$app->queue->delay($delay_time)->push(new FreezeJob(['id' => $this->id]));
$coin_publish_rule->qid = $qid;
$coin_publish_rule->save();
}
// 记录解冻操作
Yii::info(sprintf('Coin Freeze Job Finished: sid[%s] lock[%s] release[%s]',
$coin_publish_rule->sid, $coin_publish_rule->lock, $coin_publish_rule->release), __CLASS__);
return 0;
}
}
<?php
/**
* Created By Sublime Text 3
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
namespace backend\models\coin;
use yii\base\Model;
use Yii;
class CoinPublishForm extends Model
{
const SCENARIOS_ADD = 'add';
const SCENARIOS_UPDATE = 'update';
public $id;
public $company_name;
public $coin_name_en;
public $coin_name_zh;
public $address;
public $owner;
public $platform_id;
public function rules()
{
return [
[['company_name', 'coin_name_zh', 'coin_name_en', 'address'], 'string', 'max' => 255],
[['owner'], 'ownerValidate'],
[['id', 'platform_id'], 'integer', 'min' => 0],
[
['id', 'company_name', 'coin_name_zh', 'coin_name_en'],
'required',
'on' => self::SCENARIOS_UPDATE
],
[['company_name', 'coin_name_zh', 'coin_name_en'], 'required', 'on' => self::SCENARIOS_ADD],
];
}
public function attributeLabels()
{
return [
'id' => 'ID',
'company_name' => '公司名称',
'coin_name_zh' => '币种中文名',
'coin_name_en' => '币种英文名',
'address' => '热钱包地址',
'platform_id' => '平台id',
'owner' => '企业用户组',
];
}
public function scenarios()
{
return [
self::SCENARIOS_ADD => ['company_name', 'coin_name_zh', 'coin_name_en', 'address', 'owner'],
self::SCENARIOS_UPDATE => [
'id',
'company_name',
'coin_name_zh',
'coin_name_en',
'address',
'owner'
],
];
}
public function formName()
{
return '';
}
public function ownerValidate($attribute, $params)
{
$roleName = $this->$attribute;
$auth = Yii::$app->authManager;
$child_role = $auth->getRole($roleName);
if (!$child_role) {
$this->addError($attribute, '企业用户组不存在');
}
return true;
}
}
\ No newline at end of file
......@@ -26,11 +26,6 @@ $columns = [
'headerOptions'=>['style'=>'width:10px'], 'contentOptions' => ['style' => 'white-space: nowrap;']
],
[
'label' => 'UID',
'attribute' => 'bind_uid',
'options' => ['width' => '70px'],
],
[
'label' => '真实姓名',
'attribute' => 'name.name',
'options' => ['width' => '80px'],
......
<?php
/**
* Created By Sublime Test 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
?>
<style>
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md12">
<form id="form_data" class="layui-form" lay-filter="form_data">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>" />
<input type="hidden" name="id" />
<div class="layui-inline">
<label class="layui-form-label" style="width: 110px;">锁仓编号</label>
<div class="layui-input-block">
<input name="sid" type="text" class="layui-input" lay-verify="required" readonly="readonly" />
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 110px;">锁仓比例(%)</label>
<div class="layui-input-block">
<input name="lock" type="text" class="layui-input" lay-verify="required" />
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 110px;">类型</label>
<div class="layui-input-block">
<select name="type" class="layui-input">
<option value="0"></option>
<option value="1">按锁仓总量释放</option>
<option value="2">按锁仓余量释放</option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 110px;">释放比例(%)</label>
<div class="layui-input-block">
<input name="release" type="text" class="layui-input" lay-verify="required" />
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 110px;">重复</label>
<div class="layui-input-block">
<select name="repeat" class="layui-input" lay-filter="form_data">
<option value="0">不重复</option>
<option value="1">每年</option>
<option value="2">每月</option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 110px;">释放时间</label>
<div class="layui-input-block">
<input name="release_time" type="text" class="layui-input" lay-verify="required" id="release_time" />
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label" style="width: 110px;">备注</label>
<div class="layui-input-block">
<textarea name="notice" class="layui-textarea"></textarea>
</div>
</div>
</form>
</div>
</div>
<?php
/**
* Created By Sublime Text 3
*
* @authors rlgy <rlgyzhcn@qq.com>
* @date 2018-09-04 10:11:49
*/
use backend\assets\coinPublishRule\IndexAsset;
IndexAsset::register($this);
?>
<div>
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
<script type="text/html" id="toolbar">
<a class="layui-btn layui-btn-sm" href="/admin/coin-publish-rule/list?pid={{d.id}}">查看详情</a>
</script>
\ No newline at end of file
<?php
/**
* Created By Sublime Test 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
use backend\assets\coinPublishRule\ListAsset;
ListAsset::register($this);
?>
<div class="layui-row">
<div class="layui-col-md6">
<table class="layui-table">
<thead>
<th>币种</th>
<th>热钱包数量</th>
<th>当月解冻总量</th>
<th>热钱包地址</th>
</thead>
<tbody>
<tr>
<td><?= $coin_name ?></td>
<td><?= $amount ?></td>
<td><?= $release_amount ?></td>
<td><?= $address ?></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="layui-row">
<table class="layui-hide" id="table1" lay-filter="table1"></table>
</div>
<script type="text/html" id="toolBarTop">
<div class="layui-btn-container">
<button class="layui-btn layui-btn-sm" lay-event="add">创建锁仓规则</button>
</div>
</script>
<script type="text/html" id="toolbar">
<button class="layui-btn layui-btn-xs" lay-event="update">编辑</button>
<a class="layui-btn layui-btn-xs" href="/admin/coin-release-member/list?rid={{d.id}}">详情</a>
<button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
</script>
<script type="text/html" id="form_type">
{{# if (1 == d.type) { }}
按锁仓总量释放
{{# } else if (2 == d.type) { }}
按锁仓余量释放
{{# } }}
</script>
<script type="text/html" id="form_release_time">
{{# if (d.repeat == 0) { }}
{{d.release_time}}
{{# } else if (d.repeat == 1) { }}
每年 {{d.release_time}}
{{# } else if (d.repeat == 2) { }}
每月 {{d.release_time}}
{{# } else if (d.repeat == 3) { }}
每天 {{d.release_time}}
{{# } }}
</script>
\ No newline at end of file
<?php
/**
* Created By Sublime text 3
* @author rlgzyhcn <rlgyzhcn@qq.com>
*/
/**
* @var \commom\models\psources\CoinPublish $model
* @var array $roles
*/
?>
<style type="text/css">
.layui-form-label {
width: 100px;
}
</style>
<div style="padding: 5px 20px;">
<form id="addData" class="layui-form">
<input name="_csrf" type="hidden" value="<?= Yii::$app->request->getCsrfToken() ?>">
<input type="hidden" name="id" value="<?= $model->id ?>">
<div class="layui-inline">
<span class="layui-form-label" style="width: 100px;">公司名称</span>
<div class="layui-input-block">
<input name="company_name" type="text" class="layui-input" lay-verify="required" value="<?= $model->company_name ?>">
</div>
</div>
<div class="layui-inline">
<span class="layui-form-label" style="width: 100px;">发行币种</span>
<div class="layui-input-block">
<input name="coin_name_zh" type="text" class="layui-input" lay-verify="required" value="<?= $model->coin_name_zh ?>">
</div>
</div>
<div class="layui-inline">
<span class="layui-form-label" style="width: 100px;">简称</span>
<div class="layui-input-block">
<input name="coin_name_en" type="text" class="layui-input" lay-verify="required" value="<?= $model->coin_name_en ?>">
</div>
</div>
<div class="layui-inline">
<span class="layui-form-label" style="width: 100px;">热钱包地址</span>
<div class="layui-input-block">
<input name="address" type="text" class="layui-input" lay-verify="required" value="<?= $model->address ?>">
</div>
</div>
<div class="layui-inline">
<span class="layui-form-label" style="width: 100px;">企业用户组</span>
<div class="layui-input-block">
<select name="owner" class="layui-select">
<?php if (is_array($roles)): ?>
<?php foreach($roles as $role): ?>
<option value="<?= $role ?>"><?= $role ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
</form>
</div>
\ No newline at end of file
<?php
/**
* Created By Sublime text 3
* @author rlgzyhcn <rlgyzhcn@qq.com>
*/
use backend\assets\coinPublish\IndexAsset;
IndexAsset::register($this);
?>
<h4>发币管理</h4>
<div class="layui-row">
<button class="layui-btn" id="add">添加币种监控</button>
</div>
<div class="layui-row">
<div class="layui-table" id="table1" lay-filter="table1"></div>
</div>
<script type="text/html" id="toolbar">
<a class="layui-btn layui-btn-xs" lay-event="update">编辑</a>
<a class="layui-btn layui-btn-xs" href="/admin/coin-publish-rule/list?pid={{d.id}}">查看配置</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
\ No newline at end of file
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-05 18:40:23
* @authors rlgy <rlgyzhcn@qq.com>
*/
use backend\assets\coinReleaseCheck\IndexAsset;
IndexAsset::register($this);
?>
<style type="text/css">
.layui-form-label{
width: 60px;
padding: 0 0 0 0;
line-height: 40px;
text-align: center;
}
.layui-inline{
margin-bottom: 0;
margin-right: 10px;
}
</style>
<div class="layui-row">
<table class="layui-table">
<thead>
<tr>
<th>币种</th>
<?php if (is_array($coins)): ?>
<?php foreach ($coins as $key => $value): ?>
<th><?=strtoupper($value);?></th>
<?php endforeach;?>
<?php endif;?>
</tr>
</thead>
<tbody>
<tr>
<td>高度</td>
<td>56646</td>
</tr>
</tbody>
</table>
</div>
<div class="layui-row">
<h4>审核</h4>
<div class="layui-row">
<form class="layui-form" lay-filter="form_check">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">币种</label>
<div class="layui-input-inline">
<select class="layui-select" name="coin">
<option value="">全部</option>
<?php if (is_array($coins)): ?>
<?php foreach ($coins as $key => $value): ?>
<option value="<?=strtoupper($value);?>"><?=strtoupper($value);?></option>
<?php endforeach;?>
<?php endif;?>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">开始时间</label>
<div class="layui-input-inline">
<input type="text" name="start_time" class="layui-input" placeholder="选择时间范围" id="date_check_start">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">结束时间</label>
<div class="layui-input-inline">
<input type="text" name="end_time" class="layui-input" placeholder="选择时间范围" id="date_check_end">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline" style="margin-left: 5px;">
<input type="text" name="mobile" class="layui-input" placeholder="手机" autocomplete="off">
</div>
</div>
<div class="layui-inline">
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-filter="submit_check" lay-submit>搜索</button>
<button class="layui-btn layui-btn-sm layui-btn-primary" type="reset">重置筛选</button>
</div>
</div>
</form>
</div>
<div class="layui-row">
<table class="layui-table" id="table_check" lay-filter="table_check"></table>
</div>
</div>
<div class="layui-row">
<h4>查询</h4>
<div class="layui-row">
<form class="layui-form" lay-filter="form_search">
<div class="layui-form-item">
<div class="layui-inline">
<label class="layui-form-label">状态</label>
<div class="layui-input-inline">
<select class="layui-select" name="status">
<option value="">全部</option>
<option value="1">未完成</option>
<option value="2">完成</option>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">币种</label>
<div class="layui-input-inline">
<select class="layui-select" name="coin">
<option value="">全部</option>
<?php if (is_array($coins)): ?>
<?php foreach ($coins as $key => $value): ?>
<option value="<?=strtoupper($value);?>"><?=strtoupper($value);?></option>
<?php endforeach;?>
<?php endif;?>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">初审员</label>
<div class="layui-input-inline">
<select class="layui-select" name="check_first_uid">
<option value="">全部</option>
<?php if(!empty($check_firsts)): ?>
<?php foreach($check_firsts as $key => $value): ?>
<option value="<?= $key ?>"><?= $value ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">复审员</label>
<div class="layui-input-inline">
<select class="layui-select" name="check_second_uid">
<option value="">全部</option>
<?php if(!empty($check_seconds)): ?>
<?php foreach($check_seconds as $key => $value): ?>
<option value="<?= $key ?>"><?= $value ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<br>
<div class="layui-inline">
<label class="layui-form-label">开始时间</label>
<div class="layui-input-inline">
<input type="text" name="start_time" class="layui-input" placeholder="选择时间范围" id="date_search_start">
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">结束时间</label>
<div class="layui-input-inline">
<input type="text" name="end_time" class="layui-input" placeholder="选择时间范围" id="date_search_end">
</div>
</div>
<div class="layui-inline">
<div class="layui-input-inline" style="margin-left: 5px;">
<input type="text" name="mobile" class="layui-input" placeholder="手机" autocomplete="off">
</div>
</div>
<div class="layui-inline">
<button class="layui-btn layui-btn-sm layui-btn-normal" lay-submit lay-filter="submit_search">搜索</button>
<button class="layui-btn layui-btn-sm layui-btn-primary" type="reset">重置筛选</button>
<button class="layui-btn layui-btn-sm layui-btn-danger">导出</button>
</div>
</div>
</form>
</div>
<div class="layui-row">
<table class="layui-table" id="table_search" lay-filter="table_search"></table>
</div>
</div>
<script type="text/html" id="toolbar_check">
<!-- 复核通过无法撤体 -->
{{# if(d.status!=0){ }}
<!-- 撤提之后无法进行任何操作 -->
<button class="layui-btn layui-btn-xs layui-btn-disabled">初审</button>
<button class="layui-btn layui-btn-xs layui-btn-disabled">复核</button>
<button class="layui-btn layui-btn-xs layui-btn-disabled">撤提</button>
{{# }else{ }}
<!-- 复核之后无法在初审 -->
{{# if(1==d.check_second_status){ }}
{{# if(1==d.check_first_status){ }}
<button class="layui-btn layui-btn-xs" lay-event="check_first">初审</button>
{{# }else if(2==d.check_first_status && 2!=d.check_seconf_status){ }}
<button class="layui-btn layui-btn-xs layui-btn-primary" lay-event="check_first">初审(已通过)</button>
{{# }else if(3==d.check_first_status){ }}
<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="check_first">初审(不通过)</button>
{{# } }}
{{# }else{ }}
<button class="layui-btn layui-btn-xs layui-btn-disabled">初审</button>
{{# } }}
<!-- 初审通过才可复核 -->
{{# if(2==d.check_first_status){ }}
{{# if(1==d.check_second_status){ }}
<button class="layui-btn layui-btn-xs" lay-event="check_second">复核</button>
{{# }else if(2==d.check_second_status){ }}
<button class="layui-btn layui-btn-xs layui-btn-primary" lay-event="check_second">复核(已通过)</button>
{{# }else if(3==d.check_second_status){ }}
<button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="check_second">复核(不通过)</button>
{{# } }}
{{# }else{ }}
<button class="layui-btn layui-btn-xs layui-btn-disabled">复核</button>
{{# } }}
{{# } }}
{{# if(2==d.check_second_status){ }}
<button class="layui-btn layui-btn-xs layui-btn-disabled">撤提</button>
{{# }else{ }}
<button class="layui-btn layui-btn-xs layui-btn" lay-event="extract_cancel">撤提</button>
{{# } }}
</script>
<script type="text/html" id="search_status">
{{# if(1==d.status){ }}
未完成
{{# }else if(2==d.status){ }}
被撤提
{{# }else if(3==d.status){ }}
失败
{{# }else if(4==d.status){ }}
完成
{{# } }}
</script>
\ No newline at end of file
<?php
/**
* Created By Sublime Test 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
?>
<style type="text/css">
.layui-form-label {
width: 100px;
}
</style>
<div class="layui-row" style="padding: 5px;">
<div class="layui-col-md12">
<form class="layui-table" id="form_data" lay-filter="form_data">
<input type="hidden" name="_csrf" value="<?= Yii::$app->request->getCsrfToken() ?>">
<div class="layui-inline">
<label class="layui-form-label">手机号码</label>
<div class="layui-input-block">
<input type="text" name="mobile" class="layui-input" />
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">币种</label>
<div class="layui-input-block">
<input type="text" name="coin" class="layui-input" />
</div>
</div>
<div class="layui-inline">
<label class="layui-form-label">总量</label>
<div class="layui-input-block">
<input type="text" name="amount" class="layui-input" />
</div>
</div>
</form>
</div>
</div>
\ No newline at end of file
<?php
/**
* Created By Sublime Test 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
use backend\assets\coinReleaseMember\IndexAsset;
IndexAsset::register($this);
?>
<div class="layui-row">
<button class="layui-btn layui-btn-sm" lay-event="implode" id="implode">名单导入</button>
<button class="layui-btn layui-btn-sm" lay-event="add" id="add">添加人员</button>
</div>
<div class="layui-row">
<div class="layui-col-md8">
<table class="layui-table" id="table1" lay-filter="table1"></table>
</div>
</div>
\ No newline at end of file
/**
* Created By Sublime Text 3
*
* @authors rlgy (rlgyzhcn@qq.com)
* @date 2018-09-04 10:24:52
*/
var table = layui.table;
table.render({
elem: '#table1',
url: '/admin/coin-publish-rule/index',
page: 1,
limit: 10,
cols: [[
{field: "id", title: "ID"},
{field: "coin_name_en", title: '币种中文名'},
{field: "coin_name_zh", title: "币种英文名"},
{field: "address", title: "热钱包地址"},
{title: "操作", toolbar: "#toolbar"}
]]
});
\ No newline at end of file
var table = layui.table;
var form = layui.form;
var laydate = layui.laydate;
var format = [
'yyyy-MM-dd HH:mm:ss',// 不重复
'MM月dd号 HH:mm:ss', //每年
'dd号 HH:mm:ss', //每月
];
var laydate1;
table.render({
elem: '#table1',
url: '/admin/coin-publish-rule/list',
limit: 10,
page: 1,
toolbar: '#toolBarTop',
cols: [[
{field: 'sid', title: '锁仓编号'},
{field: 'amount', title: '锁仓人数'},
{field: 'release_time', title: '释放时间', templet: "#form_release_time"},
{field: 'lock', title: '锁仓比例'},
{field: 'type', title: '释放类型', templet: "#form_type"},
{field: 'release', title: '释放比例'},
{field: 'notice', title: '备注'},
{title: '操作', toolbar: '#toolbar'}
]]
});
table.on('tool(table1)', function (obj) {
var event = obj.event;
var data = obj.data;
if ('update' == event) {
$.get('/admin/coin-publish-rule/set', {id: data.id}, function (rev) {
var index = layer.open({
type: 1,
title: '编辑',
id: 'update_one',
skin: 'layer-skin-lan',
content: rev,
btn: ['保存', '取消'],
btn1: function () {
$btn = $('.layui-layer-btn0').button('loading');
$.post('/admin/coin-publish-rule/set', $("#form_data").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
layer.close(index);
table.reload("table1", {});
}
});
$btn.button('reset');
}
});
form.render();
$.get('/admin/coin-publish-rule/list', {id: data.id, page: 1, limit: 1}, function (rev) {
if (0 == rev.code) {
var data = rev.data[0];
form.val("form_data", {
id: data.id,
sid: data.sid,
lock: data.lock,
type: data.type,
release: data.release,
repeat: data.repeat,
release_time: "",
notice: data.notice,
});
laydate1 = laydate.render({
elem: '#release_time',
type: 'datetime',
format: format[data.repeat],
value: data.release_time
});
}
});
});
} else if ('del' == event) {
layer.confirm('确定删除锁仓规则(' + data.sid + ')', {title: '删除'}, function (index) {
$.get('/admin/coin-publish-rule/del', {id: data.id}, function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
obj.del();
layer.close(index);
}
});
});
}
});
table.on('toolbar(table1)', function (obj) {
var checkStatus = table.checkStatus(obj.config.id);
var event = obj.event;
if ('add' == event) {
$.get('/admin/coin-publish-rule/set', {}, function (rev) {
var index = layer.open({
type: 1,
title: '添加锁仓规则',
id: 'add_one',
skin: 'layer-skin-lan',
content: rev,
// area: ['500px', 'auto'],
btn: ['确认', '取消'],
btn1: function () {
$btn = $('.layui-layer-btn0').button('loading');
$.post('/admin/coin-publish-rule/set', $("#form_data").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
layer.close(index);
table.reload("table1", {});
}
});
$btn.button('reset');
}
});
form.render();
laydate1 = laydate.render({
elem: '#release_time',
type: 'datetime',
});
});
}
});
form.on('select(form_data)', function (data) {
var index = $('#form_data select[name="repeat"]').val();
var clone = $("#release_time").clone();
var parent = $("#release_time").parent("div");
$("#release_time").remove();
clone.removeAttr('lay-key');
parent.append(clone);
laydate.render({
elem: '#release_time',
type: 'datetime',
format: format[index]
});
});
var table = layui.table;
table.render({
elem: "#table1",
url: '/admin/coin-publish/list',
limit: 10,
page: 1,
loading: true,
cols: [[
{field: 'id', title: 'ID'},
{field: 'company_name', title: '公司名称'},
{field: 'coin_name_zh', title: '币种中文名'},
{field: 'coin_name_en', title: '币种英文名'},
{field: 'address', title: '热钱包地址'},
{field: 'amount', title: '热钱包数量'},
{toolbar: '#toolbar', title: '操作'}
]],
});
table.on('tool(table1)', function(obj){
var event = obj.event;
var data = obj.data;
if ('update' == event) {
$.get('/admin/coin-publish/add', {id: data.id}, function (str) {
var index = layer.open({
type: 1,
title: '编辑',
id: 'add-one',
skin: 'layui-layer-lan',
area: ['320px', 'auto'],
content: str,
btn: ['确认', '取消'],
btn1: function () {
var company_name = $('#addData input[name="company_name"]').val();
var coin_name_zh = $('#addData input[name="coin_name_zh"]').val();
var coin_name_en = $('#addData input[name="coin_name_en"]').val();
if (company_name !== "" && company_name !== "" && coin_name_en !== "") {
$btn = $('.layui-layer-btn0').button('loading');
$.post('/admin/coin-publish/add', $("#addData").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
layer.close(index);
table.reload("table1", {});
}
});
$btn.button('reset');
} else {
layer.msg("请输入完整!");
}
return false;
}
});
layui.form.render();
});
}else if('del' == event){
layer.confirm('确定删除此币种监控吗?', {title: '删除币种'}, function(index){
$.get('/admin/coin-publish/del', {id: data.id}, function(rev) {
if (rev.code == 0) {
obj.del();
layer.close(index);
}
});
});
}
});
$('#add').click(function () {
//打开弹窗
$.get('/admin/coin-publish/add', {}, function (str) {
var index = layer.open({
type: 1,
title: '添加币种监控',
id: 'add-one',
skin: 'layui-layer-lan',
area: ['320px', 'auto'],
content: str,
btn: ['确认', '取消'],
btn1: function () {
var company_name = $('#addData input[name="company_name"]').val();
var coin_name_zh = $('#addData input[name="coin_name_zh"]').val();
var coin_name_en = $('#addData input[name="coin_name_en"]').val();
if (company_name !== "" && company_name !== "" && coin_name_en !== "") {
$btn = $('.layui-layer-btn0').button('loading');
$.post('/admin/coin-publish/add', $("#addData").serialize(), function (rev) {
layer.msg(rev.msg);
if (rev.code == 0) {
layer.close(index);
table.reload("table1", {});
}
});
$btn.button('reset');
} else {
layer.msg("请输入完整!");
}
return false;
}
});
layui.form.render();
});
return false;
});
\ No newline at end of file
/**
*
* @authors rlgy (rlgyzhcn@qq.com)
* @date 2018-09-05 19:33:56
*/
var form = layui.form;
var table = layui.table;
var laydate = layui.laydate;
form.render();
var table_check = table.render({
elem: '#table_check',
page: true,
limit: 10,
url: '/admin/coin-release-check/check-list',
cols: [[
{field: 'id', title: '流水编号'},
{field: 'mobile', title: '手机号'},
{field: 'coin', title: '币种'},
{field: 'amount', title: '数量'},
{field: 'to_address', title: '对方地址'},
{field: 'today', title: '该地址今日提币次数'},
{field: 'total', title: '该地址总操作数'},
{field: 'create_time', title: '提交时间'},
{title: '操作', toolbar: '#toolbar_check'}
]]
});
var table_search = table.render({
elem: '#table_search',
page: true,
limit: 10,
url: '/admin/coin-release-check/search-list',
cols: [[
{field: 'id', title: '流水编号'},
{field: 'mobile', title: '手机号'},
{field: 'coin', title: '币种'},
{field: 'amount', title: '数量'},
{field: 'to_address', title: '对方地址'},
{field: 'create_time', title: '提交时间'},
{field: 'create_time', title: '完成时间'},
{field: 'status', title: '状态', templet: '#search_status'},
{field: 'check_first_uid', title: '初审员'},
{field: 'check_second_uid', title: '复审员'},
]]
});
laydate.render({
elem: '#date_check_start',
});
laydate.render({
elem: '#date_check_end',
});
laydate.render({
elem: '#date_search_start',
});
laydate.render({
elem: '#date_search_end',
});
form.on('submit(submit_check)', function (data) {
table.reload('table_check', {
page:{
curr:1
},
where: data.field
});
return false;
});
form.on('submit(submit_search)', function (data) {
table.reload('table_search', {
page: {
curr: 1,
},
where: data.field
});
return false;
});
//工具栏点击事件
table.on('tool(table_check)',function (obj) {
var event = obj.event;
var data = obj.data;
if (event=='check_first') {
var index = layer.msg('审核通过?',{
title: '审核',
btn: ['通过', '不通过', '取消'],
btn1: function (index, layero) {
$.get('/admin/coin-release-check/check', {id: data.id, status: 2, step: 1}, function(rev){
layer.msg(rev.msg);
if (0==rev.code) {
table_check.reload();
layer.close(index);
}
});
},
btn2: function (index, layero) {
$.get('/admin/coin-release-check/check', {id: data.id, status: 3, step: 1}, function(rev){
layer.msg(rev.msg);
if (0==rev.code) {
table_check.reload();
layer.close(index);
}
});
}
});
} else if('check_second'==event){
var index = layer.msg('复核通过?',{
title: '复核',
btn: ['通过', '不通过', '取消'],
btn1: function (index, layero) {
$.get('/admin/coin-release-check/check', {id: data.id, status: 2, step: 2}, function(rev){
layer.msg(rev.msg);
if (0==rev.code) {
table_check.reload();
table_search.reload();
layer.close(index);
}
});
},
btn2: function (index, layero) {
$.get('/admin/coin-release-check/check', {id: data.id, status: 3, step: 2}, function(rev){
layer.msg(rev.msg);
if (0==rev.code) {
table_check.reload();
layer.close(index);
}
});
}
});
} else if('extract_cancel' == event){
var index = layer.msg('撤提该申请?',{
title: '撤提',
btn: ['撤提', '取消'],
btn1: function (index, layero) {
$.get('/admin/coin-release-check/check', {id: data.id, status: 2, step: 3}, function(rev){
layer.msg(rev.msg);
if (0==rev.code) {
table_check.reload();
table_search.reload();
layer.close(index);
}
});
}
});
}
});
var table = layui.table;
var upload = layui.upload;
table.render({
elem: "#table1",
url: '/admin/coin-release-member/list',
page: 1,
limit: 10,
cols: [[
{field: 'mobile', title: '手机号'},
{field: 'coin', title: '币种'},
{field: 'amount', title: '总量'},
{field: 'release', title: '已解冻'},
{field: 'freeze', title: '已冻结'},
]]
});
upload.render({
elem: "#implode",
url: "/admin/coin-release-member/implode",
accept: 'file',
exts: 'csv',
done: function (res) {
layer.closeAll('loading');
layer.msg(res.msg);
table.reload('table1', {
page: {
curr: 1
}
});
},
before: function(obj){ //obj参数包含的信息,跟 choose回调完全一致,可参见上文。
layer.load(); //上传loading
}
});
$("#add").click(function () {
$.get('/admin/coin-release-member/set', {}, function (rev) {
var index = layer.open({
type: 1,
title: "添加人员",
id: 'add_one',
skin: 'layui-skin-lan',
content: rev,
btn: ['保存', '取消'],
btn1: function () {
$.post('/admin/coin-release-member/set', $("#form_data").serialize(), function (rev) {
layer.msg(rev.msg);
if (0 == rev.code) {
layer.close(index);
table.reload('table1', {
page: {
curr: 1
}
});
}
});
}
});
});
});
\ No newline at end of file
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -147,6 +147,28 @@ class Coin extends BaseActiveRecord
}
/**
* 获取某个平台下的所有币种
*
* @param integer $id
* @param integer $page
* @param integer $limit
* @return array
*/
public static function getAllByPlatformId($id, $page = 1, $limit = 10)
{
if (!ctype_alnum($id)) {
return false;
}
$query = self::find()->andWhere(['>', "find_in_set($id, platform_id)", 0]);
$count = $query->count();
if ($count) {
$data = $query->limit($limit)->offset(($page - 1) * $limit)->asArray()->all();
return ['total' => $count, 'list' => $data];
}
return false;
}
/**
* 根据id列表获取币种信息
*
* @param array $ids [description]
......
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-07 15:18:43
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
/**
* 用户提币操作记录表
* @property integer $id
* @property string $address
* @property integer $today
* @property integer $total
* @property string $create_time
* @property string $update_time
*/
class CoinExtract extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_extract}}';
}
public function formName()
{
return '';
}
public static function getAllByAddress($addresses)
{
if (!is_array($addresses)) {
$addresses = [$addresses];
}
$query = self::find()->where(['in', 'address', $addresses])->asArray()->all();
return array_column($query, null, 'address');
}
}
<?php
/**
* Created By SUblime Text 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
/**
* @property int $id id
* @property string $company_name 公司名称
* @property string $coin_name_zh 币种中文名
* @property string $coin_name_en 币种英文名
* @property string $address 热钱包地址
* @property int $platform_id 平台id
* @property string $owner 平台id
*/
class CoinPublish extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_publish}}';
}
}
<?php
/**
* Created By Sublime Test 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
/**
* CoinPublishRule
* 锁仓规则表
* @param integer $qid 任务id
*/
class CoinPublishRule extends BaseActiveRecord
{
const SCENARIOS_ADD = 'add';
const SCENARIOS_UPDAET = 'update';
const DATE_FORMAT = [
0 => 'Y-m-d H:i:s',
1 => 'm-d H:i:s',
2 => 'd H:i:s',
3 => 'H:i:s',
];
const DATE_FORMAT_PREFIX = [
0 => '',
1 => 'Y-',
2 => 'Y-m-',
3 => 'Y-m-d ',
];
const REPEAT_NORMAL = 0; //不重复
const REPEAT_YEAR = 1; //每年
const REPEAT_MONTH = 2; //每月
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_publish_rule}}';
}
public function getMemberCount()
{
return CoinReleaseMember::find()->where(['rule_id' => $this->id])->count();
}
public function formName()
{
return '';
}
public function attributeLabels()
{
return [
'id' => 'ID',
'sid' => '锁仓编号',
'lock' => '锁仓比例',
'release' => '释放比例',
'type' => '释放类型',
'repeat' => '重复',
'release_time' => '释放时间',
'notice' => '备注',
];
}
public function sercians()
{
return [
self::SCENARIOS_ADD => ['lock', 'release', 'type', 'repeat', 'release_time', 'notice'],
self::SCENARIOS_UPDAET => ['id', 'sid', 'lock', 'release', 'type', 'repeat', 'release_time', 'notice'],
];
}
public function rules()
{
return [
[['sid', 'release_time', 'notice'], 'string'],
[['sid', 'release_time'], 'string', 'max' => 255],
[['release_time'], 'validateTime'],
[['id', 'lock', 'release', 'type', 'repeat'], 'integer'],
[['lock', 'release', 'type', 'repeat', 'release_time'], 'required', 'on' => self::SCENARIOS_ADD],
[
['id', 'sid', 'lock', 'release', 'type', 'repeat', 'release_time'],
'required',
'on' => self::SCENARIOS_UPDAET,
],
];
}
/**
* 获取距离下一次执行的时间(秒)
*
* @param int $timestamp 开始时间戳
* @param int $repeat_type 重复类型
* @param int $repeat_time 重复时间戳
* @return int|false
*/
public static function getDelay($timestamp, $repeat_type, $repeat_time)
{
if (empty($timestamp)) {
$timestamp = time();
}
$next_timestamp = self::getNextExecTimestamp($timestamp, $repeat_type, $repeat_time);
if ($next_timestamp < $timestamp) {
return false;
}
return $next_timestamp - $timestamp;
}
/**
* 返回下一次执行的时间戳
*
* @param integer $timestamp 开始时间戳
* @param integer $repeat_type 重复类型
* @param string $repeat_time 数据库存储的时间戳
* @return integer
*/
public static function getNextExecTimestamp($timestamp, $repeat_type, $repeat_time)
{
if (empty($timestamp)) {
$timestamp = time();
}
$format = self::DATE_FORMAT[$repeat_type];
$repeat = date($format, $repeat_time);
$prefix = date(self::DATE_FORMAT_PREFIX[$repeat_type], $timestamp);
$next_time = $prefix . $repeat;
$next_timestamp = strtotime($next_time);
return $next_timestamp;
}
/**
* 验证时间
*
* @param [type] $attribute [description]
* @param [type] $params [description]
* @return [type] [description]
*/
public function validateTime($attribute, $params)
{
if ($this->repeat == 0) {
if (strtotime($this->$attribute) <= time()) {
$this->addErrors(['无效的释放时间']);
}
}
}
/**
* 获取当月解冻总量
* @param integer $id
* @return integer
*/
public static function getReleaseAmountThisMonthById($id)
{
//获取时间范围
$timestamp = time();
$month = date('Y-m', $timestamp);
$month_start = strtotime($month . '-01 00:00:00');
$month_end = strtotime('+1 month', $month_start);
// 获取当月计划执行的规则 (每天+每月+每年+不重复的)
$datas = CoinPublishRule::find()->where(['pid' => $id])->asArray()->all();
foreach ($datas as $key => $value) {
$variable = self::isVariableInRange($month_start, $month_end, $value['repeat'], strtotime($value['release_time']));
if ($variable === false) {
unset($datas[$key]);
}
}
$datas = array_column($datas, null, 'id'); // 所有规则
//获取规则下的所有用户
$ids = array_keys($datas);
$members = CoinReleaseMember::getMemberByRuleIds($ids);
// 已rule_id为键合并数组
$new_members = [];
foreach ($members as $key => &$value) {
$new_members[$value['rule_id']][] = $value;
}
$members = &$new_members;
$amount = 0;
foreach ($members as $rule_id => $value) {
$rule = $datas[$rule_id];
$lock_present = $rule['lock'];
$rel_present = $rule['release'];
$type = $rule['type'];
$repeat = $rule['repeat'];
$release_timestamp = strtotime($rule['release_time']);
foreach ($value as $key => $item) {
$amount += self::calReleaseAmountMonth($lock_present, $rel_present, $type, $repeat, $item['amount'], $item['freeze'], $timestamp, $month_end, $release_timestamp);
}
}
return $amount;
}
/**
* 获取时间范围内的有效任务(将要执行的)
*
* @param string $start 时间戳
* @param string $end 时间戳
* @param integer $repeat 重复方法
* @param string $release_time 时间戳
* @return boolean $result
*/
public static function isVariableInRange($start, $end, $repeat, $release_time)
{
$delay = self::getDelay($start, $repeat, $release_time);
if (false === $delay) {
return false;
}
if ($start + $delay > $end) {
return false;
}
return true;
}
/**
* 计算一次释放币种数量
*
* @param integer $lock_present 锁仓百分比
* @param integer $rel_present 释放百分比
* @param integer $type 释放类型,1按总量,2按余量
* @param integer $amount 用户币的总量
* @param integer $freeze 用户释放的币
* @param integer $n 计算上n次释放数量
* @return integer|boolean
*/
public static function calReleaseAmount($lock_present, $rel_present, $type, $amount, $freeze, $n = 0)
{
$first_lock_amount = $amount * $lock_present / 100;
if (1 == $type) {
return $first_lock_amount * $rel_present / 100;
} elseif (2 == $type) {
return $freeze * pow((100 - $rel_present) / 100, $n) * $rel_present / 100;
}
return false;
}
/**
* 计算一个月内释放的币种数量
*
* @param integer $lock_present 锁仓百分比
* @param integer $rel_present 释放百分比
* @param integer $type 释放类型,1按总量,2按余量
* @param integer $amount 用户币的总量
* @param integer $freeze 用户已经释放的币
* @param integer $timestamp 当前时间戳
* @param integer $month_end 截止时间戳
* @param integer $repeat 重复类型
* @param integer $release_timestamp 重复时间戳
* @return integer
*/
public static function calReleaseAmountMonth($lock_present, $rel_present, $type, $repeat, $amount, $freeze, $timestamp, $month_end, $release_timestamp)
{
$result = 0;
$is_executed = self::isVariableInRange($timestamp, $month_end, $repeat, $release_timestamp);
if ($is_executed) {
$result += self::calReleaseAmount($lock_present, $rel_present, $type, $amount, $freeze, 0);
} else {
//如果是第一次添加的不计算
if ($amount * $lock_present / 100 != $freeze) {
$result += self::calReleaseAmount($lock_present, $rel_present, $type, $amount, $freeze, -1);
}
}
return $result;
}
}
<?php
/**
* Created By Sublime Text 3
*
* @date 2018-09-06 14:07:10
* @authors rlgy <rlgyzhcn@qq.com>
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
/**
* @property integer $id
* @property integer $uid
* @property string $mobile
* @property string $coin
* @property string $to_address
* @property integer $check_first_status
* @property integer $check_first_uid
* @property integer $check_second_status
* @property integer $check_second_uid
* @property integer $status
* @property srting $create_time
* @property srting $update_time
*/
class CoinReleaseCheck extends BaseActiveRecord
{
const SCENARIOS_CHECK = 'check'; //审核列表筛选
const SCENARIOS_SEARCH = 'search'; //查询列表筛选
const CHECK_FIRST_STATUS_NORMAL = 1; // 初审未审核
const CHECK_FIRST_STATUS_SUCCEED = 2; // 初审审核通过
const CHECK_FIRST_STATUS_FAILD = 3; // 初审审核未通过
const CHECK_SECOND_STATUS_NORMAL = 1; // 复审未审核
const CHECK_SECOND_STATUS_SUCCEED = 2; // 复审审核通过
const CHECK_SECOND_STATUS_FAILD = 3; // 复审审核未通过
const STATUS_NORMAL = 0; // 提币申请审核未通过
const STATUS_PADDING = 1; // 提币申请审核完成,提币未完成
const STATUS_CANCEL = 2; // 提币申请被撤提
const STATUS_FAILD = 3; // 提币失败
const STATUS_SUCCEED = 4; // 提币成功
public $start_time = '';
public $end_time = '';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_release_check}}';
}
public function formName()
{
return '';
}
public function attributeLabels()
{
return [
'id' => 'ID',
'uid' => 'UID',
'mobile' => '手机',
'coin' => '币种',
'to_address' => '对方地址',
'check_first_status' => '初审状态',
'check_first_uid' => '初审员',
'check_second_status' => '复审状态',
'check_second_uid' => '复审员',
'create_time' => '创建时间',
'update_time' => '更新时间',
'start_time' => '提交开始时间',
'end_time' => '提交结束时间',
'status' => '审核状态',
];
}
public function sercians()
{
return [
self::SCENARIOS_CHECK => ['coin', 'start_time', 'end_time', 'mobile'],
self::SCENARIOS_SEARCH => ['status', 'coin', 'check_first_uid', 'check_second_uid', 'start_time', 'end_time', 'mobile'],
];
}
public function rules()
{
return [
[['id', 'uid', 'check_first_status', 'check_first_uid', 'check_second_status', 'check_second_uid', 'status'], 'integer'],
[['mobile', 'coin', 'to_address', 'create_time', 'update_time', 'start_time', 'end_time'], 'string', 'max' => 255],
[['end_time'], 'compare', 'compareAttribute' => 'start_time', 'operator' => '>=', 'skipOnEmpty' => true],
[['coin', 'start_time', 'end_time', 'mobile'], 'default', 'value' => '', 'on' => self::SCENARIOS_CHECK],
[['status', 'coin', 'check_first_uid', 'check_second_uid', 'start_time', 'end_time', 'mobile'], 'default', 'value' => '', 'on' => self::SCENARIOS_SEARCH],
];
}
}
<?php
/**
* Created By Sublime Test 3
*
* @author rlgyzhcn <rlgyzhcn@qq.com>
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
/**
* CoinReleaseMember
* @property int $id
* @property int $rule_id
* @property int $user_id
* @property int $amount 币种总数
* @property int $release 币种释放总数
* @property int $freeze 币种冻结总数
* @property int $platform_id 平台id
* @property string $mobile 手机号码
* @property string $coin 币种
*/
class CoinReleaseMember extends BaseActiveRecord
{
const SCENARIOS_ADD = 'add';
const SCENARIOS_UPDATE = 'update';
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_release_member}}';
}
public function attributeLabels()
{
return [
'id' => 'ID',
'rule_id' => '规则ID',
'user_id' => '用户ID',
'amount' => '总量',
'release' => '已解冻',
'freeze' => '冻结',
'platform_id' => '平台id',
'mobile' => '手机',
'coin' => '币种',
];
}
public function rules()
{
return [
[['id', 'rule_id', 'user_id', 'amount', 'release', 'freeze', 'platform_id'], 'integer'],
[['mobile', 'coin'], 'string'],
[['rule_id', 'amount', 'mobile', 'coin'], 'required', 'on' => self::SCENARIOS_ADD],
];
}
public function formName()
{
return '';
}
public function sercians()
{
return [
self::SCENARIOS_ADD => ['rule_id', 'mobile', 'coin', 'amount'],
self::SCENARIOS_UPDATE => ['id', 'rule_id', 'mobile', 'coin', 'amount'],
];
}
/**
* 导入数据
* @param int $datas[0] mobile
* @param string $datas[1] coin
* @param int $datas[2] amount
* @return boolean
*/
public static function implode(array $datas)
{
if (!is_array($datas)) {
return false;
}
try {
$result = self::getDb()
->createCommand()
->batchInsert(self::tableName(), ['rule_id', 'mobile', 'coin', 'amount', 'release', 'freeze'], $datas)
->execute();
return $result;
} catch (\Exception $e) {
}
return false;
}
/**
* 批量获取锁仓规则下的人数
*
* @param array $ids 规则id
* @return array|boolean 返回id为键,数量为值的数组
*/
public static function getCountByRuleIds($ids)
{
if (!is_array($ids)) {
$ids = [$ids];
}
$query = CoinReleaseMember::find()->select(['rule_id', 'COUNT(id) as count'])
->groupBy('rule_id')->where(['in', 'rule_id', $ids]);
// return $query->createCommand()->getRawSql();
$datas = $query->asArray()->all();
return array_column($datas, 'count', 'rule_id');
}
/**
* 批量返回用户
*
* @param integer|array $ids
* @return array
*/
public static function getMemberByRuleIds($ids)
{
return CoinReleaseMember::find()->where(['rule_id' => $ids])->andWhere(['>', 'freeze', 0])->asArray()->all();
}
}
......@@ -8,8 +8,8 @@
namespace common\models\pwallet;
use Yii;
use common\core\BaseActiveRecord;
use Yii;
/**
* Class AppVersion
......@@ -30,19 +30,18 @@ class AppVersion extends BaseActiveRecord
const APP_UPDATE = 'update';
/**
* @return null|object|\yii\db\Connection
* @throws \yii\base\InvalidConfigException
* @return null|object|\yii\db\Connection
*/
public static function getDb()
{
return Yii::$app->get('db_pwallet');
}
/**
* 获取最新的稳定版app
*
* @param int $type android(1) IOS(3)
* @param int $type android(1) IOS(3)
* @return array
*/
public static function getLastStable($type = 1)
......@@ -96,7 +95,7 @@ EOF;
[['download_url'], 'string', 'max' => 255],
[['status', 'type', 'version_code', 'version', 'download_url'], 'required', 'on' => 'add'],
[['id', 'status', 'type', 'version_code', 'version', 'download_url'], 'required', 'on' => 'update']
[['id', 'status', 'type', 'version_code', 'version', 'download_url'], 'required', 'on' => 'update'],
];
}
......@@ -104,7 +103,7 @@ EOF;
{
return [
'add' => ['status', 'type', 'version_code', 'version', 'download_url', 'log'],
'update' => ['id', 'status', 'type', 'version_code', 'version', 'download_url', 'log']
'update' => ['id', 'status', 'type', 'version_code', 'version', 'download_url', 'log'],
];
}
}
\ No newline at end of file
}
......@@ -58,14 +58,6 @@ class AdminSearch extends Admin
// $query->where('0=1');
return $dataProvider;
}
if ($this->from) {
if ($this->from == 'backend') {
$query->andWhere('bind_uid is null');
} else if ($this->from == 'fxee') {
$query->andWhere('bind_uid is not null');
}
}
return $dataProvider;
}
}
......@@ -42,11 +42,10 @@ class Admin extends \common\core\BaseActiveRecord
return HtmlPurifier::process($str);
}
],
[['bind_uid', 'reg_time', 'reg_ip', 'last_login_time', 'last_login_ip', 'update_time', 'status'], 'integer'],
[['reg_time', 'reg_ip', 'last_login_time', 'last_login_ip', 'update_time', 'status'], 'integer'],
[['username'], 'string', 'max' => 32],
[['password'], 'string', 'min' => 6, 'max' => 60],
[['salt'], 'string', 'max' => 32],
[['username', 'bind_uid'], 'unique', 'message' => '该账号或UID已被占用'],
];
}
......@@ -57,7 +56,6 @@ class Admin extends \common\core\BaseActiveRecord
{
return [
'uid' => 'Uid',
'bind_uid' => 'Bind Uid',
'username' => 'Username',
'password' => 'Password',
'salt' => 'Salt',
......
<?php
/**
* Created By Sublime Text 3
*
* @authors rlgy <rlgyzhcn@qq.com>
* @date 2018-09-05 16:54:03
*/
namespace console\controllers;
use Yii;
use yii\base\BaseObject;
use backend\jobs\FreezeJob;
use yii\queue\JobInterface;
use yii\queue\Queue;
use yii\console\Controller;
use common\models\psources\CoinPublishRule;
use common\models\psources\CoinReleaseMember;
/**
* Class ExchangeController
* 调用交易所api更新数据保存到redis
* @package console\controllers
*/
class DevController extends Controller
{
/**
* 解冻币任务
* @return [type] [description]
*/
public function actionFreeze1()
{
$qid = Yii::$app->queue->push(new FreezeJob(['id' => 43]));
var_dump($qid);
}
}
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