Commit 7708aabe authored by rlgy's avatar rlgy

提币审核不通过,账单里全部和提币两栏仍然记录这一笔,状态显示成功

parent d4603e13
......@@ -156,47 +156,21 @@ class CoinReleaseCheckController extends BaseController
if (CoinReleaseCheck::STATUS_NORMAL != $model->status) {
return ['code' => -1, 'msg' => '不允许进行审核!'];
}
try {
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;
if ($model->check_first($status)) {
if ($model->check_first_status == CoinReleaseCheck::CHECK_FIRST_STATUS_FAILD) {
$message = '操作成功! 该申请已被撤提';
$model->status = CoinReleaseCheck::STATUS_CANCEL;
} else {
$message = '审核通过!';
}
if ($model->save()) {
if ($model->check_first_status == CoinReleaseCheck::CHECK_FIRST_STATUS_FAILD) {
return ['code' => 0, 'msg' => $message];
}
return ['code' => 0, 'msg' => '操作成功!'];
}
} else {
return ['code' => -1, 'msg' => '初审失败!'];
}
} elseif (self::STEP_CHECK_SECOND == $step) {
//复审
if (CoinReleaseCheck::CHECK_FIRST_STATUS_SUCCEED == $model->check_first_status) {
//开启事务
$trans = CoinReleaseMember::getDb()->beginTransaction();
$model->check_second_uid = Yii::$app->user->id;
$model->check_second_status = $status;
if ($model->check_second_status == CoinReleaseCheck::CHECK_SECOND_STATUS_FAILD) {
$message = '操作成功! 该申请已被撤提';
$model->status = CoinReleaseCheck::STATUS_CANCEL;
} else {
//改变status
$model->status = CoinReleaseCheck::STATUS_PADDING;
}
if ($model->save()) {
//复审状态
if ($model->check_second_status == CoinReleaseCheck::CHECK_SECOND_STATUS_FAILD) {
//复审不通过就撤提
$trans->commit();
return ['code' => 0, 'msg' => $message];
}
// 提币 区块链转账接口
$from = '';
$member = CoinReleaseMember::findOne($model->mid);
if ($member) {
......@@ -209,74 +183,26 @@ class CoinReleaseCheckController extends BaseController
}
}
if (empty($from)) {
$trans->rollBack();
return ['code' => -1, 'msg' => '提币失败'];
}
if (strtoupper($model->coin) == 'BTY') {
$isToken = false;
} else {
$isToken = true;
}
//减少用户资产
$member->release -= $model->amount;
$member->output += $model->amount;
if ($member->save()) {
//保存提币记录到数据库
$coin_release_list = new CoinReleaseList();
$coin_release_list->mid = $member->id;
$coin_release_list->mobile = $member->mobile;
$coin_release_list->amount = $model->amount;
$coin_release_list->coin = $model->coin;
$coin_release_list->type = 1;//提币
$coin_release_list->from = $from;
$coin_release_list->to = $model->to_address;
if ($coin_release_list->save()) {
//转账
$result = Chain33Business::transToken(
trim($from),
trim($model->to_address),
(int)$model->amount,
"锁仓释放",
$isToken,
$model->coin
);
if (is_array($result)) {
$trans->rollBack();
return $result;
}
Yii::$app->queue->delay(15)->push(new QueryTransJob([
'txhash' => $result,
'lid' => $coin_release_list->id,
'cid' => $model->id
]));
$trans->commit();
return ['code' => 0, 'msg' => '审核通过'];
} else {
$trans->rollBack();
return ['code' => -1, 'msg' => '保存提币记录失败!'];
}
} else {
$trans->rollBack();
return ['code' => -1, 'msg' => '减少资产失败!'];
return ['code' => -1, 'msg' => '获取提币地址失败!'];
}
if ($model->check_second($status, $from)) {
if ($model->check_second_status == CoinReleaseCheck::CHECK_SECOND_STATUS_FAILD) {
$message = '操作成功! 该申请已被撤提';
} else {
$trans->rollBack();
return ['code' => -1, 'msg' => '保存提币记录失败'];
$message = '审核通过!';
}
return ['code' => 0, 'msg' => $message];
} else {
return ['code' => -1, 'msg' => '初审未通过'];
return ['code' => -1, 'msg' => '复审失败!'];
}
} elseif (self::STEP_CANCEL == $step) {
$model->check_first_uid = Yii::$app->user->id;
$model->check_second_uid = Yii::$app->user->id;
$model->status = CoinReleaseCheck::STATUS_CANCEL;
if ($model->save(false)) {
//返还币
if ($model->check_cancel()) {
return ['code' => 0, 'msg' => '操作成功'];
} else {
return ['code' => -1, '操作失败'];
}
}
} catch (\Exception $exception) {
return ['code' => $exception->getCode(), 'msg' => $exception->getMessage()];
}
}
}
}
......
......@@ -10,11 +10,14 @@ namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
use common\business\Chain33Business;
use backend\jobs\QueryTransJob;
/**
* @property integer $id
* @property integer $uid
* @property integer $mid
* @property integer $list_id
* @property string $mobile
* @property string $coin
* @property double $amount
......@@ -70,6 +73,7 @@ class CoinReleaseCheck extends BaseActiveRecord
return [
'id' => 'ID',
'uid' => 'UID',
'list_id' => '记录ID',
'mobile' => '手机',
'coin' => '币种',
'to_address' => '对方地址',
......@@ -89,46 +93,137 @@ class CoinReleaseCheck extends BaseActiveRecord
{
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'
],
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
],
[['id', 'uid', 'check_first_status', 'check_first_uid', 'check_second_status', 'check_second_uid', 'status', 'list_id'], '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
],
[['status', 'coin', 'check_first_uid', 'check_second_uid', 'start_time', 'end_time', 'mobile'], 'default', 'value' => '', 'on' => self::SCENARIOS_SEARCH],
];
}
/**
* 初审
*
* @param int $status
* @throws \Exception
* @return bool
*/
public function check_first(int $status)
{
if ($this->check_second_status != CoinReleaseCheck::CHECK_SECOND_STATUS_NORMAL) {
throw new \Exception('已经复核的申请不允许初审', -1);
}
if (self::CHECK_FIRST_STATUS_FAILD == $status) {
$this->check_first_status = $status;
return $this->check_cancel();
} else {
$this->check_first_uid = Yii::$app->user->id;
$this->check_first_status = $status;
return $this->save();
}
}
/**
* @param int $status
* @param string $address 提币地址
* @throws \Exception
* @return bool
*/
public function check_second(int $status, string $address = '')
{
if (self::CHECK_FIRST_STATUS_SUCCEED != $this->check_first_status) {
throw new \Exception('初审未通过!', -1);
}
if (CoinReleaseCheck::CHECK_SECOND_STATUS_FAILD == $status) {
$this->check_second_status = $status;
return $this->check_cancel();
} else {
//开启事务
$trans = self::getDb()->beginTransaction();
try {
$this->check_second_uid = Yii::$app->user->id;
$this->check_second_status = $status;
$this->status = self::STATUS_PADDING;
if ($this->save(false)) {
//区块链转币
if (strtoupper($this->coin) == 'BTY') {
$isToken = false;
} else {
$isToken = true;
}
$result = Chain33Business::transToken(
trim($address),
trim($this->to_address),
(int)$this->amount,
"锁仓释放",
$isToken,
$this->coin
);
if (is_array($result)) {
$trans->rollBack();
throw new \Exception($result['msg'], $result['code']);
}
$trans->commit();
Yii::$app->queue->delay(15)->push(new QueryTransJob([
'txhash' => $result,
'lid' => $this->list_id,
'cid' => $this->id
]));
return true;
} else {
throw new \Exception('修改审核状态失败', -1);
}
} catch (\Exception $exception) {
throw $exception;
}
}
}
/**
* 提币审核撤提
*
* @return bool
* @throws \Exception
*/
public function check_cancel()
{
//开启事务
$trans = self::getDb()->beginTransaction();
try {
$this->status = self::STATUS_CANCEL;
if (empty($this->check_first_uid)) {
$this->check_first_uid = Yii::$app->user->id;
}
if (empty($this->check_second_uid)) {
$this->check_second_uid = Yii::$app->user->id;
}
if ($this->save(false)) {
//修改提币记录
$coin_release_list = CoinReleaseList::findOne($this->list_id);
if ($coin_release_list) {
$coin_release_list->status = 2;//提币失败
if ($coin_release_list->save(false)) {
$trans->commit();
return true;
} else {
throw new \Exception('修改提币记录失败', -1);
}
} else {
throw new \Exception('获取提币记录失败', -1);
}
} else {
throw new \Exception('修改审核状态失败', -1);
}
} catch (\Exception $exception) {
$trans->rollBack();
throw $exception;
}
}
}
......@@ -18,6 +18,7 @@ use h5\base\ResponseBuild;
use Yii;
use h5\base\BaseController;
use common\business\ZhaobiBusiness;
use common\models\psources\CoinPublish;
class GuodunController extends BaseController
{
......@@ -84,11 +85,17 @@ class GuodunController extends BaseController
return $response;
}
//开启事务
$transaction = Yii::$app->db->beginTransaction();
try {
$user_asset = CoinReleaseMember::findOne([$id]);
//判断余额师傅充足
if ($user_asset->release < $amount * 1e8) {
$response->build(-1, '余额不足!');
return $response;
if (!$user_asset) {
throw new \Exception('资产不存在', -1);
}
//判断余额是否充足
$amount *= 1e8;
if ($user_asset->release < $amount) {
throw new \Exception('余额不足', -1);
}
//添加提币申请
......@@ -96,24 +103,54 @@ class GuodunController extends BaseController
$request_coin->uid = $user_asset->user_id;
$request_coin->mid = $id;
$request_coin->mobile = $user_asset->mobile;
$request_coin->amount = $amount * 1e8;
$request_coin->amount = $amount;
$request_coin->coin = $user_asset->coin;
$request_coin->to_address = $address;
$request_coin->company_name = $user_asset->company_name;
//记录提笔数据
// $user_asset->release -= ($amount * 1e8);
// $user_asset->output += $amount * 1e8;
//开启事务
try {
$trans = CoinReleaseMember::getDb()->beginTransaction();
//减少用户资产
$user_asset->release -= $amount;
$user_asset->output += $amount;
//获取发币地址
$from = '';
$coin_publish_rule = CoinPublishRule::findOne($user_asset->rule_id);
if ($coin_publish_rule) {
$coin_publish = CoinPublish::findOne($coin_publish_rule->pid);
if ($coin_publish) {
$from = $coin_publish->address;
}
}
if (empty($from)) {
throw new \Exception('获取发币地址失败', -1);
}
//添加提币记录
$coin_release_list = new CoinReleaseList();
$coin_release_list->mid = $id;
$coin_release_list->uid = $user_asset->user_id;
$coin_release_list->mobile = $user_asset->mobile;
$coin_release_list->amount = $amount;
$coin_release_list->coin = $user_asset->coin;
$coin_release_list->type = 1;
$coin_release_list->from = $from;
$coin_release_list->to = $address;
$coin_release_list->status = 3;//未完成
if ($user_asset->save(false)) {
if ($coin_release_list->save()) {
$request_coin->list_id = $coin_release_list->id;
if ($request_coin->save()) {
$trans->commit();
$transaction->commit();
$response->build(ResponseBuild::STATUS_SUCCEED);
} else {
$trans->rollBack();
$response->build(ResponseBuild::STATUS_INTERNAL_ERROR);
throw new \Exception('保存提币申请失败', -1);
}
} else {
throw new \Exception('保存提币记录失败', -1);
}
} else {
throw new \Exception('提币失败', -1);
}
} catch (\Exception $exception) {
$transaction->rollBack();
$response->build($exception->getCode(), $exception->getMessage());
}
//记录提币申请
......
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