From 4918efa597a463b197f92545006dc5f1d2791589 Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Wed, 16 Nov 2022 13:16:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=BC=E5=85=A5=EF=BC=8C?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 分离出充值系统 修复了充值的问题 --- app/Console/Commands/CalcModule.php | 2 +- app/Console/Commands/Count.php | 6 +- app/Console/Commands/ReduceBalance.php | 4 +- app/Console/Commands/Status.php | 1 - app/Console/Kernel.php | 3 +- app/Exceptions/Handler.php | 5 +- app/Helpers/ApiResponse.php | 58 +-- app/Helpers/HttpEvent.php | 2 +- app/Helpers/Lock.php | 6 +- app/Http/Controllers/Admin/AuthController.php | 3 +- app/Http/Controllers/Admin/UserController.php | 17 +- .../Controllers/Api/BalanceController.php | 122 +----- app/Http/Controllers/Api/ForumController.php | 31 +- app/Http/Controllers/Api/HostController.php | 2 +- .../Api/WorkOrder/ReplyController.php | 2 +- .../Modules/BroadcastController.php | 13 +- .../Modules/Host/HostController.php | 4 +- .../Controllers/Modules/ModuleController.php | 36 +- .../Modules/WorkOrder/ReplyController.php | 1 + .../Modules/WorkOrder/WorkOrderController.php | 6 +- .../Controllers/{ => Web}/AuthController.php | 9 +- .../Controllers/Web/BalanceController.php | 137 ++++++ app/Http/Middleware/Authenticate.php | 5 +- .../Middleware/RedirectIfAuthenticated.php | 7 +- app/Jobs/CalcModule.php | 8 +- app/Jobs/Module/Host.php | 1 + app/Jobs/Module/WorkOrder/Reply.php | 1 + app/Jobs/Module/WorkOrder/WorkOrder.php | 2 +- app/Models/Admin.php | 2 +- app/Models/Host.php | 111 ++--- app/Models/Module.php | 53 ++- app/Models/PersonalAccessToken.php | 3 +- app/Models/Task.php | 44 +- app/Models/Transaction.php | 403 +++++++++--------- app/Models/User.php | 25 +- app/Models/WorkOrder/Reply.php | 35 +- app/Models/WorkOrder/WorkOrder.php | 73 ++-- app/Notifications/ModuleEarnings.php | 3 +- app/Notifications/UserBalanceNotification.php | 5 +- app/Notifications/WorkOrderNotification.php | 5 +- app/Observers/BalanceObserve.php | 19 +- app/Observers/WorkOrder/ReplyObserver.php | 15 +- app/Observers/WorkOrder/WorkOrderObserver.php | 15 +- artisan | 4 +- config/app.php | 4 +- config/broadcasting.php | 2 +- config/filesystems.php | 2 +- config/logging.php | 2 +- config/pay.php | 2 +- config/session.php | 2 +- database/factories/UserFactory.php | 2 +- .../2014_10_12_000000_create_users_table.php | 3 +- ...12_100000_create_password_resets_table.php | 3 +- ..._08_19_000000_create_failed_jobs_table.php | 3 +- ...01_create_personal_access_tokens_table.php | 3 +- .../2022_08_12_081236_create_drops_table.php | 5 +- ...08_12_082631_create_transcations_table.php | 3 +- ...2_08_12_084822_add_type_to_drops_table.php | 3 +- ...2022_08_12_123308_create_modules_table.php | 3 +- .../2022_08_13_051148_create_hosts_table.php | 3 +- ...2_08_13_051705_create_workorders_table.php | 3 +- ..._051817_create_workorder_replies_table.php | 3 +- ...8_13_083908_create_notifications_table.php | 3 +- ...04635_add_managed_price_to_hosts_table.php | 3 +- ...user_id_nullable_to_work_order_replies.php | 3 +- ..._08_19_082540_add_url_to_modules_table.php | 3 +- .../2022_08_25_142429_create_tasks_table.php | 3 +- ...094841_add_suspended_at_to_hosts_table.php | 3 +- ...8_30_081930_add_balance_to_users_table.php | 7 +- ...022_09_01_033240_create_balances_table.php | 3 +- ...22_09_03_070656_add_module_id_to_hosts.php | 3 +- ...2_09_08_135104_delete_drops_from_users.php | 3 +- ...22_09_13_191255_add_banned_at_to_users.php | 5 +- ...2_09_14_214642_drop_transcations_table.php | 3 +- ...09_14_215159_create_transactions_table.php | 3 +- .../2022_10_03_123715_convert_user_drops.php | 3 +- ...10_31_161617_add_wecom_hook_to_modules.php | 3 +- .../2022_11_02_103610_create_admins_table.php | 3 +- ...05842_add_remaining_amount_to_balances.php | 3 +- .../2022_11_06_205958_drop_drops_table.php | 3 +- ..._recreate_personal_access_tokens_table.php | 3 +- ..._11_08_181357_drop_access_tokens_table.php | 3 +- lang/zh_CN/auth.php | 2 +- lang/zh_CN/pagination.php | 2 +- lang/zh_CN/passwords.php | 8 +- lang/zh_CN/validation.php | 356 ++++++++-------- public/index.php | 8 +- resources/js/bootstrap.js | 6 +- resources/views/admin/index.blade.php | 2 +- resources/views/admin/login.blade.php | 13 +- resources/views/admin/users/index.blade.php | 2 +- resources/views/balances/index.blade.php | 19 + resources/views/{ => balances}/pay.blade.php | 4 +- resources/views/banned.blade.php | 6 +- resources/views/components/alert.blade.php | 14 +- resources/views/index.blade.php | 6 +- resources/views/layouts/admin.blade.php | 112 ++--- resources/views/layouts/app.blade.php | 118 ++--- resources/views/not_verified.blade.php | 8 +- .../notifications/module/earnings.blade.php | 17 +- .../work_order/created.blade.php | 54 +-- resources/views/pay_process.blade.php | 4 +- routes/channels.php | 2 +- routes/web.php | 29 +- tests/CreatesApplication.php | 2 +- vite.config.js | 2 +- 106 files changed, 1148 insertions(+), 1074 deletions(-) rename app/Http/Controllers/{ => Web}/AuthController.php (96%) create mode 100644 app/Http/Controllers/Web/BalanceController.php create mode 100644 resources/views/balances/index.blade.php rename resources/views/{ => balances}/pay.blade.php (67%) diff --git a/app/Console/Commands/CalcModule.php b/app/Console/Commands/CalcModule.php index 7f49abf..54a4349 100644 --- a/app/Console/Commands/CalcModule.php +++ b/app/Console/Commands/CalcModule.php @@ -39,7 +39,7 @@ public function __construct() */ public function handle() { - $moduleController = new ModuleController(); + $moduleController = new ModuleController(); $rate = config('drops.module_rate'); diff --git a/app/Console/Commands/Count.php b/app/Console/Commands/Count.php index 762dd6a..4bf0f5e 100644 --- a/app/Console/Commands/Count.php +++ b/app/Console/Commands/Count.php @@ -58,13 +58,13 @@ public function handle() $this->info('正在获取主机数量...'); $hosts = Host::count(); - + $this->info('正在获取部署中的主机数量...'); $pending_hosts = Host::where('status', 'pending')->count(); - + $this->info('正在获取已停止的主机数量...'); $stopped_hosts = Host::where('status', 'stopped')->count(); - + $this->info('正在获取部署失败的主机数量...'); $error_hosts = Host::where('status', 'error')->count(); diff --git a/app/Console/Commands/ReduceBalance.php b/app/Console/Commands/ReduceBalance.php index 804f103..60d0409 100644 --- a/app/Console/Commands/ReduceBalance.php +++ b/app/Console/Commands/ReduceBalance.php @@ -48,11 +48,11 @@ public function handle() $user = User::find($user_id); - $this->warn('扣除金额: ' . $user->balance . ' 元'); + $this->warn('扣除金额: ' . $amount . ' 元'); $this->warn('用户当前余额:' . $user->balance . ' 元'); - $this->warn('剩余余额:' . $user->balance -$amount . ' 元'); + $this->warn('剩余余额:' . $user->balance - $amount . ' 元'); $confirm = $this->confirm('确认扣除?'); diff --git a/app/Console/Commands/Status.php b/app/Console/Commands/Status.php index 8ce77c8..a941498 100644 --- a/app/Console/Commands/Status.php +++ b/app/Console/Commands/Status.php @@ -109,7 +109,6 @@ public function handle() $this->info('Redis 总命令数: ' . $redis_total_commands_processed); - $this->warn('===== 莱云 统计 ====='); $this->warn('要获取 莱云 统计信息,请运行 count 命令。'); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index e90ec2f..f726bc6 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -17,7 +17,8 @@ class Kernel extends ConsoleKernel /** * Define the application's command schedule. * - * @param \Illuminate\Console\Scheduling\Schedule $schedule + * @param \Illuminate\Console\Scheduling\Schedule $schedule + * * @return void */ protected function schedule(Schedule $schedule) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index c704eb5..39cfe09 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -4,7 +4,6 @@ use Illuminate\Auth\AuthenticationException; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; -use Illuminate\Http\JsonResponse; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Throwable; @@ -63,8 +62,8 @@ public function register() /** * Convert an authentication exception into an unauthenticated response. * - * @param \Illuminate\Http\Request $request - * @param \Illuminate\Auth\AuthenticationException $exception + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Auth\AuthenticationException $exception * * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\Http\Response */ diff --git a/app/Helpers/ApiResponse.php b/app/Helpers/ApiResponse.php index c8bcd99..4bbb7aa 100644 --- a/app/Helpers/ApiResponse.php +++ b/app/Helpers/ApiResponse.php @@ -5,6 +5,25 @@ trait ApiResponse { // RESTful API response + public function remoteResponse($response, $status = 200) + { + return response()->json($response, $status)->setEncodingOptions(JSON_UNESCAPED_UNICODE); + } + + public function notFound($message = 'Not found') + { + return $this->error($message, 404); + } + + // success + + public function error($message = '', $code = 400) + { + return $this->apiResponse($message, $code); + } + + // error + public function apiResponse($data = [], $status = 200) { // if data is paginated, return paginated data @@ -34,55 +53,44 @@ public function apiResponse($data = [], $status = 200) return response()->json($data, $status)->setEncodingOptions(JSON_UNESCAPED_UNICODE); } - public function remoteResponse($response, $status = 200) - { - return response()->json($response, $status)->setEncodingOptions(JSON_UNESCAPED_UNICODE); - } - - // success - public function success($data = []) - { - return $this->apiResponse($data, 200); - } - - // error - public function error($message = '', $code = 400) - { - return $this->apiResponse($message, $code); - } - // not found - public function notFound($message = 'Not found') - { - return $this->error($message, 404); - } - // forbidden public function forbidden($message = 'Forbidden') { return $this->error($message, 403); } - // unauthorized + // forbidden + public function unauthorized($message = 'Unauthorized') { return $this->error($message, 401); } - // bad request + // unauthorized + public function badRequest($message = 'Bad request') { return $this->error($message, 400); } - // created + // bad request + public function created($message = 'Created') { return $this->success($message, 201); } + // created + + public function success($data = []) + { + return $this->apiResponse($data, 200); + } + // accepted + public function accepted($message = 'Accepted') { return $this->success($message, 202); diff --git a/app/Helpers/HttpEvent.php b/app/Helpers/HttpEvent.php index 334fff8..021b44e 100644 --- a/app/Helpers/HttpEvent.php +++ b/app/Helpers/HttpEvent.php @@ -4,5 +4,5 @@ trait HttpEvent { - + } diff --git a/app/Helpers/Lock.php b/app/Helpers/Lock.php index 00153c3..6f0fbc3 100644 --- a/app/Helpers/Lock.php +++ b/app/Helpers/Lock.php @@ -6,8 +6,10 @@ use Illuminate\Contracts\Cache\LockTimeoutException; use Illuminate\Support\Facades\Cache; -trait Lock { - public function await($name, Closure $callback) { +trait Lock +{ + public function await($name, Closure $callback) + { // if env is local if (env('APP_ENV') == 'local') { return $callback(); diff --git a/app/Http/Controllers/Admin/AuthController.php b/app/Http/Controllers/Admin/AuthController.php index 19c27f4..65becd2 100644 --- a/app/Http/Controllers/Admin/AuthController.php +++ b/app/Http/Controllers/Admin/AuthController.php @@ -20,7 +20,8 @@ public function index() } } - public function login(Request $request) { + public function login(Request $request) + { if (auth('admin')->attempt($request->only('email', 'password'))) { return redirect()->route('admin.index'); } else { diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 44b928a..03073e6 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -30,7 +30,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) @@ -41,7 +42,8 @@ public function store(Request $request) /** * Display the specified resource. * - * @param int $id + * @param int $id + * * @return \Illuminate\Http\Response */ public function show($id) @@ -52,7 +54,8 @@ public function show($id) /** * Show the form for editing the specified resource. * - * @param int $id + * @param int $id + * * @return \Illuminate\Http\Response */ public function edit($id) @@ -63,8 +66,9 @@ public function edit($id) /** * Update the specified resource in storage. * - * @param \Illuminate\Http\Request $request - * @param int $id + * @param \Illuminate\Http\Request $request + * @param int $id + * * @return \Illuminate\Http\Response */ public function update(Request $request, $id) @@ -75,7 +79,8 @@ public function update(Request $request, $id) /** * Remove the specified resource from storage. * - * @param int $id + * @param int $id + * * @return \Illuminate\Http\Response */ public function destroy($id) diff --git a/app/Http/Controllers/Api/BalanceController.php b/app/Http/Controllers/Api/BalanceController.php index 6587150..5e1623f 100644 --- a/app/Http/Controllers/Api/BalanceController.php +++ b/app/Http/Controllers/Api/BalanceController.php @@ -2,134 +2,30 @@ namespace App\Http\Controllers\Api; +use App\Exceptions\ChargeException; use App\Http\Controllers\Controller; use App\Models\Balance; use App\Models\Transaction; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; use Yansongda\LaravelPay\Facades\Pay; use Yansongda\Pay\Exception\InvalidResponseException; use function auth; use function config; use function now; -use function route; -use function view; class BalanceController extends Controller { // - public function index(Request $request) + public function index(): JsonResponse { $balances = Balance::thisUser()->simplePaginate(30); return $this->success($balances); } - public function store(Request $request) - { - // 充值 - $this->validate($request, [ - 'amount' => 'required|integer|min:1|max:10000', - ]); - - $user = $request->user(); - - $balance = new Balance(); - - - $data = [ - 'user_id' => $user->id, - 'amount' => $request->amount, - 'payment' => 'alipay', - ]; - - // if local - // if (env('APP_ENV') == 'local') { - // $data['payment'] = null; - // $data['paid_at'] = now(); - // } - - - $balance = $balance->create($data); - - // 生成 18 位订单号 - $order_id = date('YmdHis') . $balance->id . rand(1000, 9999); - $balance->order_id = $order_id; - - $balance->save(); - - $balance = $balance->toArray(); - $balance['pay_url'] = route('balances.pay.show', ['balance' => $balance['order_id']]); - - return $this->success($balance); - } - - - public function show(Balance $balance) - { - if ($balance->paid_at !== null) { - return $this->error('订单已支付'); - } - - if (now()->diffInDays($balance->created_at) > 1) { - return $this->error('订单已失效'); - } - - $pay = Pay::alipay()->web([ - 'out_trade_no' => $balance->order_id, - 'total_amount' => $balance->amount, - 'subject' => config('app.display_name') . ' 充值', - ]); - - return $pay; - } - - public function notify(Request $request) - { - $this->validate($request, [ - 'out_trade_no' => 'required', - ]); - - // 检测订单是否存在 - $balance = Balance::where('order_id', $request->out_trade_no)->with('user')->first(); - if (!$balance) { - return $this->notFound('找不到对应的订单'); - } - - // 检测订单是否已支付 - if ($balance->paid_at !== null) { - // return $this->success('订单已支付'); - return view('pay_process'); - } - - // try { - // $data = Pay::alipay()->callback(); - // } catch (InvalidResponseException $e) { - // return $this->error('支付失败'); - // } - - // // 检测 out_trade_no 是否为商户系统中创建的订单号 - // if ($data->out_trade_no != $balance->order_id) { - // return $this->error('订单号不一致'); - // } - - // if ((int) $data->total_amount != (int) $balance->amount) { - // throw new ChargeException('金额不一致'); - // } - - // // 验证 商户 - // if ($data['app_id'] != config('pay.alipay.default.app_id')) { - // throw new ChargeException('商户不匹配'); - // } - - if ($this->checkAndCharge($balance, true)) { - return view('pay_process'); - } else { - return $this->error('支付失败'); - } - } - - public function checkAndCharge(Balance $balance, $check = false) + public function checkAndCharge(Balance $balance, $check = false): JsonResponse|bool { if ($check) { @@ -150,8 +46,13 @@ public function checkAndCharge(Balance $balance, $check = false) $balance->update([ 'paid_at' => now() ]); - } catch (InvalidResponseException) { + } catch (InvalidResponseException $e) { + Log::error($e->getMessage()); return $this->error('无法验证支付结果。'); + } catch (ChargeException $e) { + Log::error($e->getMessage()); + return $this->error('暂时无法处理充值。'); + } return true; @@ -160,7 +61,8 @@ public function checkAndCharge(Balance $balance, $check = false) /** * 获取交易记录 * - * @param mixed $request + * @param mixed $request + * * @return JsonResponse */ public function transactions(Request $request): JsonResponse diff --git a/app/Http/Controllers/Api/ForumController.php b/app/Http/Controllers/Api/ForumController.php index d27e3fe..084d1e0 100644 --- a/app/Http/Controllers/Api/ForumController.php +++ b/app/Http/Controllers/Api/ForumController.php @@ -23,13 +23,6 @@ public function __construct() $this->http = Http::baseUrl($this->baseUrl . '/api')->throw(); } - public function get($url) - { - $resp = $this->http->get($url)->json()['data']; - return $resp; - } - - public function announcements() { $resp = $this->cache(function () { @@ -39,16 +32,6 @@ public function announcements() return $this->resp($resp); } - public function pinned() - { - $resp = $this->cache(function () { - return $this->get('discussions?filter[tag]=pinned&page[offset]=0&sort=-createdAt'); - }); - - return $this->resp($resp); - } - - public function cache(Closure $callback) { // 获取调用方法名 @@ -59,6 +42,11 @@ public function cache(Closure $callback) }); } + public function get($url) + { + $resp = $this->http->get($url)->json()['data']; + return $resp; + } public function resp($data) { @@ -66,4 +54,13 @@ public function resp($data) return $this->success($data); } + + public function pinned() + { + $resp = $this->cache(function () { + return $this->get('discussions?filter[tag]=pinned&page[offset]=0&sort=-createdAt'); + }); + + return $this->resp($resp); + } } diff --git a/app/Http/Controllers/Api/HostController.php b/app/Http/Controllers/Api/HostController.php index 9f2b2cc..5a16812 100644 --- a/app/Http/Controllers/Api/HostController.php +++ b/app/Http/Controllers/Api/HostController.php @@ -15,7 +15,7 @@ class HostController extends Controller { public function index(): JsonResponse { - $hosts = Host::where('user_id', auth()->id())->with('module', function ($query) { + $hosts = Host::where('user_id', auth()->id())->with('module', function ($query) { $query->select(['id', 'name']); })->get(); diff --git a/app/Http/Controllers/Api/WorkOrder/ReplyController.php b/app/Http/Controllers/Api/WorkOrder/ReplyController.php index 54aef26..61c840a 100644 --- a/app/Http/Controllers/Api/WorkOrder/ReplyController.php +++ b/app/Http/Controllers/Api/WorkOrder/ReplyController.php @@ -29,7 +29,7 @@ public function index(WorkOrder $workOrder) /** * Store a newly created resource in storage. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response */ diff --git a/app/Http/Controllers/Modules/BroadcastController.php b/app/Http/Controllers/Modules/BroadcastController.php index 65e5a1c..be37eb3 100644 --- a/app/Http/Controllers/Modules/BroadcastController.php +++ b/app/Http/Controllers/Modules/BroadcastController.php @@ -25,6 +25,13 @@ public function broadcast_to_user(Request $request, User $user) } + private function rules() + { + return [ + 'message' => 'required', + ]; + } + public function broadcast_to_host(Request $request, Host $host) { $this->validate($request, $this->rules()); @@ -37,10 +44,4 @@ public function broadcast_to_host(Request $request, Host $host) return $this->created($request->message); } - - private function rules() { - return [ - 'message' => 'required', - ]; - } } diff --git a/app/Http/Controllers/Modules/Host/HostController.php b/app/Http/Controllers/Modules/Host/HostController.php index f78ef71..6da4c18 100644 --- a/app/Http/Controllers/Modules/Host/HostController.php +++ b/app/Http/Controllers/Modules/Host/HostController.php @@ -72,7 +72,7 @@ public function store(Request $request) /** * Display the specified resource. * - * @param Host $host + * @param Host $host * * @return JsonResponse */ @@ -89,7 +89,7 @@ public function show(Host $host) * Update the specified resource in storage. * * @param Request $request - * @param Host $host + * @param Host $host * * @return JsonResponse */ diff --git a/app/Http/Controllers/Modules/ModuleController.php b/app/Http/Controllers/Modules/ModuleController.php index f5fd1ee..8b5f830 100644 --- a/app/Http/Controllers/Modules/ModuleController.php +++ b/app/Http/Controllers/Modules/ModuleController.php @@ -19,7 +19,7 @@ public function index() $data = [ 'module' => $module, - 'rate' => (int) config('drops.module_rate'), + 'rate' => (int)config('drops.module_rate'), ]; // merge @@ -28,6 +28,22 @@ public function index() return $this->success($data); } + public function calcModule(Module|Authenticatable $module): array + { + + $default = [ + 'balance' => 0, + 'drops' => 0, + ]; + + return [ + 'transactions' => [ + 'this_month' => Cache::get('this_month_balance_and_drops_' . $module->id, $default), + 'last_month' => Cache::get('last_month_balance_and_drops_' . $module->id, $default), + ] + ]; + } + public function call(Request $request, Module $module) { $path = request()->path(); @@ -58,7 +74,6 @@ public function call(Request $request, Module $module) return $this->remoteResponse($response['json'], $response['status']); } - public function exportCall(Request $request, Module $module): \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory { $path = request()->path(); @@ -76,21 +91,4 @@ public function exportCall(Request $request, Module $module): \Illuminate\Http\R return $this->remoteResponse($response['json'], $response['status']); } - - - public function calcModule(Module|Authenticatable $module): array - { - - $default = [ - 'balance' => 0, - 'drops' => 0, - ]; - - return [ - 'transactions' => [ - 'this_month' => Cache::get('this_month_balance_and_drops_' . $module->id, $default), - 'last_month' => Cache::get('last_month_balance_and_drops_' . $module->id, $default), - ] - ]; - } } diff --git a/app/Http/Controllers/Modules/WorkOrder/ReplyController.php b/app/Http/Controllers/Modules/WorkOrder/ReplyController.php index 42cac97..86a226f 100644 --- a/app/Http/Controllers/Modules/WorkOrder/ReplyController.php +++ b/app/Http/Controllers/Modules/WorkOrder/ReplyController.php @@ -25,6 +25,7 @@ public function index(Request $request) * Store a newly created resource in storage. * * @param Request $request + * * @return JsonResponse */ public function store(Request $request) diff --git a/app/Http/Controllers/Modules/WorkOrder/WorkOrderController.php b/app/Http/Controllers/Modules/WorkOrder/WorkOrderController.php index a04aed2..7e8861d 100644 --- a/app/Http/Controllers/Modules/WorkOrder/WorkOrderController.php +++ b/app/Http/Controllers/Modules/WorkOrder/WorkOrderController.php @@ -10,7 +10,8 @@ class WorkOrderController extends Controller { // - public function index(Request $request, WorkOrder $workOrder) { + public function index(Request $request, WorkOrder $workOrder) + { // $work_orders = new WorkOrder(); // // if route has user // if ($request->route('user')) { @@ -28,7 +29,8 @@ public function index(Request $request, WorkOrder $workOrder) { // } - public function show(WorkOrderRequest $request, WorkOrder $workOrder) { + public function show(WorkOrderRequest $request, WorkOrder $workOrder) + { return $this->success($workOrder); } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/Web/AuthController.php similarity index 96% rename from app/Http/Controllers/AuthController.php rename to app/Http/Controllers/Web/AuthController.php index 8441ec8..665c373 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/Web/AuthController.php @@ -1,15 +1,22 @@ getDrops(); + + $balance = $request->user()->balance; + + return view('balances.index', compact('drops', 'balance')); + } + + public function store(Request $request) + { + // 充值 + $this->validate($request, [ + 'amount' => 'required|integer|min:1|max:10000', + ]); + + $user = $request->user(); + + $balance = new Balance(); + + + $data = [ + 'user_id' => $user->id, + 'amount' => $request->amount, + 'payment' => 'alipay', + ]; + + // if local + // if (env('APP_ENV') == 'local') { + // $data['payment'] = null; + // $data['paid_at'] = now(); + // } + + + $balance = $balance->create($data); + + // 生成 18 位订单号 + $order_id = date('YmdHis') . $balance->id . rand(1000, 9999); + $balance->order_id = $order_id; + + $balance->save(); + + // $balances['pay_url'] = route('balances.balances.show', ['balances' => $balances['order_id']]); + + return redirect()->route('balances.balances.show', ['balances' => $balance->order_id]); + } + + /** + * @throws \Laravel\Octane\Exceptions\DdException + */ + public function show(Balance $balance) + { + if ($balance->paid_at !== null) { + return $this->error('订单已支付'); + } + + if (now()->diffInDays($balance->created_at) > 1) { + return $this->error('订单已失效'); + } + + $web = Pay::alipay()->web([ + 'out_trade_no' => $balance->order_id, + 'total_amount' => $balance->amount, + 'subject' => config('app.display_name') . ' 充值', + ]); + + return view('balances.pay', ['html' => (string)$web->getBody()]); + } + + /** + * @throws ValidationException + */ + public function notify(Request $request): View|JsonResponse + { + $this->validate($request, [ + 'out_trade_no' => 'required', + ]); + + // 检测订单是否存在 + $balance = Balance::where('order_id', $request->out_trade_no)->with('user')->first(); + if (!$balance) { + abort(404, '找不到订单。'); + } + + // 检测订单是否已支付 + if ($balance->paid_at !== null) { + // return $this->success('订单已支付'); + return view('pay_process'); + } + + // try { + // $data = Pay::alipay()->callback(); + // } catch (InvalidResponseException $e) { + // return $this->error('支付失败'); + // } + + // // 检测 out_trade_no 是否为商户系统中创建的订单号 + // if ($data->out_trade_no != $balances->order_id) { + // return $this->error('订单号不一致'); + // } + + // if ((int) $data->total_amount != (int) $balances->amount) { + // throw new ChargeException('金额不一致'); + // } + + // // 验证 商户 + // if ($data['app_id'] != config('balances.alipay.default.app_id')) { + // throw new ChargeException('商户不匹配'); + // } + + if ((new \App\Http\Controllers\Api\BalanceController())->checkAndCharge($balance, true)) { + return view('pay_process'); + } else { + abort(500, '支付失败'); + } + } +} diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php index 4b500b4..0cf26d2 100644 --- a/app/Http/Middleware/Authenticate.php +++ b/app/Http/Middleware/Authenticate.php @@ -9,12 +9,13 @@ class Authenticate extends Middleware /** * Get the path the user should be redirected to when they are not authenticated. * - * @param \Illuminate\Http\Request $request + * @param \Illuminate\Http\Request $request + * * @return string|null */ protected function redirectTo($request) { - if (! $request->expectsJson()) { + if (!$request->expectsJson()) { return route('index'); } } diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index a2813a0..e96617b 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -12,9 +12,10 @@ class RedirectIfAuthenticated /** * Handle an incoming request. * - * @param \Illuminate\Http\Request $request - * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next - * @param string|null ...$guards + * @param \Illuminate\Http\Request $request + * @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next + * @param string|null ...$guards + * * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse */ public function handle(Request $request, Closure $next, ...$guards) diff --git a/app/Jobs/CalcModule.php b/app/Jobs/CalcModule.php index c5ab6d3..ee34dfb 100644 --- a/app/Jobs/CalcModule.php +++ b/app/Jobs/CalcModule.php @@ -37,8 +37,8 @@ public function handle() $this_month = Transaction::where('module_id', $module->id)->where('type', 'payout')->whereBetween('created_at', [$beginOfMonth, $endOfMonth]); // this month transactions - $this_month = [ - 'balance' => $this_month->sum('outcome'), + $this_month = [ + 'balances' => $this_month->sum('outcome'), 'drops' => $this_month->sum('outcome_drops') ]; @@ -47,8 +47,8 @@ public function handle() // last month transactions $last_moth = Transaction::where('module_id', $module->id)->where('type', 'payout')->whereBetween('created_at', [$beginOfMonth, $endOfMonth]); - $last_moth = [ - 'balance' => $last_moth->sum('outcome'), + $last_moth = [ + 'balances' => $last_moth->sum('outcome'), 'drops' => $last_moth->sum('outcome_drops') ]; diff --git a/app/Jobs/Module/Host.php b/app/Jobs/Module/Host.php index 0a10708..f67af62 100644 --- a/app/Jobs/Module/Host.php +++ b/app/Jobs/Module/Host.php @@ -17,6 +17,7 @@ class Host implements ShouldQueue public HostModel $host; public string $type; + /** * Create a new job instance. * diff --git a/app/Jobs/Module/WorkOrder/Reply.php b/app/Jobs/Module/WorkOrder/Reply.php index 58f7e55..6a2d854 100644 --- a/app/Jobs/Module/WorkOrder/Reply.php +++ b/app/Jobs/Module/WorkOrder/Reply.php @@ -17,6 +17,7 @@ class Reply implements ShouldQueue use InteractsWithQueue, Queueable, SerializesModels; protected $reply; + /** * Create a new job instance. * diff --git a/app/Jobs/Module/WorkOrder/WorkOrder.php b/app/Jobs/Module/WorkOrder/WorkOrder.php index a28fd12..eab0de3 100644 --- a/app/Jobs/Module/WorkOrder/WorkOrder.php +++ b/app/Jobs/Module/WorkOrder/WorkOrder.php @@ -23,7 +23,7 @@ class WorkOrder implements ShouldQueue * * @return void */ - public function __construct(WorkOrderWorkOrder $workOrder, $type = 'post') + public function __construct(WorkOrderWorkOrder $workOrder, $type = 'post') { // $this->workOrder = $workOrder; diff --git a/app/Models/Admin.php b/app/Models/Admin.php index bd9cfd6..c964114 100644 --- a/app/Models/Admin.php +++ b/app/Models/Admin.php @@ -2,8 +2,8 @@ namespace App\Models; -use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Foundation\Auth\User as Authenticatable; class Admin extends Authenticatable { diff --git a/app/Models/Host.php b/app/Models/Host.php index 852e831..00855e3 100644 --- a/app/Models/Host.php +++ b/app/Models/Host.php @@ -38,6 +38,55 @@ class Host extends Model // get user hosts + + 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->status == 'suspended') { + $model->suspended_at = now(); + } else if ($model->status == 'running') { + $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); + }); + } + + + // user + public function getUserHosts($user_id = null) { return $this->where('user_id', $user_id)->with('module', function ($query) { @@ -45,31 +94,35 @@ public function getUserHosts($user_id = null) })->get(); } + // module - // user public function user(): BelongsToAlias { return $this->belongsTo(User::class); } - // module + // workOrders + public function module(): BelongsToAlias { return $this->belongsTo(Module::class); } - // workOrders + // scope + public function workOrders(): HasManyAlias { return $this->hasMany(WorkOrder::class); } - // scope public function scopeActive($query) { return $query->where('status', 'running')->where('price', '!=', 0); } + + // cost + public function scopeThisUser($query, $module = null) { if ($module) { @@ -79,8 +132,6 @@ public function scopeThisUser($query, $module = null) } } - - // cost public function cost($price = null, $auto = true): bool { $this->load('user'); @@ -154,8 +205,7 @@ public function cost($price = null, $auto = true): bool return true; } - - public function costBalance($amount = 1) + public function costBalance($amount = 1): bool { $transaction = new Transaction(); @@ -185,49 +235,4 @@ public function costBalance($amount = 1) 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->status == 'suspended') { - $model->suspended_at = now(); - } else if ($model->status == 'running') { - $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); - }); - } } diff --git a/app/Models/Module.php b/app/Models/Module.php index 4c1c32a..191a7f8 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -13,13 +13,12 @@ class Module extends Authenticatable { use Cachable; - protected $table = 'modules'; + public $incrementing = false; // primary key - public $incrementing = false; - protected $keyType = 'string'; public $timestamps = false; - + protected $table = 'modules'; + protected $keyType = 'string'; protected $fillable = [ 'id', 'name', @@ -32,6 +31,16 @@ class Module extends Authenticatable 'wecom_key' ]; + protected static function boot() + { + parent::boot(); + static::creating(function ($model) { + // if local + if (!app()->environment('local')) { + $model->api_token = Str::random(60); + } + }); + } public function remoteHost($host_id, $func, $requests) { @@ -44,6 +53,9 @@ public function remoteHost($host_id, $func, $requests) return [$json, $status]; } + + // post, get, patch, delete 等请求 + public function remote($func, $requests) { $http = Http::module($this->api_token, $this->url); @@ -55,8 +67,6 @@ public function remote($func, $requests) return [$json, $status]; } - - // post, get, patch, delete 等请求 public function remoteRequest($method, $path, $requests) { $user = auth()->user(); @@ -115,8 +125,6 @@ public function moduleRequest($method, $path, $requests) ]; } - - public function remotePost($path = '', $data = []) { $http = Http::module($this->api_token, $this->url); @@ -128,6 +136,15 @@ public function remotePost($path = '', $data = []) return [$json, $status]; } + + // // get cached modules + // public static function cached_modules() + // { + // return Cache::remember('modules', 600, function () { + // return Module::all(); + // }); + // } + public function check($module_id = null) { if ($module_id) { @@ -150,24 +167,4 @@ public function check($module_id = null) return false; } } - - - // // get cached modules - // public static function cached_modules() - // { - // return Cache::remember('modules', 600, function () { - // return Module::all(); - // }); - // } - - protected static function boot() - { - parent::boot(); - static::creating(function ($model) { - // if local - if (!app()->environment('local')) { - $model->api_token = Str::random(60); - } - }); - } } diff --git a/app/Models/PersonalAccessToken.php b/app/Models/PersonalAccessToken.php index 80da42f..bbae467 100644 --- a/app/Models/PersonalAccessToken.php +++ b/app/Models/PersonalAccessToken.php @@ -16,7 +16,8 @@ class PersonalAccessToken extends SanctumPersonalAccessToken * the last_used_at column that has changed. It prevents extra DB writes * since we aren't going to use that column for anything. * - * @param array $options + * @param array $options + * * @return bool */ public function save(array $options = []) diff --git a/app/Models/Task.php b/app/Models/Task.php index e2a14ce..781803d 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -16,43 +16,21 @@ class Task extends Model { use HasFactory, Cachable; + public $incrementing = false; protected $fillable = [ 'host_id', 'title', 'progress', 'status', ]; - protected $casts = [ 'id' => 'string', 'progress' => 'integer', ]; - public $incrementing = false; - // key type string protected $keyType = 'string'; - public function scopeUser($query) - { - return $query->where('user_id', auth()->id()); - } - - - public function getCurrentUserTasks() - { - return Cache::remember('user_tasks_' . auth()->id(), 3600, function () { - return $this->user()->with('host')->latest()->get(); - }); - } - - - public function host() - { - return $this->belongsTo(Host::class); - } - - // before create protected static function boot() { parent::boot(); @@ -82,7 +60,6 @@ protected static function boot() // dd($host); - $model->user_id = $model->host->user_id; Cache::forget('user_tasks_' . $model->user_id); @@ -117,4 +94,23 @@ protected static function boot() broadcast(new UserEvent($model->user_id, 'tasks.deleted', $model)); }); } + + public function scopeUser($query) + { + return $query->where('user_id', auth()->id()); + } + + public function getCurrentUserTasks() + { + return Cache::remember('user_tasks_' . auth()->id(), 3600, function () { + return $this->user()->with('host')->latest()->get(); + }); + } + + // before create + + public function host() + { + return $this->belongsTo(Host::class); + } } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index aa0db0e..1149221 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -13,12 +13,11 @@ class Transaction extends Model { // $t = (new App\Models\Transaction)->create(['name' => 1]) + const UPDATED_AT = null; protected $connection = 'mongodb'; - protected $collection = 'transactions'; // 停用 updated_at - const UPDATED_AT = null; - + protected $collection = 'transactions'; protected $dates = [ 'created_at', 'updated_at', @@ -70,32 +69,11 @@ public function scopeThisUser($query) return $query->where('user_id', auth()->id()); } - - public function getDrops($user_id = null): float - { - // - if (!$user_id) { - $user_id = auth()->id(); - } - - $cache_key = 'user_drops_' . $user_id; - - $drops = Cache::get($cache_key, [ - 'drops' => 0, - ]); - - // 保留 8 位 - $drops['drops'] = round($drops['drops'], 8); - - return $drops['drops']; - } - public function increaseCurrentUserDrops($amount = 0) { return $this->increaseDrops(auth()->id(), $amount); } - public function increaseDrops($user_id, $amount = 0) { $cache_key = 'user_drops_' . $user_id; @@ -111,7 +89,6 @@ public function increaseDrops($user_id, $amount = 0) return $current_drops['drops']; } - public function reduceDrops($user_id, $host_id, $module_id, $auto = 1, $amount = 0) { @@ -136,7 +113,6 @@ public function reduceDrops($user_id, $host_id, $module_id, $auto = 1, $amount = $this->addPayoutDrops($user_id, $amount, $description, $host_id, $module_id); } - public function addPayoutDrops($user_id, $amount, $description, $host_id, $module_id) { $data = [ @@ -163,186 +139,6 @@ public function addPayoutDrops($user_id, $amount, $description, $host_id, $modul return $this->addLog($user_id, $data); } - - public function addIncomeDrops($user_id, $amount, $description) - { - $data = [ - 'type' => 'income', - 'payment' => 'balances', - 'description' => $description, - 'income' => 0, - 'income_drops' => (float)$amount, - 'outcome' => 0, - 'outcome_drops' => 0, - ]; - - return $this->addLog($user_id, $data); - } - - public function addIncomeBalances($user_id, $payment, $amount, $description) - { - $data = [ - 'type' => 'income', - 'payment' => $payment, - 'description' => $description, - 'income' => (float)$amount, - 'income_drops' => 0, - 'outcome' => 0, - 'outcome_drops' => 0, - ]; - - return $this->addLog($user_id, $data); - } - - public function addPayoutBalances($user_id, $amount, $description, $module_id = null) - { - $data = [ - 'type' => 'payout', - 'payment' => 'balances', - 'description' => $description, - 'income' => 0, - 'income_drops' => 0, - 'outcome' => (float)$amount, - 'outcome_drops' => 0 - ]; - - if ($module_id) { - $data['module_id'] = $module_id; - } - - return $this->addLog($user_id, $data); - } - - public function addHostPayoutBalances($user_id, $host_id, $module_id, $amount, $description) - { - $data = [ - 'type' => 'payout', - 'payment' => 'balances', - 'description' => $description, - 'income' => 0, - 'income_drops' => 0, - 'outcome' => (float)$amount, - 'outcome_drops' => 0, - 'host_id' => $host_id, - 'module_id' => $module_id, - ]; - - return $this->addLog($user_id, $data); - } - - - public function reduceAmount($user_id, $amount = 0, $description = '扣除费用请求。') - { - - $lock = Cache::lock("user_balances_lock_" . $user_id, 10); - try { - - $lock->block(5); - - $user = User::findOrFail($user_id); - - $user->balances -= $amount; - $user->save(); - - $this->addPayoutBalances($user_id, $amount, $description); - - return $user->balances; - } finally { - optional($lock)->release(); - } - - return false; - } - - public function reduceAmountModuleFail($user_id, $module_id, $amount = 0, $description = '扣除费用请求。') - { - - $lock = Cache::lock("user_balances_lock_" . $user_id, 10); - try { - - $lock->block(5); - - $user = User::findOrFail($user_id); - - $user->balances -= $amount; - - // if balances < 0 - if ($user->balances < 0) { - throw new BalanceNotEnoughException('余额不足。'); - } - - $user->save(); - - $this->addPayoutBalances($user_id, $amount, $description, $module_id); - - return $user->balances; - } finally { - optional($lock)->release(); - } - - return false; - } - - - public function reduceHostAmount($user_id, $host_id, $module_id, $amount = 0, $description = '扣除费用请求。') - { - - $lock = Cache::lock("user_balances_lock_" . $user_id, 10); - try { - - $lock->block(5); - - $user = User::findOrFail($user_id); - - $user->balances -= $amount; - $user->save(); - - $this->addHostPayoutBalances($user_id, $host_id, $module_id, $amount, $description); - - return $user->balances; - } finally { - optional($lock)->release(); - } - - return false; - } - - /** - * @throws ChargeException - */ - public function addAmount($user_id, $payment = 'console', $amount = 0, $description = null) - { - $lock = Cache::lock("user_balances_lock_" . $user_id, 10); - try { - - $lock->block(5); - - $user = User::findOrFail($user_id); - - $left_balances = $user->balances + $amount; - - $user->increment('balances', $amount); - - if (!$description) { - $description = '充值金额。'; - } else { - $description = '充值 ' . $amount . ' 元'; - } - - $this->addIncomeBalances($user_id, $payment, $amount, $description); - - return $left_balances; - } catch (LockTimeoutException $e) { - Log::error($e); - throw new ChargeException('充值失败,请稍后再试。'); - } finally { - optional($lock)->release(); - } - - return false; - } - - private function addLog($user_id, $data) { $user = User::find($user_id); @@ -362,4 +158,199 @@ private function addLog($user_id, $data) return $this->create($data); } + + public function getDrops($user_id = null): float + { + // + if (!$user_id) { + $user_id = auth()->id(); + } + + $cache_key = 'user_drops_' . $user_id; + + $drops = Cache::get($cache_key, [ + 'drops' => 0, + ]); + + // 保留 8 位 + $drops['drops'] = round($drops['drops'], 8); + + return $drops['drops']; + } + + public function addIncomeDrops($user_id, $amount, $description) + { + $data = [ + 'type' => 'income', + 'payment' => 'balances', + 'description' => $description, + 'income' => 0, + 'income_drops' => (float)$amount, + 'outcome' => 0, + 'outcome_drops' => 0, + ]; + + return $this->addLog($user_id, $data); + } + + public function reduceAmount($user_id, $amount = 0, $description = '扣除费用请求。') + { + + $lock = Cache::lock("user_balance_lock_" . $user_id, 10); + try { + + $lock->block(5); + + $user = User::findOrFail($user_id); + + $user->balance -= $amount; + $user->save(); + + $this->addPayoutBalance($user_id, $amount, $description); + + return $user->balance; + } finally { + optional($lock)->release(); + } + + return false; + } + + public function addPayoutBalance($user_id, $amount, $description, $module_id = null) + { + $data = [ + 'type' => 'payout', + 'payment' => 'balances', + 'description' => $description, + 'income' => 0, + 'income_drops' => 0, + 'outcome' => (float)$amount, + 'outcome_drops' => 0 + ]; + + if ($module_id) { + $data['module_id'] = $module_id; + } + + return $this->addLog($user_id, $data); + } + + public function reduceAmountModuleFail($user_id, $module_id, $amount = 0, $description = '扣除费用请求。') + { + + $lock = Cache::lock("user_balance_lock_" . $user_id, 10); + try { + + $lock->block(5); + + $user = User::findOrFail($user_id); + + $user->balance -= $amount; + + // if balance < 0 + if ($user->balance < 0) { + throw new BalanceNotEnoughException('余额不足。'); + } + + $user->save(); + + $this->addPayoutBalance($user_id, $amount, $description, $module_id); + + return $user->balance; + } finally { + optional($lock)->release(); + } + + return false; + } + + public function reduceHostAmount($user_id, $host_id, $module_id, $amount = 0, $description = '扣除费用请求。') + { + + $lock = Cache::lock("user_balance_lock_" . $user_id, 10); + try { + + $lock->block(5); + + $user = User::findOrFail($user_id); + + $user->balance -= $amount; + $user->save(); + + $this->addHostPayoutBalance($user_id, $host_id, $module_id, $amount, $description); + + return $user->balance; + } finally { + optional($lock)->release(); + } + + return false; + } + + public function addHostPayoutBalance($user_id, $host_id, $module_id, $amount, $description) + { + $data = [ + 'type' => 'payout', + 'payment' => 'balances', + 'description' => $description, + 'income' => 0, + 'income_drops' => 0, + 'outcome' => (float)$amount, + 'outcome_drops' => 0, + 'host_id' => $host_id, + 'module_id' => $module_id, + ]; + + return $this->addLog($user_id, $data); + } + + /** + * @throws ChargeException + */ + public function addAmount($user_id, $payment = 'console', $amount = 0, $description = null) + { + $lock = Cache::lock("user_balance_lock_" . $user_id, 10); + try { + + $lock->block(5); + + $user = User::findOrFail($user_id); + + $left_balance = $user->balance + $amount; + + $user->increment('balance', $amount); + + if (!$description) { + $description = '充值金额。'; + } else { + $description = '充值 ' . $amount . ' 元'; + } + + $this->addIncomeBalance($user_id, $payment, $amount, $description); + + return $left_balance; + } catch (LockTimeoutException $e) { + Log::error($e); + throw new ChargeException('充值失败,请稍后再试。'); + } finally { + optional($lock)->release(); + } + + return false; + } + + public function addIncomeBalance($user_id, $payment, $amount, $description) + { + $data = [ + 'type' => 'income', + 'payment' => $payment, + 'description' => $description, + 'income' => (float)$amount, + 'income_drops' => 0, + 'outcome' => 0, + 'outcome_drops' => 0, + ]; + + return $this->addLog($user_id, $data); + } } diff --git a/app/Models/User.php b/app/Models/User.php index 9895122..af30c97 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -44,7 +44,21 @@ class User extends Authenticatable 'banned_at' => 'datetime', ]; + protected static function boot() + { + parent::boot(); + static::updating(function ($model) { + + // balance 四舍五入 + $model->balance = round($model->balance, 2); + }); + } + + /** + * @throws CommonException + * @throws BalanceNotEnoughException + */ public function toDrops($amount = 1) { @@ -98,15 +112,4 @@ public function toDrops($amount = 1) return $this; } - - protected static function boot() - { - parent::boot(); - - static::updating(function ($model) { - - // balance 四舍五入 - $model->balance = round($model->balance, 2); - }); - } } diff --git a/app/Models/WorkOrder/Reply.php b/app/Models/WorkOrder/Reply.php index 7a64eb8..1838ae5 100644 --- a/app/Models/WorkOrder/Reply.php +++ b/app/Models/WorkOrder/Reply.php @@ -22,23 +22,6 @@ class Reply extends Model 'is_pending', ]; - public function workOrder() - { - return $this->belongsTo(WorkOrder::class, 'work_order_id', 'id'); - } - - public function user() - { - return $this->belongsTo(User::class); - } - - public function scopeWorkOrderId($query, $work_order_id) - { - return $query->where('work_order_id', $work_order_id); - } - - - // before create protected static function boot() { parent::boot(); @@ -79,4 +62,22 @@ protected static function boot() dispatch(new \App\Jobs\Module\WorkOrder\WorkOrder($model->workOrder, 'put')); }); } + + public function workOrder() + { + return $this->belongsTo(WorkOrder::class, 'work_order_id', 'id'); + } + + public function user() + { + return $this->belongsTo(User::class); + } + + + // before create + + public function scopeWorkOrderId($query, $work_order_id) + { + return $query->where('work_order_id', $work_order_id); + } } diff --git a/app/Models/WorkOrder/WorkOrder.php b/app/Models/WorkOrder/WorkOrder.php index 374d10c..f4f0dc4 100644 --- a/app/Models/WorkOrder/WorkOrder.php +++ b/app/Models/WorkOrder/WorkOrder.php @@ -26,41 +26,7 @@ class WorkOrder extends Model ]; // user - public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo - { - return $this->belongsTo(User::class); - } - // replies - public function replies(): \Illuminate\Database\Eloquent\Relations\HasMany - { - return $this->hasMany(Reply::class); - } - - // host - public function host(): \Illuminate\Database\Eloquent\Relations\BelongsTo - { - return $this->belongsTo(Host::class); - } - - public function module(): \Illuminate\Database\Eloquent\Relations\BelongsTo - { - return $this->belongsTo(Module::class); - } - - // scope - public function scopeThisModule($query) - { - return $query->where('module_id', auth('module')->id()); - } - - public function scopeThisUser($query) - { - return $query->where('user_id', auth()->id()); - } - - - // on create protected static function boot() { parent::boot(); @@ -104,4 +70,43 @@ protected static function boot() dispatch(new \App\Jobs\Module\WorkOrder\WorkOrder($model, 'put')); }); } + + // replies + + public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(User::class); + } + + // host + + public function replies(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany(Reply::class); + } + + public function host(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Host::class); + } + + // scope + + public function module(): \Illuminate\Database\Eloquent\Relations\BelongsTo + { + return $this->belongsTo(Module::class); + } + + public function scopeThisModule($query) + { + return $query->where('module_id', auth('module')->id()); + } + + + // on create + + public function scopeThisUser($query) + { + return $query->where('user_id', auth()->id()); + } } diff --git a/app/Notifications/ModuleEarnings.php b/app/Notifications/ModuleEarnings.php index 78fbebe..16e7332 100644 --- a/app/Notifications/ModuleEarnings.php +++ b/app/Notifications/ModuleEarnings.php @@ -27,7 +27,8 @@ public function __construct(Module $module) /** * Get the mail representation of the notification. * - * @param mixed $notifiable + * @param mixed $notifiable + * * @return \Illuminate\Notifications\Messages\MailMessage */ public function toGroup($notifiable) diff --git a/app/Notifications/UserBalanceNotification.php b/app/Notifications/UserBalanceNotification.php index 96b2fb0..44f9f2a 100644 --- a/app/Notifications/UserBalanceNotification.php +++ b/app/Notifications/UserBalanceNotification.php @@ -27,7 +27,8 @@ public function __construct() /** * Get the notification's delivery channels. * - * @param mixed $notifiable + * @param mixed $notifiable + * * @return array */ public function via($notifiable) @@ -49,7 +50,7 @@ public function toGroup($notifiable) $data = [ - 'balance' => $notifiable, + 'balances' => $notifiable, 'user' => $user, ]; diff --git a/app/Notifications/WorkOrderNotification.php b/app/Notifications/WorkOrderNotification.php index a5d530d..854e7ab 100644 --- a/app/Notifications/WorkOrderNotification.php +++ b/app/Notifications/WorkOrderNotification.php @@ -28,7 +28,8 @@ public function __construct() /** * Get the notification's delivery channels. * - * @param mixed $notifiable + * @param mixed $notifiable + * * @return array */ public function via($notifiable) @@ -49,7 +50,7 @@ public function toGroup($notifiable) $workOrder->load(['module', 'user']); $module = $workOrder->module; - } elseif ($notifiable instanceof Reply) { + } else if ($notifiable instanceof Reply) { $view = 'notifications.work_order.reply'; diff --git a/app/Observers/BalanceObserve.php b/app/Observers/BalanceObserve.php index 61d9a7e..448c4ed 100644 --- a/app/Observers/BalanceObserve.php +++ b/app/Observers/BalanceObserve.php @@ -10,33 +10,36 @@ class BalanceObserve /** * Handle the Balance "created" event. * - * @param \App\Models\Balance $balance + * @param \App\Models\Balance $balance + * * @return void */ public function created(Balance $balance) { // return (new UserBalanceNotification()) - ->toGroup($balance); + ->toGroup($balance); } /** * Handle the Balance "updated" event. * - * @param \App\Models\Balance $balance + * @param \App\Models\Balance $balance + * * @return void */ public function updated(Balance $balance) { // return (new UserBalanceNotification()) - ->toGroup($balance); + ->toGroup($balance); } /** * Handle the Balance "deleted" event. * - * @param \App\Models\Balance $balance + * @param \App\Models\Balance $balance + * * @return void */ public function deleted(Balance $balance) @@ -47,7 +50,8 @@ public function deleted(Balance $balance) /** * Handle the Balance "restored" event. * - * @param \App\Models\Balance $balance + * @param \App\Models\Balance $balance + * * @return void */ public function restored(Balance $balance) @@ -58,7 +62,8 @@ public function restored(Balance $balance) /** * Handle the Balance "force deleted" event. * - * @param \App\Models\Balance $balance + * @param \App\Models\Balance $balance + * * @return void */ public function forceDeleted(Balance $balance) diff --git a/app/Observers/WorkOrder/ReplyObserver.php b/app/Observers/WorkOrder/ReplyObserver.php index ffbd8b7..bc0473e 100644 --- a/app/Observers/WorkOrder/ReplyObserver.php +++ b/app/Observers/WorkOrder/ReplyObserver.php @@ -10,7 +10,8 @@ class ReplyObserver /** * Handle the Reply "created" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param \App\Models\WorkOrder\Reply $reply + * * @return void */ public function created(Reply $reply) @@ -23,7 +24,8 @@ public function created(Reply $reply) /** * Handle the Reply "updated" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param \App\Models\WorkOrder\Reply $reply + * * @return void */ public function updated(Reply $reply) @@ -34,7 +36,8 @@ public function updated(Reply $reply) /** * Handle the Reply "deleted" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param \App\Models\WorkOrder\Reply $reply + * * @return void */ public function deleted(Reply $reply) @@ -45,7 +48,8 @@ public function deleted(Reply $reply) /** * Handle the Reply "restored" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param \App\Models\WorkOrder\Reply $reply + * * @return void */ public function restored(Reply $reply) @@ -56,7 +60,8 @@ public function restored(Reply $reply) /** * Handle the Reply "force deleted" event. * - * @param \App\Models\WorkOrder\Reply $reply + * @param \App\Models\WorkOrder\Reply $reply + * * @return void */ public function forceDeleted(Reply $reply) diff --git a/app/Observers/WorkOrder/WorkOrderObserver.php b/app/Observers/WorkOrder/WorkOrderObserver.php index 7cfd9ff..8df357b 100644 --- a/app/Observers/WorkOrder/WorkOrderObserver.php +++ b/app/Observers/WorkOrder/WorkOrderObserver.php @@ -11,7 +11,8 @@ class WorkOrderObserver /** * Handle the WorkOrder "created" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param \App\Models\WorkOrder\WorkOrder $workOrder + * * @return void */ public function created(WorkOrder $workOrder) @@ -24,7 +25,8 @@ public function created(WorkOrder $workOrder) /** * Handle the WorkOrder "updated" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param \App\Models\WorkOrder\WorkOrder $workOrder + * * @return void */ public function updated(WorkOrder $workOrder) @@ -39,7 +41,8 @@ public function updated(WorkOrder $workOrder) /** * Handle the WorkOrder "deleted" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param \App\Models\WorkOrder\WorkOrder $workOrder + * * @return void */ public function deleted(WorkOrder $workOrder) @@ -50,7 +53,8 @@ public function deleted(WorkOrder $workOrder) /** * Handle the WorkOrder "restored" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param \App\Models\WorkOrder\WorkOrder $workOrder + * * @return void */ public function restored(WorkOrder $workOrder) @@ -61,7 +65,8 @@ public function restored(WorkOrder $workOrder) /** * Handle the WorkOrder "force deleted" event. * - * @param \App\Models\WorkOrder\WorkOrder $workOrder + * @param \App\Models\WorkOrder\WorkOrder $workOrder + * * @return void */ public function forceDeleted(WorkOrder $workOrder) diff --git a/artisan b/artisan index 67a3329..0a11434 100755 --- a/artisan +++ b/artisan @@ -15,9 +15,9 @@ define('LARAVEL_START', microtime(true)); | */ -require __DIR__.'/vendor/autoload.php'; +require __DIR__ . '/vendor/autoload.php'; -$app = require_once __DIR__.'/bootstrap/app.php'; +$app = require_once __DIR__ . '/bootstrap/app.php'; /* |-------------------------------------------------------------------------- diff --git a/config/app.php b/config/app.php index 41f0cb6..07b5838 100644 --- a/config/app.php +++ b/config/app.php @@ -42,7 +42,7 @@ | */ - 'debug' => (bool) env('APP_DEBUG', false), + 'debug' => (bool)env('APP_DEBUG', false), /* |-------------------------------------------------------------------------- @@ -141,7 +141,7 @@ 'maintenance' => [ 'driver' => 'cache', - 'store' => 'redis', + 'store' => 'redis', ], /* diff --git a/config/broadcasting.php b/config/broadcasting.php index 9e4d4aa..4dbd22c 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -36,7 +36,7 @@ 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ - 'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com', + 'host' => env('PUSHER_HOST') ?: 'api-' . env('PUSHER_APP_CLUSTER', 'mt1') . '.pusher.com', 'port' => env('PUSHER_PORT', 443), 'scheme' => env('PUSHER_SCHEME', 'https'), 'encrypted' => true, diff --git a/config/filesystems.php b/config/filesystems.php index e9d9dbd..4afc1fc 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -39,7 +39,7 @@ 'public' => [ 'driver' => 'local', 'root' => storage_path('app/public'), - 'url' => env('APP_URL').'/storage', + 'url' => env('APP_URL') . '/storage', 'visibility' => 'public', 'throw' => false, ], diff --git a/config/logging.php b/config/logging.php index 5aa1dbb..752af71 100644 --- a/config/logging.php +++ b/config/logging.php @@ -85,7 +85,7 @@ 'handler_with' => [ 'host' => env('PAPERTRAIL_URL'), 'port' => env('PAPERTRAIL_PORT'), - 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), + 'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'), ], ], diff --git a/config/pay.php b/config/pay.php index f4eb7a6..b9d085b 100644 --- a/config/pay.php +++ b/config/pay.php @@ -85,7 +85,7 @@ 'connect_timeout' => 5.0, // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html) ], - // optional,默认 warning;日志路径为:sys_get_temp_dir().'/logs/yansongda.pay.log' + // optional,默认 warning;日志路径为:sys_get_temp_dir().'/logs/yansongda.balances.log' 'logger' => [ 'enable' => false, 'file' => null, diff --git a/config/session.php b/config/session.php index 8fed97c..1b99f22 100644 --- a/config/session.php +++ b/config/session.php @@ -128,7 +128,7 @@ 'cookie' => env( 'SESSION_COOKIE', - Str::slug(env('APP_NAME', 'laravel'), '_').'_session' + Str::slug(env('APP_NAME', 'laravel'), '_') . '_session' ), /* diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 41f8ae8..09e48af 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -33,7 +33,7 @@ public function definition() */ public function unverified() { - return $this->state(fn (array $attributes) => [ + return $this->state(fn(array $attributes) => [ 'email_verified_at' => null, ]); } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index b8ab975..76767b3 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_100000_create_password_resets_table.php index fcacb80..440f474 100644 --- a/database/migrations/2014_10_12_100000_create_password_resets_table.php +++ b/database/migrations/2014_10_12_100000_create_password_resets_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php index 1719198..262db10 100644 --- a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php +++ b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php index 6c81fd2..a399be0 100644 --- a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_12_081236_create_drops_table.php b/database/migrations/2022_08_12_081236_create_drops_table.php index 3e06978..59df2f0 100644 --- a/database/migrations/2022_08_12_081236_create_drops_table.php +++ b/database/migrations/2022_08_12_081236_create_drops_table.php @@ -5,8 +5,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -17,7 +16,7 @@ public function up() Schema::create('drops', function (Blueprint $table) { $table->id(); - // payment + // payment $table->string('payment')->index(); // amount diff --git a/database/migrations/2022_08_12_082631_create_transcations_table.php b/database/migrations/2022_08_12_082631_create_transcations_table.php index 7a0d875..03ec94f 100644 --- a/database/migrations/2022_08_12_082631_create_transcations_table.php +++ b/database/migrations/2022_08_12_082631_create_transcations_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_12_084822_add_type_to_drops_table.php b/database/migrations/2022_08_12_084822_add_type_to_drops_table.php index b74c429..b43566f 100644 --- a/database/migrations/2022_08_12_084822_add_type_to_drops_table.php +++ b/database/migrations/2022_08_12_084822_add_type_to_drops_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_12_123308_create_modules_table.php b/database/migrations/2022_08_12_123308_create_modules_table.php index 90cb8fe..14f0306 100644 --- a/database/migrations/2022_08_12_123308_create_modules_table.php +++ b/database/migrations/2022_08_12_123308_create_modules_table.php @@ -5,8 +5,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_13_051148_create_hosts_table.php b/database/migrations/2022_08_13_051148_create_hosts_table.php index 564f806..629e9c1 100644 --- a/database/migrations/2022_08_13_051148_create_hosts_table.php +++ b/database/migrations/2022_08_13_051148_create_hosts_table.php @@ -5,8 +5,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_13_051705_create_workorders_table.php b/database/migrations/2022_08_13_051705_create_workorders_table.php index f0c2f98..7d32d62 100644 --- a/database/migrations/2022_08_13_051705_create_workorders_table.php +++ b/database/migrations/2022_08_13_051705_create_workorders_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_13_051817_create_workorder_replies_table.php b/database/migrations/2022_08_13_051817_create_workorder_replies_table.php index 02824b6..170e943 100644 --- a/database/migrations/2022_08_13_051817_create_workorder_replies_table.php +++ b/database/migrations/2022_08_13_051817_create_workorder_replies_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_13_083908_create_notifications_table.php b/database/migrations/2022_08_13_083908_create_notifications_table.php index 4357c9e..3d6cbf7 100644 --- a/database/migrations/2022_08_13_083908_create_notifications_table.php +++ b/database/migrations/2022_08_13_083908_create_notifications_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_15_104635_add_managed_price_to_hosts_table.php b/database/migrations/2022_08_15_104635_add_managed_price_to_hosts_table.php index bddf669..cac99c8 100644 --- a/database/migrations/2022_08_15_104635_add_managed_price_to_hosts_table.php +++ b/database/migrations/2022_08_15_104635_add_managed_price_to_hosts_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_15_141837_set_user_id_nullable_to_work_order_replies.php b/database/migrations/2022_08_15_141837_set_user_id_nullable_to_work_order_replies.php index a769458..5b23ef5 100644 --- a/database/migrations/2022_08_15_141837_set_user_id_nullable_to_work_order_replies.php +++ b/database/migrations/2022_08_15_141837_set_user_id_nullable_to_work_order_replies.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_19_082540_add_url_to_modules_table.php b/database/migrations/2022_08_19_082540_add_url_to_modules_table.php index b366537..c770175 100644 --- a/database/migrations/2022_08_19_082540_add_url_to_modules_table.php +++ b/database/migrations/2022_08_19_082540_add_url_to_modules_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_25_142429_create_tasks_table.php b/database/migrations/2022_08_25_142429_create_tasks_table.php index f0852c1..f116229 100644 --- a/database/migrations/2022_08_25_142429_create_tasks_table.php +++ b/database/migrations/2022_08_25_142429_create_tasks_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_29_094841_add_suspended_at_to_hosts_table.php b/database/migrations/2022_08_29_094841_add_suspended_at_to_hosts_table.php index dbce206..8f8f570 100644 --- a/database/migrations/2022_08_29_094841_add_suspended_at_to_hosts_table.php +++ b/database/migrations/2022_08_29_094841_add_suspended_at_to_hosts_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_08_30_081930_add_balance_to_users_table.php b/database/migrations/2022_08_30_081930_add_balance_to_users_table.php index 18489d8..1506a80 100644 --- a/database/migrations/2022_08_30_081930_add_balance_to_users_table.php +++ b/database/migrations/2022_08_30_081930_add_balance_to_users_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -15,7 +14,7 @@ public function up() { Schema::table('users', function (Blueprint $table) { // - $table->decimal('balance', 10, 2)->default(0)->after('password'); + $table->decimal('balances', 10, 2)->default(0)->after('password'); // drop column if exists if (Schema::hasColumn('users', 'drops')) { @@ -33,7 +32,7 @@ public function down() { Schema::table('users', function (Blueprint $table) { // - $table->dropColumn('balance'); + $table->dropColumn('balances'); }); } }; diff --git a/database/migrations/2022_09_01_033240_create_balances_table.php b/database/migrations/2022_09_01_033240_create_balances_table.php index 3d276fd..0e547b8 100644 --- a/database/migrations/2022_09_01_033240_create_balances_table.php +++ b/database/migrations/2022_09_01_033240_create_balances_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_09_03_070656_add_module_id_to_hosts.php b/database/migrations/2022_09_03_070656_add_module_id_to_hosts.php index 0d423f6..c5516a6 100644 --- a/database/migrations/2022_09_03_070656_add_module_id_to_hosts.php +++ b/database/migrations/2022_09_03_070656_add_module_id_to_hosts.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_09_08_135104_delete_drops_from_users.php b/database/migrations/2022_09_08_135104_delete_drops_from_users.php index 809b425..09d4e45 100644 --- a/database/migrations/2022_09_08_135104_delete_drops_from_users.php +++ b/database/migrations/2022_09_08_135104_delete_drops_from_users.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_09_13_191255_add_banned_at_to_users.php b/database/migrations/2022_09_13_191255_add_banned_at_to_users.php index e8aa195..d145cb2 100644 --- a/database/migrations/2022_09_13_191255_add_banned_at_to_users.php +++ b/database/migrations/2022_09_13_191255_add_banned_at_to_users.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * @@ -15,7 +14,7 @@ public function up() { Schema::table('users', function (Blueprint $table) { // - $table->dateTime('banned_at')->nullable()->comment('封禁时间')->after('balance'); + $table->dateTime('banned_at')->nullable()->comment('封禁时间')->after('balances'); // reason $table->string('banned_reason')->nullable()->after('banned_at'); }); diff --git a/database/migrations/2022_09_14_214642_drop_transcations_table.php b/database/migrations/2022_09_14_214642_drop_transcations_table.php index 0e2914e..0320060 100644 --- a/database/migrations/2022_09_14_214642_drop_transcations_table.php +++ b/database/migrations/2022_09_14_214642_drop_transcations_table.php @@ -3,8 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_09_14_215159_create_transactions_table.php b/database/migrations/2022_09_14_215159_create_transactions_table.php index 2316cf3..231f4b0 100644 --- a/database/migrations/2022_09_14_215159_create_transactions_table.php +++ b/database/migrations/2022_09_14_215159_create_transactions_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_10_03_123715_convert_user_drops.php b/database/migrations/2022_10_03_123715_convert_user_drops.php index df7c26e..787f6c3 100644 --- a/database/migrations/2022_10_03_123715_convert_user_drops.php +++ b/database/migrations/2022_10_03_123715_convert_user_drops.php @@ -4,8 +4,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\Cache; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_10_31_161617_add_wecom_hook_to_modules.php b/database/migrations/2022_10_31_161617_add_wecom_hook_to_modules.php index eaa1c9d..dd8df96 100644 --- a/database/migrations/2022_10_31_161617_add_wecom_hook_to_modules.php +++ b/database/migrations/2022_10_31_161617_add_wecom_hook_to_modules.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_11_02_103610_create_admins_table.php b/database/migrations/2022_11_02_103610_create_admins_table.php index 2691777..96acec2 100644 --- a/database/migrations/2022_11_02_103610_create_admins_table.php +++ b/database/migrations/2022_11_02_103610_create_admins_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_11_06_205842_add_remaining_amount_to_balances.php b/database/migrations/2022_11_06_205842_add_remaining_amount_to_balances.php index a60c716..ce19d9f 100644 --- a/database/migrations/2022_11_06_205842_add_remaining_amount_to_balances.php +++ b/database/migrations/2022_11_06_205842_add_remaining_amount_to_balances.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_11_06_205958_drop_drops_table.php b/database/migrations/2022_11_06_205958_drop_drops_table.php index 5474329..04ccd22 100644 --- a/database/migrations/2022_11_06_205958_drop_drops_table.php +++ b/database/migrations/2022_11_06_205958_drop_drops_table.php @@ -3,8 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_11_07_001025_recreate_personal_access_tokens_table.php b/database/migrations/2022_11_07_001025_recreate_personal_access_tokens_table.php index 74e9e96..a703faa 100644 --- a/database/migrations/2022_11_07_001025_recreate_personal_access_tokens_table.php +++ b/database/migrations/2022_11_07_001025_recreate_personal_access_tokens_table.php @@ -4,8 +4,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/database/migrations/2022_11_08_181357_drop_access_tokens_table.php b/database/migrations/2022_11_08_181357_drop_access_tokens_table.php index 7bdf461..4a002f3 100644 --- a/database/migrations/2022_11_08_181357_drop_access_tokens_table.php +++ b/database/migrations/2022_11_08_181357_drop_access_tokens_table.php @@ -3,8 +3,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\Schema; -return new class extends Migration -{ +return new class extends Migration { /** * Run the migrations. * diff --git a/lang/zh_CN/auth.php b/lang/zh_CN/auth.php index 6eb03c0..3de2bb0 100644 --- a/lang/zh_CN/auth.php +++ b/lang/zh_CN/auth.php @@ -1,7 +1,7 @@ '用户名或密码错误。', + 'failed' => '用户名或密码错误。', 'password' => '密码错误', 'throttle' => '您尝试的登录次数过多,请 :seconds 秒后再试。', ]; diff --git a/lang/zh_CN/pagination.php b/lang/zh_CN/pagination.php index e13e040..b6aeca1 100644 --- a/lang/zh_CN/pagination.php +++ b/lang/zh_CN/pagination.php @@ -1,6 +1,6 @@ '下一页 »', + 'next' => '下一页 »', 'previous' => '« 上一页', ]; diff --git a/lang/zh_CN/passwords.php b/lang/zh_CN/passwords.php index a72ab7e..35fbbcb 100644 --- a/lang/zh_CN/passwords.php +++ b/lang/zh_CN/passwords.php @@ -1,9 +1,9 @@ '密码重置成功!', - 'sent' => '密码重置邮件已发送!', + 'reset' => '密码重置成功!', + 'sent' => '密码重置邮件已发送!', 'throttled' => '请稍候再试。', - 'token' => '密码重置令牌无效。', - 'user' => '找不到该邮箱对应的用户。', + 'token' => '密码重置令牌无效。', + 'user' => '找不到该邮箱对应的用户。', ]; diff --git a/lang/zh_CN/validation.php b/lang/zh_CN/validation.php index b003632..208ceee 100644 --- a/lang/zh_CN/validation.php +++ b/lang/zh_CN/validation.php @@ -1,204 +1,204 @@ '您必须接受 :attribute。', - 'accepted_if' => '当 :other 为 :value 时,必须接受 :attribute。', - 'active_url' => ':Attribute 不是一个有效的网址。', - 'after' => ':Attribute 必须要晚于 :date。', - 'after_or_equal' => ':Attribute 必须要等于 :date 或更晚。', - 'alpha' => ':Attribute 只能由字母组成。', - 'alpha_dash' => ':Attribute 只能由字母、数字、短划线(-)和下划线(_)组成。', - 'alpha_num' => ':Attribute 只能由字母和数字组成。', - 'array' => ':Attribute 必须是一个数组。', - 'before' => ':Attribute 必须要早于 :date。', - 'before_or_equal' => ':Attribute 必须要等于 :date 或更早。', - 'between' => [ - 'array' => ':Attribute 必须只有 :min - :max 个单元。', - 'file' => ':Attribute 必须介于 :min - :max KB 之间。', + 'accepted' => '您必须接受 :attribute。', + 'accepted_if' => '当 :other 为 :value 时,必须接受 :attribute。', + 'active_url' => ':Attribute 不是一个有效的网址。', + 'after' => ':Attribute 必须要晚于 :date。', + 'after_or_equal' => ':Attribute 必须要等于 :date 或更晚。', + 'alpha' => ':Attribute 只能由字母组成。', + 'alpha_dash' => ':Attribute 只能由字母、数字、短划线(-)和下划线(_)组成。', + 'alpha_num' => ':Attribute 只能由字母和数字组成。', + 'array' => ':Attribute 必须是一个数组。', + 'before' => ':Attribute 必须要早于 :date。', + 'before_or_equal' => ':Attribute 必须要等于 :date 或更早。', + 'between' => [ + 'array' => ':Attribute 必须只有 :min - :max 个单元。', + 'file' => ':Attribute 必须介于 :min - :max KB 之间。', 'numeric' => ':Attribute 必须介于 :min - :max 之间。', - 'string' => ':Attribute 必须介于 :min - :max 个字符之间。', + 'string' => ':Attribute 必须介于 :min - :max 个字符之间。', ], - 'boolean' => ':Attribute 必须为布尔值。', - 'confirmed' => ':Attribute 两次输入不一致。', - 'current_password' => '密码错误。', - 'date' => ':Attribute 不是一个有效的日期。', - 'date_equals' => ':Attribute 必须要等于 :date。', - 'date_format' => ':Attribute 的格式必须为 :format。', - 'declined' => ':Attribute 必须是拒绝的。', - 'declined_if' => '当 :other 为 :value 时字段 :attribute 必须是拒绝的。', - 'different' => ':Attribute 和 :other 必须不同。', - 'digits' => ':Attribute 必须是 :digits 位数字。', - 'digits_between' => ':Attribute 必须是介于 :min 和 :max 位的数字。', - 'dimensions' => ':Attribute 图片尺寸不正确。', - 'distinct' => ':Attribute 已经存在。', - 'doesnt_end_with' => ':Attribute 不能以以下之一结尾: :values。', - 'doesnt_start_with' => ':Attribute 不能以下列之一开头: :values。', - 'email' => ':Attribute 不是一个合法的邮箱。', - 'ends_with' => ':Attribute 必须以 :values 为结尾。', - 'enum' => ':Attribute 值不正确。', - 'exists' => ':Attribute 不存在。', - 'file' => ':Attribute 必须是文件。', - 'filled' => ':Attribute 不能为空。', - 'gt' => [ - 'array' => ':Attribute 必须多于 :value 个元素。', - 'file' => ':Attribute 必须大于 :value KB。', + 'boolean' => ':Attribute 必须为布尔值。', + 'confirmed' => ':Attribute 两次输入不一致。', + 'current_password' => '密码错误。', + 'date' => ':Attribute 不是一个有效的日期。', + 'date_equals' => ':Attribute 必须要等于 :date。', + 'date_format' => ':Attribute 的格式必须为 :format。', + 'declined' => ':Attribute 必须是拒绝的。', + 'declined_if' => '当 :other 为 :value 时字段 :attribute 必须是拒绝的。', + 'different' => ':Attribute 和 :other 必须不同。', + 'digits' => ':Attribute 必须是 :digits 位数字。', + 'digits_between' => ':Attribute 必须是介于 :min 和 :max 位的数字。', + 'dimensions' => ':Attribute 图片尺寸不正确。', + 'distinct' => ':Attribute 已经存在。', + 'doesnt_end_with' => ':Attribute 不能以以下之一结尾: :values。', + 'doesnt_start_with' => ':Attribute 不能以下列之一开头: :values。', + 'email' => ':Attribute 不是一个合法的邮箱。', + 'ends_with' => ':Attribute 必须以 :values 为结尾。', + 'enum' => ':Attribute 值不正确。', + 'exists' => ':Attribute 不存在。', + 'file' => ':Attribute 必须是文件。', + 'filled' => ':Attribute 不能为空。', + 'gt' => [ + 'array' => ':Attribute 必须多于 :value 个元素。', + 'file' => ':Attribute 必须大于 :value KB。', 'numeric' => ':Attribute 必须大于 :value。', - 'string' => ':Attribute 必须多于 :value 个字符。', + 'string' => ':Attribute 必须多于 :value 个字符。', ], - 'gte' => [ - 'array' => ':Attribute 必须多于或等于 :value 个元素。', - 'file' => ':Attribute 必须大于或等于 :value KB。', + 'gte' => [ + 'array' => ':Attribute 必须多于或等于 :value 个元素。', + 'file' => ':Attribute 必须大于或等于 :value KB。', 'numeric' => ':Attribute 必须大于或等于 :value。', - 'string' => ':Attribute 必须多于或等于 :value 个字符。', + 'string' => ':Attribute 必须多于或等于 :value 个字符。', ], - 'image' => ':Attribute 必须是图片。', - 'in' => '已选的属性 :attribute 无效。', - 'in_array' => ':Attribute 必须在 :other 中。', - 'integer' => ':Attribute 必须是整数。', - 'ip' => ':Attribute 必须是有效的 IP 地址。', - 'ipv4' => ':Attribute 必须是有效的 IPv4 地址。', - 'ipv6' => ':Attribute 必须是有效的 IPv6 地址。', - 'json' => ':Attribute 必须是正确的 JSON 格式。', - 'lt' => [ - 'array' => ':Attribute 必须少于 :value 个元素。', - 'file' => ':Attribute 必须小于 :value KB。', + 'image' => ':Attribute 必须是图片。', + 'in' => '已选的属性 :attribute 无效。', + 'in_array' => ':Attribute 必须在 :other 中。', + 'integer' => ':Attribute 必须是整数。', + 'ip' => ':Attribute 必须是有效的 IP 地址。', + 'ipv4' => ':Attribute 必须是有效的 IPv4 地址。', + 'ipv6' => ':Attribute 必须是有效的 IPv6 地址。', + 'json' => ':Attribute 必须是正确的 JSON 格式。', + 'lt' => [ + 'array' => ':Attribute 必须少于 :value 个元素。', + 'file' => ':Attribute 必须小于 :value KB。', 'numeric' => ':Attribute 必须小于 :value。', - 'string' => ':Attribute 必须少于 :value 个字符。', + 'string' => ':Attribute 必须少于 :value 个字符。', ], - 'lte' => [ - 'array' => ':Attribute 必须少于或等于 :value 个元素。', - 'file' => ':Attribute 必须小于或等于 :value KB。', + 'lte' => [ + 'array' => ':Attribute 必须少于或等于 :value 个元素。', + 'file' => ':Attribute 必须小于或等于 :value KB。', 'numeric' => ':Attribute 必须小于或等于 :value。', - 'string' => ':Attribute 必须少于或等于 :value 个字符。', + 'string' => ':Attribute 必须少于或等于 :value 个字符。', ], - 'mac_address' => ':Attribute 必须是一个有效的 MAC 地址。', - 'max' => [ - 'array' => ':Attribute 最多只有 :max 个单元。', - 'file' => ':Attribute 不能大于 :max KB。', + 'mac_address' => ':Attribute 必须是一个有效的 MAC 地址。', + 'max' => [ + 'array' => ':Attribute 最多只有 :max 个单元。', + 'file' => ':Attribute 不能大于 :max KB。', 'numeric' => ':Attribute 不能大于 :max。', - 'string' => ':Attribute 不能大于 :max 个字符。', + 'string' => ':Attribute 不能大于 :max 个字符。', ], - 'max_digits' => ':Attribute 不能超过 :max 位数。', - 'mimes' => ':Attribute 必须是一个 :values 类型的文件。', - 'mimetypes' => ':Attribute 必须是一个 :values 类型的文件。', - 'min' => [ - 'array' => ':Attribute 至少有 :min 个单元。', - 'file' => ':Attribute 大小不能小于 :min KB。', + 'max_digits' => ':Attribute 不能超过 :max 位数。', + 'mimes' => ':Attribute 必须是一个 :values 类型的文件。', + 'mimetypes' => ':Attribute 必须是一个 :values 类型的文件。', + 'min' => [ + 'array' => ':Attribute 至少有 :min 个单元。', + 'file' => ':Attribute 大小不能小于 :min KB。', 'numeric' => ':Attribute 必须大于等于 :min。', - 'string' => ':Attribute 至少为 :min 个字符。', + 'string' => ':Attribute 至少为 :min 个字符。', ], - 'min_digits' => ':Attribute 必须至少有 :min 位数。', - 'multiple_of' => ':Attribute 必须是 :value 中的多个值。', - 'not_in' => '已选的属性 :attribute 非法。', - 'not_regex' => ':Attribute 的格式错误。', - 'numeric' => ':Attribute 必须是一个数字。', - 'password' => [ - 'letters' => ':Attribute 必须至少包含一个字母。', - 'mixed' => ':Attribute 必须至少包含一个大写字母和一个小写字母。', - 'numbers' => ':Attribute 必须至少包含一个数字。', - 'symbols' => ':Attribute 必须至少包含一个符号。', + 'min_digits' => ':Attribute 必须至少有 :min 位数。', + 'multiple_of' => ':Attribute 必须是 :value 中的多个值。', + 'not_in' => '已选的属性 :attribute 非法。', + 'not_regex' => ':Attribute 的格式错误。', + 'numeric' => ':Attribute 必须是一个数字。', + 'password' => [ + 'letters' => ':Attribute 必须至少包含一个字母。', + 'mixed' => ':Attribute 必须至少包含一个大写字母和一个小写字母。', + 'numbers' => ':Attribute 必须至少包含一个数字。', + 'symbols' => ':Attribute 必须至少包含一个符号。', 'uncompromised' => '给定的 :attribute 出现在数据泄漏中。请选择不同的 :attribute。', ], - 'present' => ':Attribute 必须存在。', - 'prohibited' => ':Attribute 字段被禁止。', - 'prohibited_if' => '当 :other 为 :value 时,禁止 :attribute 字段。', - 'prohibited_unless' => ':Attribute 字段被禁止,除非 :other 位于 :values 中。', - 'prohibits' => ':Attribute 字段禁止出现 :other。', - 'regex' => ':Attribute 格式不正确。', - 'required' => ':Attribute 不能为空。', - 'required_array_keys' => ':Attribute 至少包含指定的键::values.', - 'required_if' => '当 :other 为 :value 时 :attribute 不能为空。', + 'present' => ':Attribute 必须存在。', + 'prohibited' => ':Attribute 字段被禁止。', + 'prohibited_if' => '当 :other 为 :value 时,禁止 :attribute 字段。', + 'prohibited_unless' => ':Attribute 字段被禁止,除非 :other 位于 :values 中。', + 'prohibits' => ':Attribute 字段禁止出现 :other。', + 'regex' => ':Attribute 格式不正确。', + 'required' => ':Attribute 不能为空。', + 'required_array_keys' => ':Attribute 至少包含指定的键::values.', + 'required_if' => '当 :other 为 :value 时 :attribute 不能为空。', 'required_if_accepted' => '当 :other 存在时,:attribute 不能为空。', - 'required_unless' => '当 :other 不为 :values 时 :attribute 不能为空。', - 'required_with' => '当 :values 存在时 :attribute 不能为空。', - 'required_with_all' => '当 :values 存在时 :attribute 不能为空。', - 'required_without' => '当 :values 不存在时 :attribute 不能为空。', + 'required_unless' => '当 :other 不为 :values 时 :attribute 不能为空。', + 'required_with' => '当 :values 存在时 :attribute 不能为空。', + 'required_with_all' => '当 :values 存在时 :attribute 不能为空。', + 'required_without' => '当 :values 不存在时 :attribute 不能为空。', 'required_without_all' => '当 :values 都不存在时 :attribute 不能为空。', - 'same' => ':Attribute 和 :other 必须相同。', - 'size' => [ - 'array' => ':Attribute 必须为 :size 个单元。', - 'file' => ':Attribute 大小必须为 :size KB。', + 'same' => ':Attribute 和 :other 必须相同。', + 'size' => [ + 'array' => ':Attribute 必须为 :size 个单元。', + 'file' => ':Attribute 大小必须为 :size KB。', 'numeric' => ':Attribute 大小必须为 :size。', - 'string' => ':Attribute 必须是 :size 个字符。', + 'string' => ':Attribute 必须是 :size 个字符。', ], - 'starts_with' => ':Attribute 必须以 :values 为开头。', - 'string' => ':Attribute 必须是一个字符串。', - 'timezone' => ':Attribute 必须是一个合法的时区值。', - 'unique' => ':Attribute 已经存在。', - 'uploaded' => ':Attribute 上传失败。', - 'url' => ':Attribute 格式不正确。', - 'uuid' => ':Attribute 必须是有效的 UUID。', - 'attributes' => [ - 'address' => '地址', - 'age' => '年龄', - 'amount' => '数额', - 'area' => '区域', - 'available' => '可用的', - 'birthday' => '生日', - 'body' => '身体', - 'city' => '城市', - 'content' => '内容', - 'country' => '国家', - 'created_at' => '创建于', - 'creator' => '创建者', - 'current_password' => '当前密码', - 'date' => '日期', - 'date_of_birth' => '出生日期', - 'day' => '天', - 'deleted_at' => '删除于', - 'description' => '描述', - 'district' => '地区', - 'duration' => '期间', - 'email' => '邮箱', - 'excerpt' => '摘要', - 'filter' => '过滤', - 'first_name' => '名', - 'gender' => '性别', - 'group' => '组', - 'hour' => '时', - 'image' => '图像', - 'last_name' => '姓', - 'lesson' => '课程', - 'line_address_1' => '线路地址 1', - 'line_address_2' => '线路地址 2', - 'message' => '信息', - 'middle_name' => '中间名字', - 'minute' => '分', - 'mobile' => '手机', - 'month' => '月', - 'name' => '名称', - 'national_code' => '国家代码', - 'number' => '数字', - 'password' => '密码', - 'password_confirmation' => '确认密码', - 'phone' => '电话', - 'photo' => '照片', - 'postal_code' => '邮政编码', - 'price' => '价格', - 'province' => '省', + 'starts_with' => ':Attribute 必须以 :values 为开头。', + 'string' => ':Attribute 必须是一个字符串。', + 'timezone' => ':Attribute 必须是一个合法的时区值。', + 'unique' => ':Attribute 已经存在。', + 'uploaded' => ':Attribute 上传失败。', + 'url' => ':Attribute 格式不正确。', + 'uuid' => ':Attribute 必须是有效的 UUID。', + 'attributes' => [ + 'address' => '地址', + 'age' => '年龄', + 'amount' => '数额', + 'area' => '区域', + 'available' => '可用的', + 'birthday' => '生日', + 'body' => '身体', + 'city' => '城市', + 'content' => '内容', + 'country' => '国家', + 'created_at' => '创建于', + 'creator' => '创建者', + 'current_password' => '当前密码', + 'date' => '日期', + 'date_of_birth' => '出生日期', + 'day' => '天', + 'deleted_at' => '删除于', + 'description' => '描述', + 'district' => '地区', + 'duration' => '期间', + 'email' => '邮箱', + 'excerpt' => '摘要', + 'filter' => '过滤', + 'first_name' => '名', + 'gender' => '性别', + 'group' => '组', + 'hour' => '时', + 'image' => '图像', + 'last_name' => '姓', + 'lesson' => '课程', + 'line_address_1' => '线路地址 1', + 'line_address_2' => '线路地址 2', + 'message' => '信息', + 'middle_name' => '中间名字', + 'minute' => '分', + 'mobile' => '手机', + 'month' => '月', + 'name' => '名称', + 'national_code' => '国家代码', + 'number' => '数字', + 'password' => '密码', + 'password_confirmation' => '确认密码', + 'phone' => '电话', + 'photo' => '照片', + 'postal_code' => '邮政编码', + 'price' => '价格', + 'province' => '省', 'recaptcha_response_field' => '重复验证码响应字段', - 'remember' => '记住', - 'restored_at' => '恢复于', - 'result_text_under_image' => '图像下的结果文本', - 'role' => '角色', - 'second' => '秒', - 'sex' => '性别', - 'short_text' => '短文本', - 'size' => '大小', - 'state' => '状态', - 'street' => '街道', - 'student' => '学生', - 'subject' => '主题', - 'teacher' => '教师', - 'terms' => '条款', - 'test_description' => '测试说明', - 'test_locale' => '测试语言环境', - 'test_name' => '测试名称', - 'text' => '文本', - 'time' => '时间', - 'title' => '标题', - 'updated_at' => '更新于', - 'username' => '用户名', - 'year' => '年', + 'remember' => '记住', + 'restored_at' => '恢复于', + 'result_text_under_image' => '图像下的结果文本', + 'role' => '角色', + 'second' => '秒', + 'sex' => '性别', + 'short_text' => '短文本', + 'size' => '大小', + 'state' => '状态', + 'street' => '街道', + 'student' => '学生', + 'subject' => '主题', + 'teacher' => '教师', + 'terms' => '条款', + 'test_description' => '测试说明', + 'test_locale' => '测试语言环境', + 'test_name' => '测试名称', + 'text' => '文本', + 'time' => '时间', + 'title' => '标题', + 'updated_at' => '更新于', + 'username' => '用户名', + 'year' => '年', ], ]; diff --git a/public/index.php b/public/index.php index 5e81d35..f3c2ebc 100644 --- a/public/index.php +++ b/public/index.php @@ -1,7 +1,7 @@ make(Kernel::class); diff --git a/resources/js/bootstrap.js b/resources/js/bootstrap.js index 58c3fed..244b40c 100644 --- a/resources/js/bootstrap.js +++ b/resources/js/bootstrap.js @@ -1,6 +1,4 @@ import _ from 'lodash'; -window._ = _; - import 'bootstrap'; /** @@ -8,8 +6,10 @@ import 'bootstrap'; * to our Laravel back-end. This library automatically handles sending the * CSRF token as a header based on the value of the "XSRF" token cookie. */ - import axios from 'axios'; + +window._ = _; + window.axios = axios; window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; diff --git a/resources/views/admin/index.blade.php b/resources/views/admin/index.blade.php index 3756134..fd96372 100644 --- a/resources/views/admin/index.blade.php +++ b/resources/views/admin/index.blade.php @@ -4,6 +4,6 @@ @section('content') -欢迎来到后台管理系统 + 欢迎来到后台管理系统 @endsection diff --git a/resources/views/admin/login.blade.php b/resources/views/admin/login.blade.php index 6dabfab..d293b15 100644 --- a/resources/views/admin/login.blade.php +++ b/resources/views/admin/login.blade.php @@ -16,11 +16,11 @@
+ class="form-control @error('email') is-invalid @enderror" name="email" + value="{{ old('email') }}" required autocomplete="email" autofocus> @error('email') - + {{ $message }} @enderror @@ -32,11 +32,12 @@ class="form-control @error('email') is-invalid @enderror" name="email"
+ class="form-control @error('password') is-invalid @enderror" name="password" + required + autocomplete="current-password"> @error('password') - + {{ $message }} @enderror diff --git a/resources/views/admin/users/index.blade.php b/resources/views/admin/users/index.blade.php index 843aaee..2161328 100644 --- a/resources/views/admin/users/index.blade.php +++ b/resources/views/admin/users/index.blade.php @@ -4,6 +4,6 @@ @section('content') -欢迎来到后台管理系统 + 欢迎来到后台管理系统 @endsection diff --git a/resources/views/balances/index.blade.php b/resources/views/balances/index.blade.php new file mode 100644 index 0000000..25e7830 --- /dev/null +++ b/resources/views/balances/index.blade.php @@ -0,0 +1,19 @@ +@extends('layouts.app') + +@section('title', '余额') + +@section('content') +

余额

+ + +

您的余额: {{ $balance }} 元

+

Drops: {{ $drops }}

+ +
+ @csrf + + +
+ + +@endsection diff --git a/resources/views/pay.blade.php b/resources/views/balances/pay.blade.php similarity index 67% rename from resources/views/pay.blade.php rename to resources/views/balances/pay.blade.php index 280c0be..5ae1086 100644 --- a/resources/views/pay.blade.php +++ b/resources/views/balances/pay.blade.php @@ -2,12 +2,12 @@ - + 支付订单 - {!! $html !!} +{!! $html !!} diff --git a/resources/views/banned.blade.php b/resources/views/banned.blade.php index d3003cb..16d9f30 100644 --- a/resources/views/banned.blade.php +++ b/resources/views/banned.blade.php @@ -10,10 +10,10 @@ -

很抱歉,您可能违反了我们的规定。

-

{{ auth()->user()->banned_reason }}

+

很抱歉,您可能违反了我们的规定。

+

{{ auth()->user()->banned_reason }}

- 更换账号 +更换账号 diff --git a/resources/views/components/alert.blade.php b/resources/views/components/alert.blade.php index eaa4644..2131c9b 100644 --- a/resources/views/components/alert.blade.php +++ b/resources/views/components/alert.blade.php @@ -2,22 +2,22 @@ + d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/> + d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm.93-9.412-1 4.705c-.07.34.029.533.304.533.194 0 .487-.07.686-.246l-.088.416c-.287.346-.92.598-1.465.598-.703 0-1.002-.422-.808-1.319l.738-3.468c.064-.293.006-.399-.287-.47l-.451-.081.082-.381 2.29-.287zM8 5.5a1 1 0 1 1 0-2 1 1 0 0 1 0 2z"/> + d="M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/> @if (session('error'))