|
|
@@ -60,13 +60,13 @@ class PledgeOrderService extends BaseService
|
|
|
{
|
|
|
$cacheKey = "caches:pledge:counts_{$userId}";
|
|
|
$counts = RedisService::get($cacheKey);
|
|
|
- if ($counts) {
|
|
|
- $expiredTime = isset($counts['expired_time']) ? intval($counts['expired_time']) : 0;
|
|
|
- $settleTime = isset($counts['settle_time']) ? intval($counts['settle_time']) : 0;
|
|
|
- $counts['pledge_end_time'] = $expiredTime > time() ? intval($expiredTime - time()) : 0;
|
|
|
- $counts['pledge_settle_time'] = $settleTime > time() ? intval($settleTime - time()) : 0;
|
|
|
+ if($counts){
|
|
|
+ $expiredTime = isset($counts['expired_time'])? intval($counts['expired_time']) : 0;
|
|
|
+ $settleTime = isset($counts['settle_time'])? intval($counts['settle_time']) : 0;
|
|
|
+ $counts['pledge_end_time'] = $expiredTime>time()? intval($expiredTime - time()) : 0;
|
|
|
+ $counts['pledge_settle_time'] = $settleTime>time()? intval($settleTime - time()) : 0;
|
|
|
$counts['pledge_end_text'] = timeFormat($counts['pledge_end_time']);
|
|
|
- $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'], 2);
|
|
|
+ $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'],2);
|
|
|
return $counts;
|
|
|
}
|
|
|
|
|
|
@@ -75,35 +75,33 @@ class PledgeOrderService extends BaseService
|
|
|
"pledge_total" => "0.00",
|
|
|
"pledge_money" => "0.00",
|
|
|
"pledge_profit" => "0.00",
|
|
|
- "pledge_destruction" => "0.00",
|
|
|
"pledge_end_time" => 0,
|
|
|
"pledge_settle_time" => 0,
|
|
|
"pledge_ent_text" => '00:00:00',
|
|
|
"pledge_settle_data" => [
|
|
|
- 'hour' => '00',
|
|
|
- 'minute' => '00',
|
|
|
- 'second' => '00',
|
|
|
+ 'hour'=> '00',
|
|
|
+ 'minute'=> '00',
|
|
|
+ 'second'=> '00',
|
|
|
],
|
|
|
];
|
|
|
|
|
|
- if ($userId) {
|
|
|
- $counts['pledge_count'] = (int)$this->model->where(['user_id' => $userId, 'mark' => 1])->count('id');
|
|
|
- $counts['pledge_destruction'] = (int)abs(AccountLogModel::where(['type' => 1, 'coin_type' => 2, 'status' => 1, 'mark' => 1])->sum('money'));
|
|
|
- $counts['pledge_total'] = moneyFormat($this->model->where(['user_id' => $userId, 'mark' => 1])->sum('money'), 2);
|
|
|
- $info = $this->model->where(['user_id' => $userId, 'status' => 1, 'mark' => 1])->orderBy('create_time', 'desc')->orderBy('id', 'desc')->first();
|
|
|
- $info = $info ? $info->toArray() : [];
|
|
|
- if ($info) {
|
|
|
- $counts['pledge_money'] = moneyFormat($info['money'], 2);
|
|
|
+ if($userId){
|
|
|
+ $counts['pledge_count'] = (int)$this->model->where(['user_id'=> $userId,'mark'=>1])->count('id');
|
|
|
+ $counts['pledge_total'] = moneyFormat($this->model->where(['user_id'=> $userId,'mark'=>1])->sum('money'),2);
|
|
|
+ $info = $this->model->where(['user_id'=> $userId,'status'=>1,'mark'=>1])->orderBy('create_time','desc')->orderBy('id','desc')->first();
|
|
|
+ $info = $info? $info->toArray() : [];
|
|
|
+ if($info){
|
|
|
+ $counts['pledge_money'] = moneyFormat($info['money'],2);
|
|
|
$counts['pledge_profit'] = moneyFormat($info['profit'], 2);
|
|
|
|
|
|
- $expiredTime = $info['expired_at'] ? strtotime($info['expired_at']) : 0;
|
|
|
- $settleTime = $info['settle_at'] ? strtotime($info['settle_at']) : 0;
|
|
|
+ $expiredTime = $info['expired_at']? strtotime($info['expired_at']) : 0;
|
|
|
+ $settleTime = $info['settle_at']? strtotime($info['settle_at']) : 0;
|
|
|
$counts['expired_time'] = $expiredTime;
|
|
|
$counts['settle_time'] = $settleTime;
|
|
|
- $counts['pledge_end_time'] = $expiredTime > time() ? intval($expiredTime - time()) : 0;
|
|
|
- $counts['pledge_settle_time'] = $settleTime > time() ? intval($settleTime - time()) : 0;
|
|
|
+ $counts['pledge_end_time'] = $expiredTime>time()? intval($expiredTime - time()) : 0;
|
|
|
+ $counts['pledge_settle_time'] = $settleTime>time()? intval($settleTime - time()) : 0;
|
|
|
$counts['pledge_end_text'] = timeFormat($counts['pledge_end_time']);
|
|
|
- $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'], 2);
|
|
|
+ $counts['pledge_settle_data'] = timeFormat($counts['pledge_settle_time'],2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -120,13 +118,13 @@ class PledgeOrderService extends BaseService
|
|
|
{
|
|
|
$cacheKey = "caches:pledge:checkRefund_{$userId}";
|
|
|
$data = RedisService::get($cacheKey);
|
|
|
- if ($data || RedisService::exists($cacheKey)) {
|
|
|
+ if($data || RedisService::exists($cacheKey)){
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- $data = $this->model->where(['user_id' => $userId, 'status' => 2, 'mark' => 1])->value('id');
|
|
|
- if ($data) {
|
|
|
- RedisService::set($cacheKey, $data, rand(3600, 7200));
|
|
|
+ $data = $this->model->where(['user_id'=> $userId,'status'=> 2,'mark'=>1])->value('id');
|
|
|
+ if($data){
|
|
|
+ RedisService::set($cacheKey, $data, rand(3600,7200));
|
|
|
}
|
|
|
return $data;
|
|
|
}
|
|
|
@@ -140,12 +138,12 @@ class PledgeOrderService extends BaseService
|
|
|
{
|
|
|
$cacheKey = "caches:pledge:check_exists_{$userId}";
|
|
|
$data = RedisService::get($cacheKey);
|
|
|
- if ($data || RedisService::exists($cacheKey)) {
|
|
|
+ if($data || RedisService::exists($cacheKey)){
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- $data = $this->model->where(['user_id' => $userId, 'mark' => 1])->value('id');
|
|
|
- if ($data) {
|
|
|
+ $data = $this->model->where(['user_id'=> $userId,'mark'=>1])->value('id');
|
|
|
+ if($data){
|
|
|
RedisService::set($cacheKey, $data, 600);
|
|
|
}
|
|
|
return $data;
|
|
|
@@ -160,52 +158,20 @@ class PledgeOrderService extends BaseService
|
|
|
{
|
|
|
$cacheKey = "caches:pledge:check_{$userId}";
|
|
|
$data = RedisService::get($cacheKey);
|
|
|
- if ($data) {
|
|
|
+ if($data){
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- $data = $this->model->where(['user_id' => $userId, 'mark' => 1])
|
|
|
- ->where(function ($query) {
|
|
|
- $query->where('expired_at', '>', date('Y-m-d H:i:s'))
|
|
|
- ->orWhere(['status' => 1]);
|
|
|
+ $data = $this->model->where(['user_id'=> $userId,'mark'=>1])
|
|
|
+ ->where(function($query){
|
|
|
+ $query->where('expired_at','>', date('Y-m-d H:i:s'))
|
|
|
+ ->orWhere(['status'=>1]);
|
|
|
})
|
|
|
- ->select(['id', 'user_id', 'order_no', 'money', 'expired_at', 'status'])
|
|
|
+ ->select(['id','user_id','order_no','money','expired_at','status'])
|
|
|
->first();
|
|
|
|
|
|
- $data = $data ? $data->toArray() : [];
|
|
|
- if ($data) {
|
|
|
- RedisService::set($cacheKey, $data, rand(300, 600));
|
|
|
- }
|
|
|
-
|
|
|
- return $data;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 验证质押订单状态
|
|
|
- * @param $userId 质押用户
|
|
|
- * @param $time 时间间隔/分钟
|
|
|
- * @return array|mixed
|
|
|
- */
|
|
|
- public function checLastPledge(int $userId, $time)
|
|
|
- {
|
|
|
- $cacheKey = "caches:pledge:last_{$userId}_{$time}";
|
|
|
- $data = RedisService::get($cacheKey);
|
|
|
- if ($data) {
|
|
|
- return $data;
|
|
|
- }
|
|
|
-
|
|
|
- $data = $this->model->where(['user_id' => $userId, 'mark' => 1])
|
|
|
- ->where(function ($query) {
|
|
|
- $query->where('expired_at', '>', date('Y-m-d H:i:s'))
|
|
|
- ->orWhere(['status' => 1]);
|
|
|
- })
|
|
|
- ->where('create_time', '>', (time() - intval(floatval($time) * 60)))
|
|
|
- ->select(['id', 'user_id', 'order_no', 'money', 'expired_at', 'status'])
|
|
|
- ->orderBy('create_time', 'desc')
|
|
|
- ->first();
|
|
|
-
|
|
|
- $data = $data ? $data->toArray() : [];
|
|
|
- if ($data) {
|
|
|
+ $data = $data? $data->toArray() :[];
|
|
|
+ if($data){
|
|
|
RedisService::set($cacheKey, $data, rand(300, 600));
|
|
|
}
|
|
|
|
|
|
@@ -219,137 +185,129 @@ class PledgeOrderService extends BaseService
|
|
|
*/
|
|
|
public function autoMakeOrder($userInfo)
|
|
|
{
|
|
|
- $userId = isset($userInfo['id']) ? intval($userInfo['id']) : 0;
|
|
|
- $pledgeAuto = isset($userInfo['pledge_auto']) ? intval($userInfo['pledge_auto']) : 0;
|
|
|
- $userUsdt = isset($userInfo['usdt']) ? floatval($userInfo['usdt']) : 0;
|
|
|
- $userSbt = isset($userInfo['sbt']) ? floatval($userInfo['sbt']) : 0;
|
|
|
- $tradeStatus = isset($userInfo['trade_status']) ? intval($userInfo['trade_status']) : 0;
|
|
|
- $userStatus = isset($userInfo['status']) ? intval($userInfo['status']) : 0;
|
|
|
- $parentIds = isset($userInfo['parent_ids']) ? trim($userInfo['parent_ids']) : '';
|
|
|
- $settleStatus = isset($userInfo['settle_status']) ? intval($userInfo['settle_status']) : 0;
|
|
|
- $settleStatus = $settleStatus == 2 ? 2 : 1; // 1-正常结算,2-不结算动态和个人业绩
|
|
|
- if ($userId <= 0 || $userUsdt <= 0 || $userStatus != 1) {
|
|
|
- $this->error = lang(4101, ['uid' => $userId, 'usdt' => $userUsdt, 'status' => $userStatus]);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- if ($userUsdt <= 0) {
|
|
|
- $this->error = lang(4112, ['uid' => $userId]);
|
|
|
+ $userId = isset($userInfo['id'])? intval($userInfo['id']) : 0;
|
|
|
+ $pledgeAuto = isset($userInfo['pledge_auto'])? intval($userInfo['pledge_auto']) : 0;
|
|
|
+ $userUsdt = isset($userInfo['usdt'])? floatval($userInfo['usdt']) : 0;
|
|
|
+ $userSbt = isset($userInfo['sbt'])? floatval($userInfo['sbt']) : 0;
|
|
|
+ $tradeStatus = isset($userInfo['trade_status'])? intval($userInfo['trade_status']) : 0;
|
|
|
+ $userStatus = isset($userInfo['status'])? intval($userInfo['status']) : 0;
|
|
|
+ $parentIds = isset($userInfo['parent_ids'])? trim($userInfo['parent_ids']) : '';
|
|
|
+ $settleStatus = isset($userInfo['settle_status'])? intval($userInfo['settle_status']) : 0;
|
|
|
+ $settleStatus = $settleStatus==2? 2 : 1; // 1-正常结算,2-不结算动态和个人业绩
|
|
|
+ if($userId<=0 || $userUsdt<=0 || $userStatus != 1){
|
|
|
+ $this->error = lang(4101,['uid'=>$userId,'usdt'=>$userUsdt,'status'=>$userStatus]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 检测是否已经开启了自动质押
|
|
|
- if ($pledgeAuto != 1 || $tradeStatus == 2) {
|
|
|
- $this->error = lang(4104, ['uid' => $userId]);
|
|
|
+ if($pledgeAuto != 1 || $tradeStatus == 2){
|
|
|
+ $this->error = 4104;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 质押所需USDT验证
|
|
|
$pledgeUsdt = ConfigService::make()->getConfigByCode('pledge_money', 500);
|
|
|
- $pledgeUsdt = $pledgeUsdt > 0 ? $pledgeUsdt : 500;
|
|
|
- if ($userUsdt < $pledgeUsdt) {
|
|
|
- $this->error = lang(4102, ['uid' => $userId, 'usdt' => $userUsdt, 'money' => $pledgeUsdt]);
|
|
|
+ $pledgeUsdt = $pledgeUsdt>0?$pledgeUsdt: 500;
|
|
|
+ if($userUsdt < $pledgeUsdt){
|
|
|
+ $this->error = lang(4102,['usdt'=> $userUsdt,'money'=>$pledgeUsdt]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// SBT 手续费
|
|
|
$sbtPrice = PriceLogService::make()->getSbtPrice();
|
|
|
$sbtUsdtFee = ConfigService::make()->getConfigByCode('pledge_sbt_usdt_fee', 0);
|
|
|
- $sbtUsdtFee = $sbtUsdtFee > 0 ? floatval($sbtUsdtFee) : 0;
|
|
|
- $sbtFee = $sbtUsdtFee && $sbtPrice > 0 ? moneyFormat($sbtUsdtFee / $sbtPrice, 2) : 0;
|
|
|
- if ($sbtUsdtFee > 0 && $sbtFee > 0 && $userSbt < $sbtFee) {
|
|
|
- $this->error = lang(4103, ['uid' => $userId, 'sbt' => $userSbt, 'fee' => $sbtFee]);
|
|
|
+ $sbtUsdtFee = $sbtUsdtFee>0? floatval($sbtUsdtFee): 0;
|
|
|
+ $sbtFee = $sbtUsdtFee && $sbtPrice>0? moneyFormat($sbtUsdtFee / $sbtPrice,2) : 0;
|
|
|
+ if($sbtUsdtFee>0 && $sbtFee>0 && $userSbt < $sbtFee){
|
|
|
+ $this->error = lang(4103,['sbt'=> $userSbt,'fee'=>$sbtFee]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 质押收益比例参数
|
|
|
- $profitRate = ConfigService::make()->getConfigByCode('pledge_profit_rate', 3);
|
|
|
- $profitRate = $profitRate > 0 && $profitRate < 100 ? floatval($profitRate) : 3;
|
|
|
- $bonusUsdtRate = ConfigService::make()->getConfigByCode('bonus_usdt_rate', 80);
|
|
|
- $bonusUsdtRate = $bonusUsdtRate > 0 && $bonusUsdtRate < 100 ? floatval($bonusUsdtRate) : 80;
|
|
|
-
|
|
|
- // 校验是否可以下一轮
|
|
|
- $time = ConfigService::make()->getConfigByCode('pledge_next_time', 2);
|
|
|
- $time = $time > 0 && $time <= 30 * 24 * 60 ? $time : 2;
|
|
|
- if ($lastInfo = $this->checLastPledge($userId, $time)) {
|
|
|
- $orderNo = isset($lastInfo['order_no']) ? $lastInfo['order_no'] : '';
|
|
|
- $this->error = lang(4105, ['uid' => $userId, 'time' => $time, 'order_no' => $orderNo]);
|
|
|
+ $profitRate = ConfigService::make()->getConfigByCode('pledge_profit_rate',3);
|
|
|
+ $profitRate = $profitRate>0 && $profitRate<100? floatval($profitRate) : 3;
|
|
|
+ $bonusUsdtRate = ConfigService::make()->getConfigByCode('bonus_usdt_rate',80);
|
|
|
+ $bonusUsdtRate = $bonusUsdtRate>0 && $bonusUsdtRate<100? floatval($bonusUsdtRate) : 80;
|
|
|
+
|
|
|
+ // 检测是否有质押中订单
|
|
|
+ if($info = PledgeOrderService::make()->checHasPledge($userId)){
|
|
|
+ $orderNo = isset($info['order_no'])? $info['order_no'] : '';
|
|
|
+ $this->error = lang(4105,['order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 预计收益
|
|
|
- $profit = moneyFormat($pledgeUsdt * $profitRate / 100, 2); // 总收益
|
|
|
- $profitUsdt = moneyFormat($profit * $bonusUsdtRate / 100, 2); // USDT余额进账部分
|
|
|
+ $profit = moneyFormat($pledgeUsdt * $profitRate/100, 2); // 总收益
|
|
|
+ $profitUsdt = moneyFormat($profit * $bonusUsdtRate/100, 2); // USDT余额进账部分
|
|
|
|
|
|
// 质押有效期
|
|
|
$pledgeTime = ConfigService::make()->getConfigByCode('pledge_time', 24);
|
|
|
- $pledgeTime = $pledgeTime > 0 && $pledgeTime < 30 * 24 ? floatval($pledgeTime) : 24;
|
|
|
+ $pledgeTime = $pledgeTime>0 && $pledgeTime < 30 * 24? floatval($pledgeTime) : 24;
|
|
|
$expiredAt = date('Y-m-d H:i:s', time() + intval($pledgeTime * 3600));
|
|
|
|
|
|
// 结算时间
|
|
|
- $pledgeSettleTime = ConfigService::make()->getConfigByCode('pledge_settle_time', 0);
|
|
|
- $pledgeSettleTime = $pledgeSettleTime >= 0 && $pledgeSettleTime < 30 * 24 ? floatval($pledgeSettleTime) : 24;
|
|
|
+ $pledgeSettleTime = ConfigService::make()->getConfigByCode('pledge_settle_time', 24);
|
|
|
+ $pledgeSettleTime = $pledgeSettleTime>0 && $pledgeSettleTime < 30 * 24? floatval($pledgeSettleTime) : 24;
|
|
|
$settleAt = date('Y-m-d H:i:s', time() + intval($pledgeTime * 3600) + intval($pledgeSettleTime * 3600));
|
|
|
|
|
|
// 质押轮次
|
|
|
- $lastRound = $this->model->where(['user_id' => $userId, 'mark' => 1])
|
|
|
- ->orderBy('round', 'desc')
|
|
|
- ->orderBy('create_time', 'desc')
|
|
|
+ $lastRound = $this->model->where(['user_id'=> $userId,'mark'=>1])
|
|
|
+ ->orderBy('round','desc')
|
|
|
+ ->orderBy('create_time','desc')
|
|
|
->value('round');
|
|
|
- $round = $lastRound > 0 ? intval($lastRound) + 1 : 1;
|
|
|
+ $round = $lastRound>0? intval($lastRound) + 1 : 1;
|
|
|
|
|
|
// 缓存锁
|
|
|
- if (RedisService::get("caches:pledge:lock_{$userId}_{$round}")) {
|
|
|
- $this->error = lang(4111, ['uid' => $userId, 'round' => $round]);
|
|
|
+ if(RedisService::get("caches:pledge:lock_{$userId}_{$round}")){
|
|
|
+ $this->error = lang(4111,['uid'=> $userId,'round'=> $round]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 若满足自动质押条件
|
|
|
DB::beginTransaction();
|
|
|
- RedisService::set("caches:pledge:lock_{$userId}_{$round}", rand(60, 120));
|
|
|
- try {
|
|
|
+ RedisService::set("caches:pledge:lock_{$userId}_{$round}",rand(60,120));
|
|
|
+ try{
|
|
|
// TODO 质押订单
|
|
|
$order = [
|
|
|
- 'user_id' => $userId,
|
|
|
- 'order_no' => get_order_num('PD'),
|
|
|
- 'money' => $pledgeUsdt,
|
|
|
- 'bonus_rate' => $profitRate,
|
|
|
- 'profit' => $profit,
|
|
|
- 'profit_usdt' => $profitUsdt,
|
|
|
- 'sbt_price' => $sbtPrice,
|
|
|
- 'time' => $pledgeTime,
|
|
|
- 'round' => $round,
|
|
|
- 'expired_at' => $expiredAt,
|
|
|
- 'settle_at' => $settleAt,
|
|
|
- 'settle_status' => $settleStatus, // 1-正常结算,2-不结算动态和个人业绩
|
|
|
- 'create_time' => time(),
|
|
|
- 'remark' => '自动质押',
|
|
|
- 'status' => 1,
|
|
|
- 'mark' => 1,
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'order_no'=> get_order_num('PD'),
|
|
|
+ 'money'=> $pledgeUsdt,
|
|
|
+ 'bonus_rate'=> $profitRate,
|
|
|
+ 'profit'=> $profit,
|
|
|
+ 'profit_usdt'=> $profitUsdt,
|
|
|
+ 'sbt_price'=> $sbtPrice,
|
|
|
+ 'time'=> $pledgeTime,
|
|
|
+ 'round'=> $round,
|
|
|
+ 'expired_at'=> $expiredAt,
|
|
|
+ 'settle_at'=> $settleAt,
|
|
|
+ 'settle_status'=> $settleStatus, // 1-正常结算,2-不结算动态和个人业绩
|
|
|
+ 'create_time'=>time(),
|
|
|
+ 'remark'=> '自动质押',
|
|
|
+ 'status'=>1,
|
|
|
+ 'mark'=>1,
|
|
|
];
|
|
|
- if (!$this->model->insertGetId($order)) {
|
|
|
+ if(!$this->model->insertGetId($order)){
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4106, ['uid' => $userId, 'round' => $round]);
|
|
|
+ $this->error = lang(4106,['uid'=> $userId,'round'=> $round]);
|
|
|
RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 扣除余额和手续费
|
|
|
$updateData = [
|
|
|
- 'usdt' => DB::raw("usdt - {$pledgeUsdt}"),
|
|
|
- 'upgrade_at' => date('Y-m-d H:i:s', time() + 2 * 86400),
|
|
|
- 'pledge_count' => DB::raw("pledge_count + 1"),
|
|
|
- 'sbt' => DB::raw("sbt - {$sbtFee}"),
|
|
|
- 'last_pledge_at' => date('Y-m-d H:i:s'),
|
|
|
- 'update_time' => time()
|
|
|
+ 'usdt'=> DB::raw("usdt - {$pledgeUsdt}"),
|
|
|
+ 'upgrade_at'=>date('Y-m-d H:i:s',time() + 2*86400),
|
|
|
+ 'pledge_count'=>DB::raw("pledge_count + 1"),
|
|
|
+ 'sbt'=>DB::raw("sbt - {$sbtFee}"),
|
|
|
+ 'update_time'=>time()
|
|
|
];
|
|
|
// 正常结算业绩
|
|
|
- if ($settleStatus == 1) {
|
|
|
+ if($settleStatus==1){
|
|
|
$updateData['performance'] = DB::raw("performance + {$pledgeUsdt}");
|
|
|
}
|
|
|
- if (!MemberModel::where(['id' => $userId])->update($updateData)) {
|
|
|
+ if(!MemberModel::where(['id'=> $userId])->update($updateData)){
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4107, ['uid' => $userId, 'round' => $round, 'money' => $pledgeUsdt]);
|
|
|
+ $this->error = lang(4107,['uid'=> $userId,'round'=>$round,'money'=> $pledgeUsdt]);
|
|
|
RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
|
|
|
return false;
|
|
|
}
|
|
|
@@ -373,13 +331,13 @@ class PledgeOrderService extends BaseService
|
|
|
|
|
|
if (!AccountLogModel::insertGetId($data)) {
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4108, ['uid' => $userId, 'round' => $round, 'money' => $pledgeUsdt]);
|
|
|
+ $this->error = lang(4108,['uid'=> $userId,'round'=>$round,'money'=> $pledgeUsdt]);
|
|
|
RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// SBT 手续费
|
|
|
- if ($sbtFee) {
|
|
|
+ if($sbtFee){
|
|
|
$data = [
|
|
|
'user_id' => $userId,
|
|
|
'order_no' => $order['order_no'],
|
|
|
@@ -398,7 +356,7 @@ class PledgeOrderService extends BaseService
|
|
|
|
|
|
if (!AccountLogModel::insertGetId($data)) {
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4108, ['uid' => $userId, 'round' => $round]);
|
|
|
+ $this->error = lang(4108,['uid'=> $userId,'round'=>$round]);
|
|
|
RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
|
|
|
return false;
|
|
|
}
|
|
|
@@ -408,35 +366,28 @@ class PledgeOrderService extends BaseService
|
|
|
|
|
|
// 更新上级团队用户的等级更新时间
|
|
|
$parentIds = get_parents($parentIds);
|
|
|
- if ($parentIds) {
|
|
|
- MemberModel::whereIn('id', $parentIds)->update(['upgrade_at' => date('Y-m-d H:i:s', time() + 2 * 86400), 'update_time' => time()]);
|
|
|
+ if($parentIds){
|
|
|
+ MemberModel::whereIn('id', $parentIds)->update(['upgrade_at'=>date('Y-m-d H:i:s',time() + 2*86400),'update_time'=>time()]);
|
|
|
}
|
|
|
|
|
|
// 质押轮次奖励
|
|
|
FinanceService::make()->pledgeAward($userId, $round, $order);
|
|
|
|
|
|
- // TODO 是否结算动态收益
|
|
|
- if ($settleStatus == 1) {
|
|
|
- // 团队分红结算
|
|
|
- if (!FinanceService::make()->settleTeamBonus($userId, $parentIds, $order)) {
|
|
|
- RedisService::set("caches:pledgeOrder:team_bonus_{$order['order_no']}", ['uid' => $userId, 'parentIds' => $parentIds, 'order' => $order, 'error' => FinanceService::make()->getError()], 600);
|
|
|
- }
|
|
|
+ // 团队分红结算
|
|
|
+ FinanceService::make()->settleTeamBonus($userId, $parentIds, $order);
|
|
|
|
|
|
- // 工作室分红结算
|
|
|
- if (!FinanceService::make()->settleRoomBonus($userId, $parentIds, $order)) {
|
|
|
- RedisService::set("caches:pledgeOrder:room_bonus_{$order['order_no']}", ['uid' => $userId, 'parentIds' => $parentIds, 'order' => $order, 'error' => FinanceService::make()->getError()], 600);
|
|
|
- }
|
|
|
- }
|
|
|
+ // 工作室分红结算
|
|
|
+ FinanceService::make()->settleRoomBonus($userId, $parentIds, $order);
|
|
|
|
|
|
- $this->error = $this->error = lang(4109, ['uid' => $userId, 'round' => $round]);
|
|
|
+ $this->error = $this->error = lang(4109,['uid'=> $userId,'round'=>$round]);
|
|
|
RedisService::clear("caches:pledge:lock_{$userId}_{$round}");
|
|
|
RedisService::clear("caches:pledgeOrder:total_{$userId}");
|
|
|
RedisService::clear("caches:pledge:check_{$userId}");
|
|
|
RedisService::clear("caches:pledge:counts_{$userId}");
|
|
|
- return ['user_id' => $userId, 'round' => $round, 'money' => $pledgeUsdt, 'settleStatus' => $settleStatus, 'msg' => '自动质押成功'];
|
|
|
- } catch (\Exception $exception) {
|
|
|
+ return ['user_id'=>$userId,'round'=>$round,'money'=>$pledgeUsdt,'msg'=>'自动质押成功'];
|
|
|
+ } catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4110, ['uid' => $userId, 'round' => $round, 'error' => $exception->getMessage()]);
|
|
|
+ $this->error = lang(4110,['uid'=> $userId,'round'=>$round,'error'=> $exception->getMessage()]);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -450,16 +401,16 @@ class PledgeOrderService extends BaseService
|
|
|
try {
|
|
|
$limit = ConfigService::make()->getConfigByCode('refund_pledge_count', 500);
|
|
|
$limit = $limit > 0 ? $limit : 500;
|
|
|
- $datas = $this->model->where(function ($query) {
|
|
|
- $query->where('expired_at', '<=', date('Y-m-d H:i:s'));
|
|
|
- })
|
|
|
+ $datas = $this->model->where(function($query){
|
|
|
+ $query->where('expired_at', '<=', date('Y-m-d H:i:s'));
|
|
|
+ })
|
|
|
->where(['status' => 1, 'mark' => 1])
|
|
|
- ->select(['id', 'user_id', 'order_no', 'money', 'status'])
|
|
|
+ ->select(['id','user_id', 'order_no','money','status'])
|
|
|
->limit($limit)
|
|
|
->orderByRaw('rand()')
|
|
|
->orderBy('expired_at', 'asc')
|
|
|
->get();
|
|
|
- return $datas ? $datas->toArray() : [];
|
|
|
+ return $datas?$datas->toArray() : [];
|
|
|
} catch (\Exception $exception) {
|
|
|
$this->error = $exception->getMessage();
|
|
|
return false;
|
|
|
@@ -475,16 +426,16 @@ class PledgeOrderService extends BaseService
|
|
|
try {
|
|
|
$limit = ConfigService::make()->getConfigByCode('settle_pledge_count', 500);
|
|
|
$limit = $limit > 0 ? $limit : 500;
|
|
|
- $datas = $this->model->where(function ($query) {
|
|
|
- $query->where('settle_at', '<=', date('Y-m-d H:i:s'));
|
|
|
- })
|
|
|
+ $datas = $this->model->where(function($query){
|
|
|
+ $query->where('settle_at', '<=', date('Y-m-d H:i:s'));
|
|
|
+ })
|
|
|
->where(['status' => 2, 'mark' => 1])
|
|
|
- ->select(['id', 'user_id', 'order_no', 'money', 'status'])
|
|
|
+ ->select(['id','user_id', 'order_no','money','status'])
|
|
|
->limit($limit)
|
|
|
->orderByRaw('rand()')
|
|
|
->orderBy('settle_at', 'asc')
|
|
|
->get();
|
|
|
- return $datas ? $datas->toArray() : [];
|
|
|
+ return $datas?$datas->toArray() : [];
|
|
|
} catch (\Exception $exception) {
|
|
|
$this->error = $exception->getMessage();
|
|
|
return false;
|
|
|
@@ -495,79 +446,79 @@ class PledgeOrderService extends BaseService
|
|
|
* 自动退本
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public function refund($orderId, $orderNo, $userId = 0)
|
|
|
+ public function refund($orderId,$orderNo, $userId=0)
|
|
|
{
|
|
|
$cacheKey = "caches:pledgeOrder:refund_{$orderId}";
|
|
|
- if (RedisService::get($cacheKey)) {
|
|
|
- $this->error = lang(4310, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ if(RedisService::get($cacheKey)){
|
|
|
+ $this->error = lang(4310,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 订单信息
|
|
|
- $orderInfo = $this->model::where(['id' => $orderId, 'mark' => 1])
|
|
|
- ->select(['id', 'user_id', 'order_no', 'money', 'round', 'bonus_rate', 'profit', 'profit_usdt', 'expired_at', 'status'])
|
|
|
+ $orderInfo = $this->model::where(['id'=> $orderId,'mark'=>1])
|
|
|
+ ->select(['id','user_id','order_no','money','round','bonus_rate','profit','profit_usdt','expired_at','status'])
|
|
|
->first();
|
|
|
- $orderInfo = $orderInfo ? $orderInfo->toArray() : [];
|
|
|
- if (empty($orderInfo)) {
|
|
|
- $this->error = lang(4311, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $orderInfo = $orderInfo? $orderInfo->toArray() : [];
|
|
|
+ if(empty($orderInfo)){
|
|
|
+ $this->error = lang(4311,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 状态验证
|
|
|
- $expiredAt = isset($orderInfo['expired_at']) ? $orderInfo['expired_at'] : '';
|
|
|
- $status = isset($orderInfo['status']) ? $orderInfo['status'] : 0;
|
|
|
- $pledgeUserId = isset($orderInfo['user_id']) ? $orderInfo['user_id'] : 0;
|
|
|
- $pledgeUsdt = isset($orderInfo['money']) ? floatval($orderInfo['money']) : 0;
|
|
|
- $pledgeRound = isset($orderInfo['round']) ? intval($orderInfo['round']) : 0;
|
|
|
- $settleStatus = isset($orderInfo['settle_status']) ? intval($orderInfo['settle_status']) : 0;
|
|
|
- $settleStatus = $settleStatus == 2 ? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
|
|
|
- if ($expiredAt > date('Y-m-d H:i:s') || $status != 1 || $pledgeRound <= 0) {
|
|
|
- $this->error = lang(4312, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $expiredAt = isset($orderInfo['expired_at'])? $orderInfo['expired_at'] : '';
|
|
|
+ $status = isset($orderInfo['status'])? $orderInfo['status'] : 0;
|
|
|
+ $pledgeUserId = isset($orderInfo['user_id'])? $orderInfo['user_id'] : 0;
|
|
|
+ $pledgeUsdt = isset($orderInfo['money'])? floatval($orderInfo['money']) : 0;
|
|
|
+ $pledgeRound = isset($orderInfo['round'])? intval($orderInfo['round']) : 0;
|
|
|
+ $settleStatus = isset($orderInfo['settle_status'])? intval($orderInfo['settle_status']) : 0;
|
|
|
+ $settleStatus = $settleStatus==2? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
|
|
|
+ if($expiredAt>date('Y-m-d H:i:s') || $status != 1 || $pledgeRound<=0){
|
|
|
+ $this->error = lang(4312,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 退本金额
|
|
|
- if ($pledgeUsdt <= 0) {
|
|
|
- $this->error = lang(4316, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ if($pledgeUsdt<=0){
|
|
|
+ $this->error = lang(4316,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 质押用户信息
|
|
|
- $memberInfo = MemberModel::where(['id' => $pledgeUserId, 'mark' => 1])
|
|
|
- ->select(['id', 'usdt', 'sbt', 'profit', 'performance', 'pledge_count', 'status'])
|
|
|
+ $memberInfo = MemberModel::where(['id'=> $pledgeUserId,'mark'=>1])
|
|
|
+ ->select(['id','usdt','sbt','profit','performance','pledge_count','status'])
|
|
|
->first();
|
|
|
- $memberInfo = $memberInfo ? $memberInfo->toArray() : [];
|
|
|
- $userUsdt = isset($memberInfo['usdt']) ? $memberInfo['usdt'] : 0;
|
|
|
- $performance = isset($memberInfo['performance']) ? $memberInfo['performance'] : 0;
|
|
|
- $pledgeCount = isset($memberInfo['pledge_count']) ? $memberInfo['pledge_count'] : 0;
|
|
|
- if (empty($memberInfo) || $pledgeUserId != $userId) {
|
|
|
- $this->error = lang(4313, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $memberInfo = $memberInfo? $memberInfo->toArray() : [];
|
|
|
+ $userUsdt = isset($memberInfo['usdt'])? $memberInfo['usdt'] : 0;
|
|
|
+ $performance = isset($memberInfo['performance'])? $memberInfo['performance'] : 0;
|
|
|
+ $pledgeCount = isset($memberInfo['pledge_count'])? $memberInfo['pledge_count'] : 0;
|
|
|
+ if(empty($memberInfo) || $pledgeUserId != $userId){
|
|
|
+ $this->error = lang(4313,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 订单退本处理
|
|
|
DB::beginTransaction();
|
|
|
- try {
|
|
|
+ try{
|
|
|
// 更新订单状态
|
|
|
- if (!$this->model->where(['id' => $orderId])->update(['status' => 2, 'refund_at' => date('Y-m-d H:i:s'), 'update_time' => time()])) {
|
|
|
+ if(!$this->model->where(['id'=> $orderId])->update(['status'=>2,'refund_at'=>date('Y-m-d H:i:s'),'update_time'=>time()])){
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4314, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $this->error = lang(4314,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 返还本金
|
|
|
$updateData = [
|
|
|
- 'usdt' => DB::raw("usdt + {$pledgeUsdt}"),
|
|
|
- 'pledge_count' => max(0, ($pledgeCount - 1)),
|
|
|
- 'update_time' => time()
|
|
|
+ 'usdt'=>DB::raw("usdt + {$pledgeUsdt}"),
|
|
|
+ 'pledge_count'=>max(0,($pledgeCount - 1)),
|
|
|
+ 'update_time'=>time()
|
|
|
];
|
|
|
// 正常结算业绩
|
|
|
- if ($settleStatus == 1) {
|
|
|
- $updateData['performance'] = max(0, ($performance - $pledgeUsdt));
|
|
|
+ if($settleStatus == 1){
|
|
|
+ $updateData['performance'] = max(0,($performance - $pledgeUsdt));
|
|
|
}
|
|
|
- if (!MemberModel::where(['id' => $pledgeUserId])->update($updateData)) {
|
|
|
+ if(!MemberModel::where(['id'=>$pledgeUserId])->update($updateData)){
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4315, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $this->error = lang(4315,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -590,17 +541,17 @@ class PledgeOrderService extends BaseService
|
|
|
|
|
|
if (!AccountLogModel::insertGetId($data)) {
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4317, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $this->error = lang(4317,['uid'=> $userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
|
- $this->error = lang(4318, ['uid' => $userId, 'order_no' => $orderNo, 'performance' => $pledgeUsdt]);
|
|
|
- $order = ['user_id' => $userId, 'round' => $pledgeRound, 'performance' => $pledgeUsdt, 'order_no' => $orderNo];
|
|
|
+ $this->error = lang(4318,['uid'=> $userId,'order_no'=>$orderNo,'performance'=>$pledgeUsdt]);
|
|
|
+ $order = ['user_id'=>$userId,'round'=>$pledgeRound,'performance'=>$pledgeUsdt,'order_no'=>$orderNo];
|
|
|
RedisService::set($cacheKey, $order, rand(300, 600));
|
|
|
RedisService::clear("caches:pledge:check_{$userId}");
|
|
|
return $order;
|
|
|
- } catch (\Exception $exception) {
|
|
|
+ }catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
|
$this->error = $exception->getMessage();
|
|
|
return false;
|
|
|
@@ -611,85 +562,85 @@ class PledgeOrderService extends BaseService
|
|
|
* 到期结算收益
|
|
|
* @return bool
|
|
|
*/
|
|
|
- public function orderSettle($orderId, $orderNo, $userId = 0)
|
|
|
+ public function orderSettle($orderId, $orderNo, $userId=0)
|
|
|
{
|
|
|
$cacheKey = "caches:pledgeOrder:settle_{$orderId}";
|
|
|
- if (RedisService::get($cacheKey)) {
|
|
|
- $this->error = lang(4410, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ if(RedisService::get($cacheKey)){
|
|
|
+ $this->error = lang(4410,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 订单信息
|
|
|
- $orderInfo = $this->model::where(['id' => $orderId, 'mark' => 1])
|
|
|
- ->select(['id', 'user_id', 'order_no', 'money', 'round', 'bonus_rate', 'sbt_price', 'profit', 'profit_usdt', 'settle_at', 'settle_status', 'status'])
|
|
|
+ $orderInfo = $this->model::where(['id'=> $orderId,'mark'=>1])
|
|
|
+ ->select(['id','user_id','order_no','money','round','bonus_rate','sbt_price','profit','profit_usdt','settle_at','settle_status','status'])
|
|
|
->first();
|
|
|
- $orderInfo = $orderInfo ? $orderInfo->toArray() : [];
|
|
|
- if (empty($orderInfo)) {
|
|
|
- $this->error = lang(4411, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $orderInfo = $orderInfo? $orderInfo->toArray() : [];
|
|
|
+ if(empty($orderInfo)){
|
|
|
+ $this->error = lang(4411,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 状态验证
|
|
|
- $settleAt = isset($orderInfo['settle_at']) ? $orderInfo['settle_at'] : '';
|
|
|
- $status = isset($orderInfo['status']) ? $orderInfo['status'] : 0;
|
|
|
- $pledgeUserId = isset($orderInfo['user_id']) ? $orderInfo['user_id'] : 0; // 质押用户
|
|
|
- $pledgeUsdt = isset($orderInfo['money']) ? floatval($orderInfo['money']) : 0; // 质押金额
|
|
|
- $profit = isset($orderInfo['profit']) ? floatval($orderInfo['profit']) : 0; // 总收益
|
|
|
- $profitUsdt = isset($orderInfo['profit_usdt']) ? floatval($orderInfo['profit_usdt']) : 0; // USDT收益
|
|
|
- $pledgeRound = isset($orderInfo['round']) ? intval($orderInfo['round']) : 0;
|
|
|
- $settleStatus = isset($orderInfo['settle_status']) ? intval($orderInfo['settle_status']) : 0;
|
|
|
- $settleStatus = $settleStatus == 2 ? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
|
|
|
- if ($settleAt > date('Y-m-d H:i:s') || $status != 2 || $pledgeRound <= 0) {
|
|
|
- $this->error = lang(4412, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $settleAt = isset($orderInfo['settle_at'])? $orderInfo['settle_at'] : '';
|
|
|
+ $status = isset($orderInfo['status'])? $orderInfo['status'] : 0;
|
|
|
+ $pledgeUserId = isset($orderInfo['user_id'])? $orderInfo['user_id'] : 0; // 质押用户
|
|
|
+ $pledgeUsdt = isset($orderInfo['money'])? floatval($orderInfo['money']) : 0; // 质押金额
|
|
|
+ $profit = isset($orderInfo['profit'])? floatval($orderInfo['profit']) : 0; // 总收益
|
|
|
+ $profitUsdt = isset($orderInfo['profit_usdt'])? floatval($orderInfo['profit_usdt']) : 0; // USDT收益
|
|
|
+ $pledgeRound = isset($orderInfo['round'])? intval($orderInfo['round']) : 0;
|
|
|
+ $settleStatus = isset($orderInfo['settle_status'])? intval($orderInfo['settle_status']) : 0;
|
|
|
+ $settleStatus = $settleStatus==2? 2 : 1; // 结算动态收益状态:1-正常,2-不结算动态
|
|
|
+ if($settleAt>date('Y-m-d H:i:s') || $status != 2 || $pledgeRound<=0){
|
|
|
+ $this->error = lang(4412,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 质押收益金额
|
|
|
- if ($pledgeUsdt <= 0 || $profit <= 0 || ($profit < $profitUsdt)) {
|
|
|
- $this->error = lang(4416, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ if($pledgeUsdt<=0 || $profit <=0 || ($profit < $profitUsdt)){
|
|
|
+ $this->error = lang(4416,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 质押用户信息
|
|
|
- $memberInfo = MemberModel::where(['id' => $pledgeUserId, 'mark' => 1])
|
|
|
- ->select(['id', 'usdt', 'sbt', 'profit', 'performance', 'parent_ids', 'status'])
|
|
|
+ $memberInfo = MemberModel::where(['id'=> $pledgeUserId,'mark'=>1])
|
|
|
+ ->select(['id','usdt','sbt','profit','performance','parent_ids','status'])
|
|
|
->first();
|
|
|
- $memberInfo = $memberInfo ? $memberInfo->toArray() : [];
|
|
|
- $userUsdt = isset($memberInfo['usdt']) ? $memberInfo['usdt'] : 0;
|
|
|
- $userProfit = isset($memberInfo['profit']) ? $memberInfo['profit'] : 0;
|
|
|
- $userSbt = isset($memberInfo['sbt']) ? $memberInfo['sbt'] : 0;
|
|
|
- $parentIds = isset($memberInfo['parent_ids']) ? $memberInfo['parent_ids'] : '';
|
|
|
- if (empty($memberInfo) || $pledgeUserId != $userId) {
|
|
|
- $this->error = lang(4413, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $memberInfo = $memberInfo? $memberInfo->toArray() : [];
|
|
|
+ $userUsdt = isset($memberInfo['usdt'])? $memberInfo['usdt'] : 0;
|
|
|
+ $userProfit = isset($memberInfo['profit'])? $memberInfo['profit'] : 0;
|
|
|
+ $userSbt = isset($memberInfo['sbt'])? $memberInfo['sbt'] : 0;
|
|
|
+ $parentIds = isset($memberInfo['parent_ids'])? $memberInfo['parent_ids'] : '';
|
|
|
+ if(empty($memberInfo) || $pledgeUserId != $userId){
|
|
|
+ $this->error = lang(4413,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// SBT 收益金额
|
|
|
$sbtPrice = PriceLogService::make()->getSbtPrice();
|
|
|
- $profitSbt = moneyFormat(($profit - $profitUsdt) / $sbtPrice, 2); // 金本位计算
|
|
|
+ $profitSbt = moneyFormat(($profit - $profitUsdt)/$sbtPrice, 2); // 金本位计算
|
|
|
|
|
|
|
|
|
// 订单收益结算处理
|
|
|
DB::beginTransaction();
|
|
|
- try {
|
|
|
+ try{
|
|
|
// 更新订单状态
|
|
|
- if (!$this->model->where(['id' => $orderId])->update(['status' => 3, 'bonus_at' => date('Y-m-d H:i:s'), 'update_time' => time()])) {
|
|
|
+ if(!$this->model->where(['id'=> $orderId])->update(['status'=>3,'bonus_at'=>date('Y-m-d H:i:s'),'update_time'=>time()])){
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4414, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $this->error = lang(4414,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// USDT收益和SBT收益
|
|
|
$updateData = [
|
|
|
- 'profit' => DB::raw("profit + {$profitUsdt}"),
|
|
|
- 'profit_total' => DB::raw("profit_total + {$profit}"),
|
|
|
- 'pledge_profit' => DB::raw("pledge_profit + {$profit}"),
|
|
|
- 'sbt' => DB::raw("sbt + {$profitSbt}"),
|
|
|
- 'update_time' => time()
|
|
|
+ 'profit'=>DB::raw("profit + {$profitUsdt}"),
|
|
|
+ 'profit_total'=>DB::raw("profit_total + {$profit}"),
|
|
|
+ 'pledge_profit'=>DB::raw("pledge_profit + {$profit}"),
|
|
|
+ 'sbt'=>DB::raw("sbt + {$profitSbt}"),
|
|
|
+ 'update_time'=>time()
|
|
|
];
|
|
|
- if (!MemberModel::where(['id' => $pledgeUserId])->update($updateData)) {
|
|
|
+ if(!MemberModel::where(['id'=>$pledgeUserId])->update($updateData)){
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4415, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $this->error = lang(4415,['uid'=>$userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
@@ -712,12 +663,12 @@ class PledgeOrderService extends BaseService
|
|
|
|
|
|
if (!AccountLogModel::insertGetId($data)) {
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4417, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $this->error = lang(4417,['uid'=> $userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// SBT收益账单
|
|
|
- if ($profitSbt > 0) {
|
|
|
+ if($profitSbt>0){
|
|
|
$data = [
|
|
|
'user_id' => $userId,
|
|
|
'order_no' => $orderNo,
|
|
|
@@ -736,15 +687,15 @@ class PledgeOrderService extends BaseService
|
|
|
|
|
|
if (!AccountLogModel::insertGetId($data)) {
|
|
|
DB::rollBack();
|
|
|
- $this->error = lang(4417, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
+ $this->error = lang(4417,['uid'=> $userId,'order_no'=>$orderNo]);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO 是否结算动态收益
|
|
|
- if ($settleStatus == 1) {
|
|
|
+ if($settleStatus==1){
|
|
|
// TODO 推荐奖结算
|
|
|
- if (!FinanceService::make()->settleShareAward($userId, $parentIds, $orderInfo)) {
|
|
|
+ if(!FinanceService::make()->settleShareAward($userId, $parentIds, $orderInfo)){
|
|
|
DB::rollBack();
|
|
|
$this->error = FinanceService::make()->getError();
|
|
|
return false;
|
|
|
@@ -752,7 +703,7 @@ class PledgeOrderService extends BaseService
|
|
|
|
|
|
|
|
|
// TODO 管理奖和平级奖结算
|
|
|
- if (!FinanceService::make()->settleManageAndLevelAward($userId, $parentIds, $orderInfo)) {
|
|
|
+ if(!FinanceService::make()->settleManageAndLevelAward($userId, $parentIds, $orderInfo)){
|
|
|
DB::rollBack();
|
|
|
$this->error = FinanceService::make()->getError();
|
|
|
return false;
|
|
|
@@ -761,13 +712,13 @@ class PledgeOrderService extends BaseService
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
- $this->error = lang(4418, ['uid' => $userId, 'order_no' => $orderNo]);
|
|
|
- $order = ['user_id' => $userId, 'round' => $pledgeRound, 'profit' => $profit, 'profit_usdt' => $profitUsdt, 'profit_sbt' => $profitSbt, 'order_no' => $orderNo];
|
|
|
+ $this->error = lang(4418,['uid'=> $userId,'order_no'=>$orderNo]);
|
|
|
+ $order = ['user_id'=>$userId,'round'=>$pledgeRound,'profit'=>$profit,'profit_usdt'=>$profitUsdt,'profit_sbt'=>$profitSbt,'order_no'=>$orderNo];
|
|
|
RedisService::set($cacheKey, $order, rand(300, 600));
|
|
|
return $order;
|
|
|
- } catch (\Exception $exception) {
|
|
|
+ }catch (\Exception $exception){
|
|
|
DB::rollBack();
|
|
|
- $this->error = '订单结算异常:' . $exception->getMessage();
|
|
|
+ $this->error = '订单结算异常:'.$exception->getMessage();
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
@@ -780,12 +731,12 @@ class PledgeOrderService extends BaseService
|
|
|
{
|
|
|
$cacheKey = "caches:pledgeOrder:globalTotal";
|
|
|
$data = RedisService::get($cacheKey);
|
|
|
- if ($data) {
|
|
|
+ if($data){
|
|
|
return $data;
|
|
|
}
|
|
|
|
|
|
- $data = $this->model->where(['status' => 1, 'mark' => 1])->sum('money');
|
|
|
- if ($data) {
|
|
|
+ $data = $this->model->where(['status'=>1,'mark'=>1])->sum('money');
|
|
|
+ if($data){
|
|
|
RedisService::set($cacheKey, $data, 600);
|
|
|
}
|
|
|
|