|
@@ -2,14 +2,63 @@
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
|
|
+use App\Constants\HttpStatus;
|
|
|
use App\Models\Backflow;
|
|
use App\Models\Backflow;
|
|
|
use App\Models\Config;
|
|
use App\Models\Config;
|
|
|
use Carbon\Carbon;
|
|
use Carbon\Carbon;
|
|
|
|
|
+use Exception;
|
|
|
|
|
|
|
|
class BackflowService extends BaseService
|
|
class BackflowService extends BaseService
|
|
|
{
|
|
{
|
|
|
public static string $MODEL = Backflow::class;
|
|
public static string $MODEL = Backflow::class;
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public static function findOne(array $search): ?Backflow
|
|
|
|
|
+ {
|
|
|
|
|
+ return self::$MODEL::where(static::getWhere($search))->first();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @param $id
|
|
|
|
|
+ * @return bool
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
|
|
+ public static function grant($id): bool
|
|
|
|
|
+ {
|
|
|
|
|
+ $params = ['id' => $id, 'status' => 0];
|
|
|
|
|
+ $backflow = static::findOne($params);
|
|
|
|
|
+ if (!$backflow) throw new Exception('数据不存在', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ $date = Carbon::now('Asia/Shanghai')->format('Y-m');
|
|
|
|
|
+ if (strtotime($backflow->date) >= strtotime($date)) {
|
|
|
|
|
+ throw new Exception('未到发放时间', HttpStatus::CUSTOM_ERROR);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //回水门槛金额
|
|
|
|
|
+ $restriction = Config::where('field', 'huishui_restriction')->first()->val;
|
|
|
|
|
+ $amount = bcadd($backflow->recharge_amount, $backflow->withdrawal_amount, 2);
|
|
|
|
|
+ $amount = abs($amount);
|
|
|
|
|
+ if ($amount >= $restriction) {
|
|
|
|
|
+ //回水比例
|
|
|
|
|
+ $ratio = Config::where('field', 'huishui_percentage')->first()->val;
|
|
|
|
|
+ $backflow->backflow_ratio = $ratio;
|
|
|
|
|
+ $backflow->amount = bcmul($amount, $backflow->backflow_ratio, 2);
|
|
|
|
|
+ if ($backflow->amount > 0) {
|
|
|
|
|
+ $percentage = bcmul($ratio, 100, 2);//返水比例百分比
|
|
|
|
|
+ $percentage = floatval($percentage);
|
|
|
|
|
+ $res = WalletService::updateBalance($backflow->member_id, $backflow->amount);
|
|
|
|
|
+ BalanceLogService::addLog($backflow->member_id, $backflow->amount, $res['before_balance'], $res['after_balance'], "回水", $backflow->id, "日期:$backflow->date;盈亏:-{$amount};回水比例:$percentage%");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $backflow->amount = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ $backflow->status = 1;
|
|
|
|
|
+ if (false !== $backflow->save()) return true;
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @param $memberId string 会员ID
|
|
* @param $memberId string 会员ID
|
|
|
* @param $changeAmount float 充值或提现金额
|
|
* @param $changeAmount float 充值或提现金额
|
|
@@ -85,8 +134,6 @@ class BackflowService extends BaseService
|
|
|
|
|
|
|
|
$paginator = $query
|
|
$paginator = $query
|
|
|
->with(['user'])->orderByDesc('date')->orderBy('status')
|
|
->with(['user'])->orderByDesc('date')->orderBy('status')
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
->paginate($search['limit']);
|
|
->paginate($search['limit']);
|
|
|
|
|
|
|
|
// $count = $query->count();
|
|
// $count = $query->count();
|