优化 import
This commit is contained in:
parent
042468ba23
commit
869d92e88b
@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Host;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
|
@ -37,7 +37,8 @@ public function create()
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
@ -48,7 +49,8 @@ public function store(Request $request)
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Host $host
|
||||
* @param \App\Models\Host $host
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function show(Host $host)
|
||||
@ -59,7 +61,8 @@ public function show(Host $host)
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Host $host
|
||||
* @param \App\Models\Host $host
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(Host $host): View
|
||||
|
@ -33,7 +33,8 @@ public function create()
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
@ -44,7 +45,8 @@ public function store(Request $request)
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Module $module
|
||||
* @param \App\Models\Module $module
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Module $module)
|
||||
@ -55,7 +57,8 @@ public function show(Module $module)
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Module $module
|
||||
* @param \App\Models\Module $module
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Module $module)
|
||||
@ -66,8 +69,9 @@ public function edit(Module $module)
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Module $module
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Module $module
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Module $module)
|
||||
@ -78,7 +82,8 @@ public function update(Request $request, Module $module)
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Module $module
|
||||
* @param \App\Models\Module $module
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Module $module)
|
||||
|
@ -31,7 +31,8 @@ public function create()
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
@ -42,7 +43,8 @@ public function store(Request $request)
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\WorkOrder\Reply $reply
|
||||
* @param \App\Models\WorkOrder\Reply $reply
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Reply $reply)
|
||||
@ -53,7 +55,8 @@ public function show(Reply $reply)
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\WorkOrder\Reply $reply
|
||||
* @param \App\Models\WorkOrder\Reply $reply
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Reply $reply)
|
||||
@ -64,8 +67,9 @@ public function edit(Reply $reply)
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\WorkOrder\Reply $reply
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\WorkOrder\Reply $reply
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Reply $reply)
|
||||
@ -76,7 +80,8 @@ public function update(Request $request, Reply $reply)
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\WorkOrder\Reply $reply
|
||||
* @param \App\Models\WorkOrder\Reply $reply
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Reply $reply)
|
||||
|
@ -22,6 +22,7 @@ public function index(WorkOrder $workOrder): View
|
||||
$workOrders = $workOrder->with('user')->paginate(100);
|
||||
return view('admin.work-orders.index', compact('workOrders'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
@ -35,7 +36,8 @@ public function create()
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
@ -46,7 +48,8 @@ public function store(Request $request)
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function show(WorkOrder $workOrder): View
|
||||
@ -99,7 +102,8 @@ public function update(Request $request, WorkOrder $workOrder): RedirectResponse
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy(WorkOrder $workOrder): RedirectResponse
|
||||
|
@ -4,9 +4,7 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Module;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ModuleController extends Controller
|
||||
|
@ -110,7 +110,7 @@ public function notify(Request $request): View|JsonResponse
|
||||
// if ($balance->paid_at !== null) {
|
||||
// // return $this->success('订单已支付');
|
||||
// return view('balances.process', compact('balance'));
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
return view('balances.process', compact('balance'));
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
use App\Models\Module;
|
||||
use App\Notifications\ModuleEarnings;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class SendModuleEarnings extends Job
|
||||
{
|
||||
|
@ -11,7 +11,6 @@
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo as BelongsToAlias;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany as HasManyAlias;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
// use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
@ -41,6 +40,56 @@ class Host extends Model
|
||||
|
||||
// user
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::created(function ($model) {
|
||||
broadcast(new UserEvent($model->user_id, 'hosts.created', $model));
|
||||
});
|
||||
|
||||
static::updating(function ($model) {
|
||||
|
||||
if ($model->isDirty('status')) {
|
||||
if ($model->status == 'suspended') {
|
||||
$model->suspended_at = now();
|
||||
} else {
|
||||
$model->suspended_at = null;
|
||||
}
|
||||
}
|
||||
|
||||
broadcast(new UserEvent($model->user_id, 'hosts.updating', $model));
|
||||
});
|
||||
|
||||
// when Updated
|
||||
static::updated(function ($model) {
|
||||
dispatch(new \App\Jobs\Module\Host($model, 'patch'));
|
||||
|
||||
Cache::forget('user_hosts_' . $model->user_id);
|
||||
Cache::forget('user_tasks_' . $model->user_id);
|
||||
|
||||
|
||||
broadcast(new UserEvent($model->user_id, 'hosts.updated', $model));
|
||||
});
|
||||
|
||||
//
|
||||
// static::deleting(function ($model) {
|
||||
// broadcast(new UserEvent($model->user_id, 'hosts.deleting', $model));
|
||||
// });
|
||||
|
||||
static::deleting(function ($model) {
|
||||
Cache::forget('user_tasks_' . $model->user_id);
|
||||
});
|
||||
|
||||
static::deleted(function ($model) {
|
||||
broadcast(new UserEvent($model->user_id, 'hosts.deleted', $model));
|
||||
Cache::forget('user_tasks_' . $model->user_id);
|
||||
Cache::forget('user_hosts_' . $model->user_id);
|
||||
});
|
||||
}
|
||||
|
||||
// module
|
||||
|
||||
public function getUserHosts($user_id = null)
|
||||
{
|
||||
return $this->where('user_id', $user_id)->with('module', function ($query) {
|
||||
@ -48,35 +97,33 @@ public function getUserHosts($user_id = null)
|
||||
})->get();
|
||||
}
|
||||
|
||||
// module
|
||||
// workOrders
|
||||
|
||||
public function user(): BelongsToAlias
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
// workOrders
|
||||
// scope
|
||||
|
||||
public function module(): BelongsToAlias
|
||||
{
|
||||
return $this->belongsTo(Module::class);
|
||||
}
|
||||
|
||||
// scope
|
||||
|
||||
public function workOrders(): HasManyAlias
|
||||
{
|
||||
return $this->hasMany(WorkOrder::class);
|
||||
}
|
||||
|
||||
|
||||
// cost
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->whereIn('status', ['running', 'stopped'])->where('price', '!=', 0)->where('managed_price', '!=', 0);
|
||||
}
|
||||
|
||||
|
||||
// cost
|
||||
|
||||
public function scopeThisUser($query, $module = null)
|
||||
{
|
||||
if ($module) {
|
||||
@ -248,52 +295,4 @@ public function costBalance($amount = 1): bool
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::created(function ($model) {
|
||||
broadcast(new UserEvent($model->user_id, 'hosts.created', $model));
|
||||
});
|
||||
|
||||
static::updating(function ($model) {
|
||||
|
||||
if ($model->isDirty('status')) {
|
||||
if ($model->status == 'suspended') {
|
||||
$model->suspended_at = now();
|
||||
} else {
|
||||
$model->suspended_at = null;
|
||||
}
|
||||
}
|
||||
|
||||
broadcast(new UserEvent($model->user_id, 'hosts.updating', $model));
|
||||
});
|
||||
|
||||
// when Updated
|
||||
static::updated(function ($model) {
|
||||
dispatch(new \App\Jobs\Module\Host($model, 'patch'));
|
||||
|
||||
Cache::forget('user_hosts_' . $model->user_id);
|
||||
Cache::forget('user_tasks_' . $model->user_id);
|
||||
|
||||
|
||||
broadcast(new UserEvent($model->user_id, 'hosts.updated', $model));
|
||||
});
|
||||
|
||||
//
|
||||
// static::deleting(function ($model) {
|
||||
// broadcast(new UserEvent($model->user_id, 'hosts.deleting', $model));
|
||||
// });
|
||||
|
||||
static::deleting(function ($model) {
|
||||
Cache::forget('user_tasks_' . $model->user_id);
|
||||
});
|
||||
|
||||
static::deleted(function ($model) {
|
||||
broadcast(new UserEvent($model->user_id, 'hosts.deleted', $model));
|
||||
Cache::forget('user_tasks_' . $model->user_id);
|
||||
Cache::forget('user_hosts_' . $model->user_id);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -169,6 +169,32 @@ public function reduceDrops($user_id, $host_id, $module_id, $auto = 1, $amount =
|
||||
|
||||
}
|
||||
|
||||
public function addPayoutDrops($user_id, $amount, $description, $host_id, $module_id)
|
||||
{
|
||||
$data = [
|
||||
'type' => 'payout',
|
||||
'payment' => 'drops',
|
||||
'description' => $description,
|
||||
'income' => 0,
|
||||
'income_drops' => 0,
|
||||
'outcome' => 0,
|
||||
'outcome_drops' => (float)$amount,
|
||||
'host_id' => $host_id,
|
||||
'module_id' => $module_id,
|
||||
];
|
||||
|
||||
|
||||
// $amount = (double) $amount;
|
||||
|
||||
// Log::debug($amount);
|
||||
|
||||
// $month = now()->month;
|
||||
|
||||
// Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount);
|
||||
|
||||
return $this->addLog($user_id, $data);
|
||||
}
|
||||
|
||||
public function reduceAmount($user_id, $amount = 0, $description = '扣除费用请求。')
|
||||
{
|
||||
|
||||
@ -406,30 +432,4 @@ public function reduceDropsWithoutHost($user_id, $amount = 0, $description = nul
|
||||
|
||||
$this->addPayoutDrops($user_id, $amount, $description, null, null);
|
||||
}
|
||||
|
||||
public function addPayoutDrops($user_id, $amount, $description, $host_id, $module_id)
|
||||
{
|
||||
$data = [
|
||||
'type' => 'payout',
|
||||
'payment' => 'drops',
|
||||
'description' => $description,
|
||||
'income' => 0,
|
||||
'income_drops' => 0,
|
||||
'outcome' => 0,
|
||||
'outcome_drops' => (float)$amount,
|
||||
'host_id' => $host_id,
|
||||
'module_id' => $module_id,
|
||||
];
|
||||
|
||||
|
||||
// $amount = (double) $amount;
|
||||
|
||||
// Log::debug($amount);
|
||||
|
||||
// $month = now()->month;
|
||||
|
||||
// Cache::increment('user_' . $user_id . '_month_' . $month . '_drops', $amount);
|
||||
|
||||
return $this->addLog($user_id, $data);
|
||||
}
|
||||
}
|
||||
|
@ -45,11 +45,6 @@ class User extends Authenticatable
|
||||
'banned_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function hosts(): HasMany
|
||||
{
|
||||
return $this->hasMany(Host::class);
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
@ -73,6 +68,11 @@ protected static function boot()
|
||||
});
|
||||
}
|
||||
|
||||
public function hosts(): HasMany
|
||||
{
|
||||
return $this->hasMany(Host::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws CommonException
|
||||
* @throws BalanceNotEnoughException
|
||||
|
@ -3,13 +3,13 @@
|
||||
namespace App\Models\WorkOrder;
|
||||
|
||||
use App\Exceptions\CommonException;
|
||||
use App\Jobs\Module\WorkOrder\WorkOrder as WorkOrderJob;
|
||||
use App\Models\Host;
|
||||
use App\Models\Module;
|
||||
use App\Models\User;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Jobs\Module\WorkOrder\WorkOrder as WorkOrderJob;
|
||||
|
||||
class WorkOrder extends Model
|
||||
{
|
||||
@ -26,17 +26,6 @@ class WorkOrder extends Model
|
||||
'status',
|
||||
];
|
||||
|
||||
public function safeDelete(): bool
|
||||
{
|
||||
if ($this->status == 'pending') {
|
||||
throw new CommonException('工单状态是 pending,无法删除');
|
||||
}
|
||||
|
||||
dispatch(new WorkOrderJob($this, 'delete'));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
@ -81,6 +70,17 @@ protected static function boot()
|
||||
});
|
||||
}
|
||||
|
||||
public function safeDelete(): bool
|
||||
{
|
||||
if ($this->status == 'pending') {
|
||||
throw new CommonException('工单状态是 pending,无法删除');
|
||||
}
|
||||
|
||||
dispatch(new WorkOrderJob($this, 'delete'));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// replies
|
||||
|
||||
public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
|
@ -72,18 +72,18 @@
|
||||
<br/>
|
||||
然后,安装依赖
|
||||
<code>composer install --no-dev</code>
|
||||
<br />
|
||||
<br/>
|
||||
接着,升级数据库(只需要在一台节点上执行)
|
||||
<code>art migrate</code>
|
||||
<br />
|
||||
<br/>
|
||||
最后,清除缓存
|
||||
<code>art optimize</code>
|
||||
<br />
|
||||
<br/>
|
||||
|
||||
如果是非 Web 节点,需要重启全部或者对应服务,比如 队列,计划任务
|
||||
<code>supervisorctl restart all</code>
|
||||
|
||||
<br />
|
||||
<br/>
|
||||
如果是 Web 节点,需要简单重启即可
|
||||
<code>supervisorctl restart lae-web</code>
|
||||
|
||||
|
@ -11,10 +11,10 @@
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
{{-- <div class="form-group">--}}
|
||||
{{-- <label for="name" class="col-sm-2 col-form-label">名称</label>--}}
|
||||
{{-- <input type="text" class="form-control" id="name" name="name" value="{{ $host->name }}">--}}
|
||||
{{-- </div>--}}
|
||||
{{-- <div class="form-group">--}}
|
||||
{{-- <label for="name" class="col-sm-2 col-form-label">名称</label>--}}
|
||||
{{-- <input type="text" class="form-control" id="name" name="name" value="{{ $host->name }}">--}}
|
||||
{{-- </div>--}}
|
||||
|
||||
<div class="form-group">
|
||||
<label for="managed_price" class="col-sm-2 col-form-label">新的价格 (Drops)</label>
|
||||
|
@ -26,7 +26,7 @@
|
||||
@foreach ($transactions as $t)
|
||||
<tr>
|
||||
|
||||
<td>
|
||||
<td>
|
||||
@if ($t->type === 'payout')
|
||||
<span class="text-danger">
|
||||
支出
|
||||
|
Loading…
Reference in New Issue
Block a user