改进 扣费
This commit is contained in:
parent
c7a0484c48
commit
c224b2c7b5
@ -94,22 +94,11 @@ public function show(Host $host): JsonResponse
|
||||
*/
|
||||
public function update(Request $request, Host $host): JsonResponse
|
||||
{
|
||||
//
|
||||
$this->validate($request, [
|
||||
'status' => 'sometimes|in:running,stopped,error,suspended,pending',
|
||||
'managed_price' => 'sometimes|numeric|nullable',
|
||||
|
||||
// 如果是立即扣费
|
||||
'cost_once' => 'sometimes|numeric|nullable',
|
||||
]);
|
||||
|
||||
// if it has cost_once
|
||||
if ($request->has('cost_once')) {
|
||||
$host->cost($request->cost_once ?? 0, false);
|
||||
|
||||
return $this->updated();
|
||||
}
|
||||
|
||||
$update = $request->except(['module_id', 'user_id']);
|
||||
|
||||
$host->update($update);
|
||||
@ -134,4 +123,16 @@ public function destroy($host): JsonResponse
|
||||
|
||||
return $this->deleted();
|
||||
}
|
||||
|
||||
public function cost(Request $request, Host $host): JsonResponse
|
||||
{
|
||||
$this->validate($request, [
|
||||
'amount' => 'required|numeric|min:0.01',
|
||||
'description' => 'nullable|string:max:255',
|
||||
]);
|
||||
|
||||
$host->cost($request->input('amount'), false);
|
||||
|
||||
return $this->noContent();
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ public function safeDelete(): bool
|
||||
return true;
|
||||
}
|
||||
|
||||
public function cost(string $amount = null, $auto = true): bool
|
||||
public function cost(string $amount = null, $auto = true, $description = null): bool
|
||||
{
|
||||
$this->load('user');
|
||||
$user = $this->user;
|
||||
@ -209,7 +209,7 @@ public function cost(string $amount = null, $auto = true): bool
|
||||
}
|
||||
|
||||
if ($real_price == 0) {
|
||||
echo '价格为 0,不扣费';
|
||||
echo '价格为 0,不扣费'.PHP_EOL;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -237,7 +237,9 @@ public function cost(string $amount = null, $auto = true): bool
|
||||
|
||||
Cache::put($month_cache_key, $hosts_balances, 604800);
|
||||
|
||||
$description = '模块发起的扣费。';
|
||||
if (! $description) {
|
||||
$description = '模块发起的扣费。';
|
||||
}
|
||||
|
||||
if ($auto) {
|
||||
$description = '自动扣费。';
|
||||
|
Loading…
Reference in New Issue
Block a user