改进
This commit is contained in:
parent
7928fb1efc
commit
24647a7af7
@ -137,9 +137,7 @@ public function cost($price = null)
|
|||||||
|
|
||||||
Cache::put($month_cache_key, $hosts_drops, 604800);
|
Cache::put($month_cache_key, $hosts_drops, 604800);
|
||||||
|
|
||||||
$description = '主机服务 ' . $this->name . ' 扣费。';
|
$transaction->reduceDrops($this->user_id, $this->id, $this->module_id, 1, $this->price);
|
||||||
|
|
||||||
$transaction->reduceDrops($this->user_id, $this->price, $description);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,8 @@ class Transaction extends Model
|
|||||||
'gift_drops',
|
'gift_drops',
|
||||||
|
|
||||||
'user_id',
|
'user_id',
|
||||||
|
'host_id',
|
||||||
|
'module_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
@ -83,12 +85,6 @@ public function getDrops($user_id = null)
|
|||||||
return $drops;
|
return $drops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function reduceCurrentUserDrops($amount = 0)
|
|
||||||
{
|
|
||||||
return $this->reduceDrops(auth()->id(), $amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function increaseCurrentUserDrops($amount = 0)
|
public function increaseCurrentUserDrops($amount = 0)
|
||||||
{
|
{
|
||||||
return $this->increaseDrops(auth()->id(), $amount);
|
return $this->increaseDrops(auth()->id(), $amount);
|
||||||
@ -110,30 +106,32 @@ public function increaseDrops($user_id, $amount = 0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function reduceDrops($user_id, $amount = 0, $description = null)
|
public function reduceDrops($user_id, $host_id, $module_id, $auto = 1, $amount = 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
$cache_key = 'user_drops_' . $user_id;
|
$cache_key = 'user_drops_' . $user_id;
|
||||||
|
|
||||||
$decimal = config('drops.decimal');
|
$decimal = config('drops.decimal');
|
||||||
|
|
||||||
|
|
||||||
$month = now()->month;
|
$month = now()->month;
|
||||||
|
|
||||||
Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount);
|
Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount);
|
||||||
|
|
||||||
$amount = $amount * $decimal;
|
$amount = $amount * $decimal;
|
||||||
|
|
||||||
$drops = Cache::decrement($cache_key, $amount);
|
Cache::decrement($cache_key, $amount);
|
||||||
|
|
||||||
// (new App\Models\Transaction)->create(['name' => 1]);
|
if ($auto) {
|
||||||
|
$description = '平台按时间自动扣费。';
|
||||||
|
} else {
|
||||||
|
$description = '集成模块发起的扣费。';
|
||||||
|
}
|
||||||
|
|
||||||
$this->addPayoutDrops($user_id, $amount / $decimal, $description);
|
$this->addPayoutDrops($user_id, $amount / $decimal, $description, $host_id, $module_id);
|
||||||
|
|
||||||
return $drops;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addPayoutDrops($user_id, $amount, $description)
|
public function addPayoutDrops($user_id, $amount, $description, $host_id, $module_id)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'type' => 'payout',
|
'type' => 'payout',
|
||||||
@ -143,11 +141,14 @@ public function addPayoutDrops($user_id, $amount, $description)
|
|||||||
'income_drops' => 0,
|
'income_drops' => 0,
|
||||||
'outcome' => 0,
|
'outcome' => 0,
|
||||||
'outcome_drops' => $amount,
|
'outcome_drops' => $amount,
|
||||||
|
'host_id' => $host_id,
|
||||||
|
'module_id' => $module_id,
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->addLog($user_id, $data);
|
return $this->addLog($user_id, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addIncomeDrops($user_id, $amount, $description)
|
public function addIncomeDrops($user_id, $amount, $description)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
@ -187,7 +188,7 @@ public function addPayoutBalance($user_id, $amount, $description)
|
|||||||
'income' => 0,
|
'income' => 0,
|
||||||
'income_drops' => 0,
|
'income_drops' => 0,
|
||||||
'outcome' => $amount,
|
'outcome' => $amount,
|
||||||
'outcome_drops' => 0,
|
'outcome_drops' => 0
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->addLog($user_id, $data);
|
return $this->addLog($user_id, $data);
|
||||||
|
@ -20,6 +20,10 @@ public function up()
|
|||||||
'type'
|
'type'
|
||||||
)->index();
|
)->index();
|
||||||
$collection->unsignedBigInteger('payment')->index();
|
$collection->unsignedBigInteger('payment')->index();
|
||||||
|
$collection->unsignedBigInteger(
|
||||||
|
'module_id'
|
||||||
|
)->index()->nullable();
|
||||||
|
$collection->unsignedBigInteger('host_id')->index()->nullable();
|
||||||
|
|
||||||
// a year
|
// a year
|
||||||
$year = 365 * 24 * 60 * 60;
|
$year = 365 * 24 * 60 * 60;
|
||||||
|
Loading…
Reference in New Issue
Block a user