优化导入,格式化代码
分离出充值系统 修复了充值的问题
This commit is contained in:
parent
1be6dea757
commit
4918efa597
@ -48,7 +48,7 @@ public function handle()
|
|||||||
|
|
||||||
$user = User::find($user_id);
|
$user = User::find($user_id);
|
||||||
|
|
||||||
$this->warn('扣除金额: ' . $user->balance . ' 元');
|
$this->warn('扣除金额: ' . $amount . ' 元');
|
||||||
|
|
||||||
$this->warn('用户当前余额:' . $user->balance . ' 元');
|
$this->warn('用户当前余额:' . $user->balance . ' 元');
|
||||||
|
|
||||||
|
@ -109,7 +109,6 @@ public function handle()
|
|||||||
$this->info('Redis 总命令数: ' . $redis_total_commands_processed);
|
$this->info('Redis 总命令数: ' . $redis_total_commands_processed);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->warn('===== 莱云 统计 =====');
|
$this->warn('===== 莱云 统计 =====');
|
||||||
$this->warn('要获取 莱云 统计信息,请运行 count 命令。');
|
$this->warn('要获取 莱云 统计信息,请运行 count 命令。');
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ class Kernel extends ConsoleKernel
|
|||||||
* Define the application's command schedule.
|
* Define the application's command schedule.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function schedule(Schedule $schedule)
|
protected function schedule(Schedule $schedule)
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
use Illuminate\Auth\AuthenticationException;
|
use Illuminate\Auth\AuthenticationException;
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Illuminate\Http\JsonResponse;
|
|
||||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
|
@ -5,6 +5,25 @@
|
|||||||
trait ApiResponse
|
trait ApiResponse
|
||||||
{
|
{
|
||||||
// RESTful API response
|
// 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)
|
public function apiResponse($data = [], $status = 200)
|
||||||
{
|
{
|
||||||
// if data is paginated, return paginated data
|
// 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);
|
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
|
// not found
|
||||||
public function notFound($message = 'Not found')
|
|
||||||
{
|
|
||||||
return $this->error($message, 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
// forbidden
|
|
||||||
public function forbidden($message = 'Forbidden')
|
public function forbidden($message = 'Forbidden')
|
||||||
{
|
{
|
||||||
return $this->error($message, 403);
|
return $this->error($message, 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
// unauthorized
|
// forbidden
|
||||||
|
|
||||||
public function unauthorized($message = 'Unauthorized')
|
public function unauthorized($message = 'Unauthorized')
|
||||||
{
|
{
|
||||||
return $this->error($message, 401);
|
return $this->error($message, 401);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bad request
|
// unauthorized
|
||||||
|
|
||||||
public function badRequest($message = 'Bad request')
|
public function badRequest($message = 'Bad request')
|
||||||
{
|
{
|
||||||
return $this->error($message, 400);
|
return $this->error($message, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// created
|
// bad request
|
||||||
|
|
||||||
public function created($message = 'Created')
|
public function created($message = 'Created')
|
||||||
{
|
{
|
||||||
return $this->success($message, 201);
|
return $this->success($message, 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// created
|
||||||
|
|
||||||
|
public function success($data = [])
|
||||||
|
{
|
||||||
|
return $this->apiResponse($data, 200);
|
||||||
|
}
|
||||||
|
|
||||||
// accepted
|
// accepted
|
||||||
|
|
||||||
public function accepted($message = 'Accepted')
|
public function accepted($message = 'Accepted')
|
||||||
{
|
{
|
||||||
return $this->success($message, 202);
|
return $this->success($message, 202);
|
||||||
|
@ -6,8 +6,10 @@
|
|||||||
use Illuminate\Contracts\Cache\LockTimeoutException;
|
use Illuminate\Contracts\Cache\LockTimeoutException;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
trait Lock {
|
trait Lock
|
||||||
public function await($name, Closure $callback) {
|
{
|
||||||
|
public function await($name, Closure $callback)
|
||||||
|
{
|
||||||
// if env is local
|
// if env is local
|
||||||
if (env('APP_ENV') == 'local') {
|
if (env('APP_ENV') == 'local') {
|
||||||
return $callback();
|
return $callback();
|
||||||
|
@ -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'))) {
|
if (auth('admin')->attempt($request->only('email', 'password'))) {
|
||||||
return redirect()->route('admin.index');
|
return redirect()->route('admin.index');
|
||||||
} else {
|
} else {
|
||||||
|
@ -31,6 +31,7 @@ public function create()
|
|||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
@ -42,6 +43,7 @@ public function store(Request $request)
|
|||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
@ -53,6 +55,7 @@ public function show($id)
|
|||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
@ -65,6 +68,7 @@ public function edit($id)
|
|||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, $id)
|
||||||
@ -76,6 +80,7 @@ public function update(Request $request, $id)
|
|||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
|
@ -2,134 +2,30 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Exceptions\ChargeException;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Balance;
|
use App\Models\Balance;
|
||||||
use App\Models\Transaction;
|
use App\Models\Transaction;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Yansongda\LaravelPay\Facades\Pay;
|
use Yansongda\LaravelPay\Facades\Pay;
|
||||||
use Yansongda\Pay\Exception\InvalidResponseException;
|
use Yansongda\Pay\Exception\InvalidResponseException;
|
||||||
use function auth;
|
use function auth;
|
||||||
use function config;
|
use function config;
|
||||||
use function now;
|
use function now;
|
||||||
use function route;
|
|
||||||
use function view;
|
|
||||||
|
|
||||||
class BalanceController extends Controller
|
class BalanceController extends Controller
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
||||||
public function index(Request $request)
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
$balances = Balance::thisUser()->simplePaginate(30);
|
$balances = Balance::thisUser()->simplePaginate(30);
|
||||||
return $this->success($balances);
|
return $this->success($balances);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(Request $request)
|
public function checkAndCharge(Balance $balance, $check = false): JsonResponse|bool
|
||||||
{
|
|
||||||
// 充值
|
|
||||||
$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)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($check) {
|
if ($check) {
|
||||||
@ -150,8 +46,13 @@ public function checkAndCharge(Balance $balance, $check = false)
|
|||||||
$balance->update([
|
$balance->update([
|
||||||
'paid_at' => now()
|
'paid_at' => now()
|
||||||
]);
|
]);
|
||||||
} catch (InvalidResponseException) {
|
} catch (InvalidResponseException $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
return $this->error('无法验证支付结果。');
|
return $this->error('无法验证支付结果。');
|
||||||
|
} catch (ChargeException $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
return $this->error('暂时无法处理充值。');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -161,6 +62,7 @@ public function checkAndCharge(Balance $balance, $check = false)
|
|||||||
* 获取交易记录
|
* 获取交易记录
|
||||||
*
|
*
|
||||||
* @param mixed $request
|
* @param mixed $request
|
||||||
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function transactions(Request $request): JsonResponse
|
public function transactions(Request $request): JsonResponse
|
||||||
|
@ -23,13 +23,6 @@ public function __construct()
|
|||||||
$this->http = Http::baseUrl($this->baseUrl . '/api')->throw();
|
$this->http = Http::baseUrl($this->baseUrl . '/api')->throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($url)
|
|
||||||
{
|
|
||||||
$resp = $this->http->get($url)->json()['data'];
|
|
||||||
return $resp;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function announcements()
|
public function announcements()
|
||||||
{
|
{
|
||||||
$resp = $this->cache(function () {
|
$resp = $this->cache(function () {
|
||||||
@ -39,16 +32,6 @@ public function announcements()
|
|||||||
return $this->resp($resp);
|
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)
|
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)
|
public function resp($data)
|
||||||
{
|
{
|
||||||
@ -66,4 +54,13 @@ public function resp($data)
|
|||||||
|
|
||||||
return $this->success($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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
public function broadcast_to_host(Request $request, Host $host)
|
||||||
{
|
{
|
||||||
$this->validate($request, $this->rules());
|
$this->validate($request, $this->rules());
|
||||||
@ -37,10 +44,4 @@ public function broadcast_to_host(Request $request, Host $host)
|
|||||||
|
|
||||||
return $this->created($request->message);
|
return $this->created($request->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function rules() {
|
|
||||||
return [
|
|
||||||
'message' => 'required',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,22 @@ public function index()
|
|||||||
return $this->success($data);
|
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)
|
public function call(Request $request, Module $module)
|
||||||
{
|
{
|
||||||
$path = request()->path();
|
$path = request()->path();
|
||||||
@ -58,7 +74,6 @@ public function call(Request $request, Module $module)
|
|||||||
return $this->remoteResponse($response['json'], $response['status']);
|
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
|
public function exportCall(Request $request, Module $module): \Illuminate\Http\Response|\Illuminate\Http\JsonResponse|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory
|
||||||
{
|
{
|
||||||
$path = request()->path();
|
$path = request()->path();
|
||||||
@ -76,21 +91,4 @@ public function exportCall(Request $request, Module $module): \Illuminate\Http\R
|
|||||||
|
|
||||||
return $this->remoteResponse($response['json'], $response['status']);
|
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),
|
|
||||||
]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public function index(Request $request)
|
|||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
|
*
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
class WorkOrderController extends Controller
|
class WorkOrderController extends Controller
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
public function index(Request $request, WorkOrder $workOrder) {
|
public function index(Request $request, WorkOrder $workOrder)
|
||||||
|
{
|
||||||
// $work_orders = new WorkOrder();
|
// $work_orders = new WorkOrder();
|
||||||
// // if route has user
|
// // if route has user
|
||||||
// if ($request->route('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);
|
return $this->success($workOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers\Web;
|
||||||
|
|
||||||
// use App\Helpers\ApiResponse;
|
// use App\Helpers\ApiResponse;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\ClientException;
|
use GuzzleHttp\Exception\ClientException;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use function back;
|
||||||
|
use function config;
|
||||||
|
use function now;
|
||||||
|
use function redirect;
|
||||||
|
use function session;
|
||||||
|
use function view;
|
||||||
|
|
||||||
class AuthController extends Controller
|
class AuthController extends Controller
|
||||||
{
|
{
|
137
app/Http/Controllers/Web/BalanceController.php
Normal file
137
app/Http/Controllers/Web/BalanceController.php
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Web;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\Balance;
|
||||||
|
use App\Models\Transaction;
|
||||||
|
use Illuminate\Contracts\View\View;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Yansongda\LaravelPay\Facades\Pay;
|
||||||
|
|
||||||
|
class BalanceController extends Controller
|
||||||
|
{
|
||||||
|
//
|
||||||
|
|
||||||
|
public function index(Request $request): View
|
||||||
|
{
|
||||||
|
|
||||||
|
$transaction = new Transaction();
|
||||||
|
|
||||||
|
$drops = $transaction->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, '支付失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ class Authenticate extends Middleware
|
|||||||
* Get the path the user should be redirected to when they are not authenticated.
|
* 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
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
protected function redirectTo($request)
|
protected function redirectTo($request)
|
||||||
|
@ -15,6 +15,7 @@ class RedirectIfAuthenticated
|
|||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
|
||||||
* @param string|null ...$guards
|
* @param string|null ...$guards
|
||||||
|
*
|
||||||
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function handle(Request $request, Closure $next, ...$guards)
|
public function handle(Request $request, Closure $next, ...$guards)
|
||||||
|
@ -38,7 +38,7 @@ public function handle()
|
|||||||
|
|
||||||
// this month transactions
|
// this month transactions
|
||||||
$this_month = [
|
$this_month = [
|
||||||
'balance' => $this_month->sum('outcome'),
|
'balances' => $this_month->sum('outcome'),
|
||||||
'drops' => $this_month->sum('outcome_drops')
|
'drops' => $this_month->sum('outcome_drops')
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ public function handle()
|
|||||||
$last_moth = Transaction::where('module_id', $module->id)->where('type', 'payout')->whereBetween('created_at', [$beginOfMonth, $endOfMonth]);
|
$last_moth = Transaction::where('module_id', $module->id)->where('type', 'payout')->whereBetween('created_at', [$beginOfMonth, $endOfMonth]);
|
||||||
|
|
||||||
$last_moth = [
|
$last_moth = [
|
||||||
'balance' => $last_moth->sum('outcome'),
|
'balances' => $last_moth->sum('outcome'),
|
||||||
'drops' => $last_moth->sum('outcome_drops')
|
'drops' => $last_moth->sum('outcome_drops')
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ class Host implements ShouldQueue
|
|||||||
|
|
||||||
public HostModel $host;
|
public HostModel $host;
|
||||||
public string $type;
|
public string $type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
|
@ -17,6 +17,7 @@ class Reply implements ShouldQueue
|
|||||||
use InteractsWithQueue, Queueable, SerializesModels;
|
use InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
protected $reply;
|
protected $reply;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new job instance.
|
* Create a new job instance.
|
||||||
*
|
*
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
|
|
||||||
class Admin extends Authenticatable
|
class Admin extends Authenticatable
|
||||||
{
|
{
|
||||||
|
@ -38,6 +38,55 @@ class Host extends Model
|
|||||||
|
|
||||||
|
|
||||||
// get user hosts
|
// 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)
|
public function getUserHosts($user_id = null)
|
||||||
{
|
{
|
||||||
return $this->where('user_id', $user_id)->with('module', function ($query) {
|
return $this->where('user_id', $user_id)->with('module', function ($query) {
|
||||||
@ -45,31 +94,35 @@ public function getUserHosts($user_id = null)
|
|||||||
})->get();
|
})->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// module
|
||||||
|
|
||||||
// user
|
|
||||||
public function user(): BelongsToAlias
|
public function user(): BelongsToAlias
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// module
|
// workOrders
|
||||||
|
|
||||||
public function module(): BelongsToAlias
|
public function module(): BelongsToAlias
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Module::class);
|
return $this->belongsTo(Module::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// workOrders
|
// scope
|
||||||
|
|
||||||
public function workOrders(): HasManyAlias
|
public function workOrders(): HasManyAlias
|
||||||
{
|
{
|
||||||
return $this->hasMany(WorkOrder::class);
|
return $this->hasMany(WorkOrder::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
// scope
|
|
||||||
public function scopeActive($query)
|
public function scopeActive($query)
|
||||||
{
|
{
|
||||||
return $query->where('status', 'running')->where('price', '!=', 0);
|
return $query->where('status', 'running')->where('price', '!=', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// cost
|
||||||
|
|
||||||
public function scopeThisUser($query, $module = null)
|
public function scopeThisUser($query, $module = null)
|
||||||
{
|
{
|
||||||
if ($module) {
|
if ($module) {
|
||||||
@ -79,8 +132,6 @@ public function scopeThisUser($query, $module = null)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// cost
|
|
||||||
public function cost($price = null, $auto = true): bool
|
public function cost($price = null, $auto = true): bool
|
||||||
{
|
{
|
||||||
$this->load('user');
|
$this->load('user');
|
||||||
@ -154,8 +205,7 @@ public function cost($price = null, $auto = true): bool
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function costBalance($amount = 1): bool
|
||||||
public function costBalance($amount = 1)
|
|
||||||
{
|
{
|
||||||
$transaction = new Transaction();
|
$transaction = new Transaction();
|
||||||
|
|
||||||
@ -185,49 +235,4 @@ public function costBalance($amount = 1)
|
|||||||
|
|
||||||
return true;
|
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);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,12 @@ class Module extends Authenticatable
|
|||||||
{
|
{
|
||||||
use Cachable;
|
use Cachable;
|
||||||
|
|
||||||
protected $table = 'modules';
|
public $incrementing = false;
|
||||||
|
|
||||||
// primary key
|
// primary key
|
||||||
public $incrementing = false;
|
|
||||||
protected $keyType = 'string';
|
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
protected $table = 'modules';
|
||||||
|
protected $keyType = 'string';
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
@ -32,6 +31,16 @@ class Module extends Authenticatable
|
|||||||
'wecom_key'
|
'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)
|
public function remoteHost($host_id, $func, $requests)
|
||||||
{
|
{
|
||||||
@ -44,6 +53,9 @@ public function remoteHost($host_id, $func, $requests)
|
|||||||
return [$json, $status];
|
return [$json, $status];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// post, get, patch, delete 等请求
|
||||||
|
|
||||||
public function remote($func, $requests)
|
public function remote($func, $requests)
|
||||||
{
|
{
|
||||||
$http = Http::module($this->api_token, $this->url);
|
$http = Http::module($this->api_token, $this->url);
|
||||||
@ -55,8 +67,6 @@ public function remote($func, $requests)
|
|||||||
return [$json, $status];
|
return [$json, $status];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// post, get, patch, delete 等请求
|
|
||||||
public function remoteRequest($method, $path, $requests)
|
public function remoteRequest($method, $path, $requests)
|
||||||
{
|
{
|
||||||
$user = auth()->user();
|
$user = auth()->user();
|
||||||
@ -115,8 +125,6 @@ public function moduleRequest($method, $path, $requests)
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function remotePost($path = '', $data = [])
|
public function remotePost($path = '', $data = [])
|
||||||
{
|
{
|
||||||
$http = Http::module($this->api_token, $this->url);
|
$http = Http::module($this->api_token, $this->url);
|
||||||
@ -128,6 +136,15 @@ public function remotePost($path = '', $data = [])
|
|||||||
return [$json, $status];
|
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)
|
public function check($module_id = null)
|
||||||
{
|
{
|
||||||
if ($module_id) {
|
if ($module_id) {
|
||||||
@ -150,24 +167,4 @@ public function check($module_id = null)
|
|||||||
return false;
|
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ class PersonalAccessToken extends SanctumPersonalAccessToken
|
|||||||
* since we aren't going to use that column for anything.
|
* since we aren't going to use that column for anything.
|
||||||
*
|
*
|
||||||
* @param array $options
|
* @param array $options
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function save(array $options = [])
|
public function save(array $options = [])
|
||||||
|
@ -16,43 +16,21 @@ class Task extends Model
|
|||||||
{
|
{
|
||||||
use HasFactory, Cachable;
|
use HasFactory, Cachable;
|
||||||
|
|
||||||
|
public $incrementing = false;
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'host_id',
|
'host_id',
|
||||||
'title',
|
'title',
|
||||||
'progress',
|
'progress',
|
||||||
'status',
|
'status',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'id' => 'string',
|
'id' => 'string',
|
||||||
'progress' => 'integer',
|
'progress' => 'integer',
|
||||||
];
|
];
|
||||||
|
|
||||||
public $incrementing = false;
|
|
||||||
|
|
||||||
// key type string
|
// key type string
|
||||||
protected $keyType = '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()
|
protected static function boot()
|
||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
@ -82,7 +60,6 @@ protected static function boot()
|
|||||||
// dd($host);
|
// dd($host);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$model->user_id = $model->host->user_id;
|
$model->user_id = $model->host->user_id;
|
||||||
|
|
||||||
Cache::forget('user_tasks_' . $model->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));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,11 @@ class Transaction extends Model
|
|||||||
{
|
{
|
||||||
// $t = (new App\Models\Transaction)->create(['name' => 1])
|
// $t = (new App\Models\Transaction)->create(['name' => 1])
|
||||||
|
|
||||||
|
const UPDATED_AT = null;
|
||||||
protected $connection = 'mongodb';
|
protected $connection = 'mongodb';
|
||||||
protected $collection = 'transactions';
|
|
||||||
|
|
||||||
// 停用 updated_at
|
// 停用 updated_at
|
||||||
const UPDATED_AT = null;
|
protected $collection = 'transactions';
|
||||||
|
|
||||||
protected $dates = [
|
protected $dates = [
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
@ -70,32 +69,11 @@ public function scopeThisUser($query)
|
|||||||
return $query->where('user_id', auth()->id());
|
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)
|
public function increaseCurrentUserDrops($amount = 0)
|
||||||
{
|
{
|
||||||
return $this->increaseDrops(auth()->id(), $amount);
|
return $this->increaseDrops(auth()->id(), $amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function increaseDrops($user_id, $amount = 0)
|
public function increaseDrops($user_id, $amount = 0)
|
||||||
{
|
{
|
||||||
$cache_key = 'user_drops_' . $user_id;
|
$cache_key = 'user_drops_' . $user_id;
|
||||||
@ -111,7 +89,6 @@ public function increaseDrops($user_id, $amount = 0)
|
|||||||
return $current_drops['drops'];
|
return $current_drops['drops'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function reduceDrops($user_id, $host_id, $module_id, $auto = 1, $amount = 0)
|
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);
|
$this->addPayoutDrops($user_id, $amount, $description, $host_id, $module_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function addPayoutDrops($user_id, $amount, $description, $host_id, $module_id)
|
public function addPayoutDrops($user_id, $amount, $description, $host_id, $module_id)
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
@ -163,186 +139,6 @@ public function addPayoutDrops($user_id, $amount, $description, $host_id, $modul
|
|||||||
return $this->addLog($user_id, $data);
|
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)
|
private function addLog($user_id, $data)
|
||||||
{
|
{
|
||||||
$user = User::find($user_id);
|
$user = User::find($user_id);
|
||||||
@ -362,4 +158,199 @@ private function addLog($user_id, $data)
|
|||||||
|
|
||||||
return $this->create($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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,21 @@ class User extends Authenticatable
|
|||||||
'banned_at' => 'datetime',
|
'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)
|
public function toDrops($amount = 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -98,15 +112,4 @@ public function toDrops($amount = 1)
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function boot()
|
|
||||||
{
|
|
||||||
parent::boot();
|
|
||||||
|
|
||||||
static::updating(function ($model) {
|
|
||||||
|
|
||||||
// balance 四舍五入
|
|
||||||
$model->balance = round($model->balance, 2);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,23 +22,6 @@ class Reply extends Model
|
|||||||
'is_pending',
|
'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()
|
protected static function boot()
|
||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
@ -79,4 +62,22 @@ protected static function boot()
|
|||||||
dispatch(new \App\Jobs\Module\WorkOrder\WorkOrder($model->workOrder, 'put'));
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,41 +26,7 @@ class WorkOrder extends Model
|
|||||||
];
|
];
|
||||||
|
|
||||||
// user
|
// 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()
|
protected static function boot()
|
||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
@ -104,4 +70,43 @@ protected static function boot()
|
|||||||
dispatch(new \App\Jobs\Module\WorkOrder\WorkOrder($model, 'put'));
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ public function __construct(Module $module)
|
|||||||
* Get the mail representation of the notification.
|
* Get the mail representation of the notification.
|
||||||
*
|
*
|
||||||
* @param mixed $notifiable
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
* @return \Illuminate\Notifications\Messages\MailMessage
|
* @return \Illuminate\Notifications\Messages\MailMessage
|
||||||
*/
|
*/
|
||||||
public function toGroup($notifiable)
|
public function toGroup($notifiable)
|
||||||
|
@ -28,6 +28,7 @@ public function __construct()
|
|||||||
* Get the notification's delivery channels.
|
* Get the notification's delivery channels.
|
||||||
*
|
*
|
||||||
* @param mixed $notifiable
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function via($notifiable)
|
public function via($notifiable)
|
||||||
@ -49,7 +50,7 @@ public function toGroup($notifiable)
|
|||||||
|
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'balance' => $notifiable,
|
'balances' => $notifiable,
|
||||||
'user' => $user,
|
'user' => $user,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ public function __construct()
|
|||||||
* Get the notification's delivery channels.
|
* Get the notification's delivery channels.
|
||||||
*
|
*
|
||||||
* @param mixed $notifiable
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function via($notifiable)
|
public function via($notifiable)
|
||||||
|
@ -11,6 +11,7 @@ class BalanceObserve
|
|||||||
* Handle the Balance "created" event.
|
* Handle the Balance "created" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Balance $balance
|
* @param \App\Models\Balance $balance
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function created(Balance $balance)
|
public function created(Balance $balance)
|
||||||
@ -24,6 +25,7 @@ public function created(Balance $balance)
|
|||||||
* Handle the Balance "updated" event.
|
* Handle the Balance "updated" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Balance $balance
|
* @param \App\Models\Balance $balance
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function updated(Balance $balance)
|
public function updated(Balance $balance)
|
||||||
@ -37,6 +39,7 @@ public function updated(Balance $balance)
|
|||||||
* Handle the Balance "deleted" event.
|
* Handle the Balance "deleted" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Balance $balance
|
* @param \App\Models\Balance $balance
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function deleted(Balance $balance)
|
public function deleted(Balance $balance)
|
||||||
@ -48,6 +51,7 @@ public function deleted(Balance $balance)
|
|||||||
* Handle the Balance "restored" event.
|
* Handle the Balance "restored" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Balance $balance
|
* @param \App\Models\Balance $balance
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function restored(Balance $balance)
|
public function restored(Balance $balance)
|
||||||
@ -59,6 +63,7 @@ public function restored(Balance $balance)
|
|||||||
* Handle the Balance "force deleted" event.
|
* Handle the Balance "force deleted" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\Balance $balance
|
* @param \App\Models\Balance $balance
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function forceDeleted(Balance $balance)
|
public function forceDeleted(Balance $balance)
|
||||||
|
@ -11,6 +11,7 @@ class ReplyObserver
|
|||||||
* Handle the Reply "created" event.
|
* Handle the Reply "created" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\Reply $reply
|
* @param \App\Models\WorkOrder\Reply $reply
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function created(Reply $reply)
|
public function created(Reply $reply)
|
||||||
@ -24,6 +25,7 @@ public function created(Reply $reply)
|
|||||||
* Handle the Reply "updated" event.
|
* Handle the Reply "updated" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\Reply $reply
|
* @param \App\Models\WorkOrder\Reply $reply
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function updated(Reply $reply)
|
public function updated(Reply $reply)
|
||||||
@ -35,6 +37,7 @@ public function updated(Reply $reply)
|
|||||||
* Handle the Reply "deleted" event.
|
* Handle the Reply "deleted" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\Reply $reply
|
* @param \App\Models\WorkOrder\Reply $reply
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function deleted(Reply $reply)
|
public function deleted(Reply $reply)
|
||||||
@ -46,6 +49,7 @@ public function deleted(Reply $reply)
|
|||||||
* Handle the Reply "restored" event.
|
* Handle the Reply "restored" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\Reply $reply
|
* @param \App\Models\WorkOrder\Reply $reply
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function restored(Reply $reply)
|
public function restored(Reply $reply)
|
||||||
@ -57,6 +61,7 @@ public function restored(Reply $reply)
|
|||||||
* Handle the Reply "force deleted" event.
|
* Handle the Reply "force deleted" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\Reply $reply
|
* @param \App\Models\WorkOrder\Reply $reply
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function forceDeleted(Reply $reply)
|
public function forceDeleted(Reply $reply)
|
||||||
|
@ -12,6 +12,7 @@ class WorkOrderObserver
|
|||||||
* Handle the WorkOrder "created" event.
|
* Handle the WorkOrder "created" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function created(WorkOrder $workOrder)
|
public function created(WorkOrder $workOrder)
|
||||||
@ -25,6 +26,7 @@ public function created(WorkOrder $workOrder)
|
|||||||
* Handle the WorkOrder "updated" event.
|
* Handle the WorkOrder "updated" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function updated(WorkOrder $workOrder)
|
public function updated(WorkOrder $workOrder)
|
||||||
@ -40,6 +42,7 @@ public function updated(WorkOrder $workOrder)
|
|||||||
* Handle the WorkOrder "deleted" event.
|
* Handle the WorkOrder "deleted" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function deleted(WorkOrder $workOrder)
|
public function deleted(WorkOrder $workOrder)
|
||||||
@ -51,6 +54,7 @@ public function deleted(WorkOrder $workOrder)
|
|||||||
* Handle the WorkOrder "restored" event.
|
* Handle the WorkOrder "restored" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function restored(WorkOrder $workOrder)
|
public function restored(WorkOrder $workOrder)
|
||||||
@ -62,6 +66,7 @@ public function restored(WorkOrder $workOrder)
|
|||||||
* Handle the WorkOrder "force deleted" event.
|
* Handle the WorkOrder "force deleted" event.
|
||||||
*
|
*
|
||||||
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
* @param \App\Models\WorkOrder\WorkOrder $workOrder
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function forceDeleted(WorkOrder $workOrder)
|
public function forceDeleted(WorkOrder $workOrder)
|
||||||
|
@ -85,7 +85,7 @@
|
|||||||
'connect_timeout' => 5.0,
|
'connect_timeout' => 5.0,
|
||||||
// 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
|
// 更多配置项请参考 [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' => [
|
'logger' => [
|
||||||
'enable' => false,
|
'enable' => false,
|
||||||
'file' => null,
|
'file' => null,
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
@ -15,7 +14,7 @@ public function up()
|
|||||||
{
|
{
|
||||||
Schema::table('users', function (Blueprint $table) {
|
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
|
// drop column if exists
|
||||||
if (Schema::hasColumn('users', 'drops')) {
|
if (Schema::hasColumn('users', 'drops')) {
|
||||||
@ -33,7 +32,7 @@ public function down()
|
|||||||
{
|
{
|
||||||
Schema::table('users', function (Blueprint $table) {
|
Schema::table('users', function (Blueprint $table) {
|
||||||
//
|
//
|
||||||
$table->dropColumn('balance');
|
$table->dropColumn('balances');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
@ -15,7 +14,7 @@ public function up()
|
|||||||
{
|
{
|
||||||
Schema::table('users', function (Blueprint $table) {
|
Schema::table('users', function (Blueprint $table) {
|
||||||
//
|
//
|
||||||
$table->dateTime('banned_at')->nullable()->comment('封禁时间')->after('balance');
|
$table->dateTime('banned_at')->nullable()->comment('封禁时间')->after('balances');
|
||||||
// reason
|
// reason
|
||||||
$table->string('banned_reason')->nullable()->after('banned_at');
|
$table->string('banned_reason')->nullable()->after('banned_at');
|
||||||
});
|
});
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -4,8 +4,7 @@
|
|||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
return new class extends Migration
|
return new class extends Migration {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Run the migrations.
|
* Run the migrations.
|
||||||
*
|
*
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Contracts\Http\Kernel;
|
use Illuminate\Contracts\Http\Kernel;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
define('LARAVEL_START', microtime(true));
|
define('LARAVEL_START', microtime(true));
|
||||||
|
|
||||||
|
6
resources/js/bootstrap.js
vendored
6
resources/js/bootstrap.js
vendored
@ -1,6 +1,4 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
window._ = _;
|
|
||||||
|
|
||||||
import 'bootstrap';
|
import 'bootstrap';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -8,8 +6,10 @@ import 'bootstrap';
|
|||||||
* to our Laravel back-end. This library automatically handles sending the
|
* 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.
|
* CSRF token as a header based on the value of the "XSRF" token cookie.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
|
window._ = _;
|
||||||
|
|
||||||
window.axios = axios;
|
window.axios = axios;
|
||||||
|
|
||||||
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
|
||||||
|
@ -32,7 +32,8 @@ class="form-control @error('email') is-invalid @enderror" name="email"
|
|||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-6">
|
||||||
<input id="password" type="password"
|
<input id="password" type="password"
|
||||||
class="form-control @error('password') is-invalid @enderror" name="password" required
|
class="form-control @error('password') is-invalid @enderror" name="password"
|
||||||
|
required
|
||||||
autocomplete="current-password">
|
autocomplete="current-password">
|
||||||
|
|
||||||
@error('password')
|
@error('password')
|
||||||
|
19
resources/views/balances/index.blade.php
Normal file
19
resources/views/balances/index.blade.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
@extends('layouts.app')
|
||||||
|
|
||||||
|
@section('title', '余额')
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<h2>余额</h2>
|
||||||
|
|
||||||
|
|
||||||
|
<p>您的余额: {{ $balance }} 元 </p>
|
||||||
|
<p>Drops: {{ $drops }} </p>
|
||||||
|
|
||||||
|
<form name="charge" method="POST" target="_blank" action="{{ route('balances.store') }}">
|
||||||
|
@csrf
|
||||||
|
<input type="number" name="amount" value="1" min="1" max="1000"/>
|
||||||
|
<button type="submit" class="btn btn-primary">充值</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
@endsection
|
@ -22,7 +22,7 @@
|
|||||||
<div id="app">
|
<div id="app">
|
||||||
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
|
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<a class="navbar-brand" href="{{ route('admin.index') }}">
|
<a class="navbar-brand" href="{{ route('index') }}">
|
||||||
{{ config('app.display_name') }}
|
{{ config('app.display_name') }}
|
||||||
</a>
|
</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
|
||||||
@ -38,7 +38,7 @@
|
|||||||
<a class="nav-link" href="{{ route('index') }}">首页</a>
|
<a class="nav-link" href="{{ route('index') }}">首页</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{{ route('index') }}">首页</a>
|
<a class="nav-link" href="{{ route('balances.index') }}">余额</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
@ -2,26 +2,25 @@
|
|||||||
# {{ $module->name }}
|
# {{ $module->name }}
|
||||||
==================================
|
==================================
|
||||||
## 本月
|
## 本月
|
||||||
#### 现金 {{ round($data['transactions']['this_month']['balance'], 2) }} 元
|
#### 现金 {{ round($data['transactions']['this_month']['balances'], 2) }} 元
|
||||||
#### Drops {{ round($data['transactions']['this_month']['drops'], 4) }}
|
#### Drops {{ round($data['transactions']['this_month']['drops'], 4) }}
|
||||||
#### 合计 {{ round($data['transactions']['this_month']['balance'] + $data['transactions']['this_month']['drops'] / $data['rate'], 2) }} 元
|
#### 合计 {{ round($data['transactions']['this_month']['balances'] + $data['transactions']['this_month']['drops'] / $data['rate'], 2) }} 元
|
||||||
==================================
|
==================================
|
||||||
## 上个月
|
## 上个月
|
||||||
#### 现金 {{ round($data['transactions']['last_month']['balance'], 2) }} 元
|
#### 现金 {{ round($data['transactions']['last_month']['balances'], 2) }} 元
|
||||||
#### Drops {{ round($data['transactions']['last_month']['drops'], 4) }}
|
#### Drops {{ round($data['transactions']['last_month']['drops'], 4) }}
|
||||||
#### 合计 {{ round($data['transactions']['last_month']['balance'] + $data['transactions']['last_month']['drops'] / $data['rate'], 2) }} 元
|
#### 合计 {{ round($data['transactions']['last_month']['balances'] + $data['transactions']['last_month']['drops'] / $data['rate'], 2) }} 元
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{{--
|
{{--
|
||||||
$module = $this->http->get('modules')->json()['data'];
|
$module = $this->http->get('modules')->json()['data'];
|
||||||
|
|
||||||
$total = $module['transactions']['this_month']['balance'];
|
$total = $module['transactions']['this_month']['balances'];
|
||||||
|
|
||||||
$drops = $module['transactions']['this_month']['drops'] / $module['rate'];
|
$drops = $module['transactions']['this_month']['drops'] / $module['rate'];
|
||||||
|
|
||||||
if ($drops < 0) { $drops=0; } $total +=$drops; $total=round($total, 2); $module=[ 'balance'=>
|
if ($drops < 0) { $drops=0; } $total +=$drops; $total=round($total, 2); $module=[ 'balances'=>
|
||||||
$module['transactions']['this_month']['balance'],
|
$module['transactions']['this_month']['balances'],
|
||||||
'drops' => $module['transactions']['this_month']['drops'],
|
'drops' => $module['transactions']['this_month']['drops'],
|
||||||
'total' => $total,
|
'total' => $total,
|
||||||
];
|
];
|
||||||
@ -32,7 +31,7 @@
|
|||||||
本月收益
|
本月收益
|
||||||
</h3>
|
</h3>
|
||||||
<p>
|
<p>
|
||||||
直接扣费金额: {{ $module['balance'] }} 元
|
直接扣费金额: {{ $module['balances'] }} 元
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Drops: {{ $module['drops'] }}
|
Drops: {{ $module['drops'] }}
|
||||||
|
@ -1,17 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\Api\BalanceController;
|
use App\Http\Controllers\Web\AuthController;
|
||||||
use App\Http\Controllers\AuthController;
|
use App\Http\Controllers\Web\BalanceController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::prefix('auth')->group(function () {
|
|
||||||
Route::get('redirect', [AuthController::class, 'redirect'])->name('login');
|
|
||||||
Route::get('callback', [AuthController::class, 'callback'])->name('callback');
|
|
||||||
});
|
|
||||||
|
|
||||||
Route::get('/', [AuthController::class, 'index'])->name('index');
|
|
||||||
Route::view('not_verified', 'not_verified')->name('not_verified');
|
|
||||||
|
|
||||||
Route::middleware(['auth'])->group(function () {
|
Route::middleware(['auth'])->group(function () {
|
||||||
Route::view('banned', 'banned')->name('banned');
|
Route::view('banned', 'banned')->name('banned');
|
||||||
|
|
||||||
@ -20,9 +12,22 @@
|
|||||||
|
|
||||||
// logout
|
// logout
|
||||||
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
|
Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
|
||||||
|
|
||||||
|
|
||||||
|
Route::resource('/balances', BalanceController::class);
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::prefix('auth')->group(function () {
|
||||||
|
Route::get('redirect', [AuthController::class, 'redirect'])->name('login');
|
||||||
|
Route::get('callback', [AuthController::class, 'callback'])->name('callback');
|
||||||
|
});
|
||||||
|
|
||||||
Route::get('/balance/{balance}', [BalanceController::class, 'show'])->name('balances.pay.show');
|
Route::get('/', [AuthController::class, 'index'])->name('index');
|
||||||
Route::get('/pay/alipay/notify', [BalanceController::class, 'notify'])->name('balances.alipay.notify');
|
Route::view('not_verified', 'not_verified')->name('not_verified');
|
||||||
|
|
||||||
|
|
||||||
|
Route::get('/balances/{balances}', [BalanceController::class, 'show'])->name('balances.balances.show');
|
||||||
|
Route::get('/balances/alipay/notify', [BalanceController::class, 'notify'])->name('balances.alipay.notify');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user