修复 充值

This commit is contained in:
iVampireSP.com 2022-08-13 17:47:10 +08:00
parent bc85e6c1f0
commit f5d5929028
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
11 changed files with 636 additions and 11 deletions

View File

@ -34,7 +34,7 @@ public function store(Request $request)
$data = [
'payment' => 'admin',
'amount' => $request->amount,
'amount' => intval($request->amount),
'status' => 1,
'user_id' => $request->route('user'),
'type' => 'add',

View File

@ -0,0 +1,122 @@
<?php
namespace App\Http\Controllers\Remote;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Ramsey\Uuid\Uuid;
class TaskController extends Controller
{
public $user_id, $host_id;
public function __construct(Request $request)
{
$request->validate([
'host_id' => 'sometimes|integer|exists:hosts,id',
'user_id' => 'integer|exists:users,id',
]);
$this->user_id = $request->user_id;
$this->host_id = $request->host_id;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
$request->validate([
'title' => 'required|max:255',
'progress' => 'sometimes|integer|max:100',
'status' => 'required|in:pending,processing,need_operation,done,success,failed,error,canceled',
]);
return $this->created($this->pushTask([
'title' => $request->title,
'progress' => $request->progress,
'status' => $request->status,
]));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$request->validate([
'id' => 'max:40|required',
]);
$tasks = $this->getTasks();
// check if task exists
if (!isset($tasks[$id])) {
// create task
$task = [
'title' => $request->title,
'progress' => 0,
'status' => $request->status,
];
$this->pushTask($task, $request->id);
} else {
$task = $tasks[$id];
}
// patch task
$task = array_merge($task, $request->only(['title', 'progress', 'status']));
// update task
$this->pushTask($task, $request->id);
}
public function getTasks()
{
$cache_key = 'user_tasks_' . $this->user_id;
return Cache::get($cache_key, []);
}
public function pushTask($task, $id = null)
{
$cache_key = 'user_tasks_' . $this->user_id;
$data = [
'user_id' => $this->user_id,
'done_at' => null,
'host_id' => $this->host_id
];
if ($id === null) {
$data['id'] = Uuid::uuid6()->toString();
} else {
$data['id'] = $id;
}
$task = array_merge($task, $data);
$tasks = $this->getTasks();
$tasks[] = $task;
Cache::put($cache_key, $tasks, 600);
return $task;
}
}

View File

@ -13,10 +13,20 @@ class Drop extends Model
{
use HasFactory, Lock;
protected $cache_key, $cache;
protected $fillable = [
'payment', 'amount', 'user_id', 'type'
];
// casts
protected $casts = [
'amount' => 'double',
'total' => 'double',
'rate' => 'integer',
'status' => 'boolean',
];
// user
public function user()
{
@ -41,9 +51,28 @@ public static function boot()
// created
self::created(function ($drops) {
$drop = new self();
$drop->await('user_drops_' . $drops->user_id, function () use ($drops) {
$drops->user->drops += $drops->total;
$drops->user->save();
$drop->await('user_' . $drops->user_id, function () use ($drops) {
$cache = Cache::tags(['users']);
$drops->load('user');
$cache_key = 'user_' . $drops->user_id;
// if cache has user
if ($cache->has($cache_key)) {
$user = $cache->get($cache_key);
if (!($user instanceof User)) {
$user = $drops->user;
}
$user->drops += $drops->total;
$cache->put($cache_key, $user, 600);
$user->save();
} else {
$drops->user->drops += $drops->total;
$drops->user->save();
}
});
});
}

View File

@ -0,0 +1,49 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class CommonNotification extends Notification
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
// title
// 'title' => $this->,
];
}
}

View File

@ -6,6 +6,7 @@
"license": "MIT",
"require": {
"php": "^8.0.2",
"doctrine/dbal": "^3.3",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.19",
"laravel/horizon": "^5.9",

422
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "4cf71a6a9ffdf51850bec92dd6da12ee",
"content-hash": "f0cfd82920c282a29cd54ef1abb2d4ea",
"packages": [
{
"name": "brick/math",
@ -149,6 +149,371 @@
},
"time": "2021-08-13T13:06:58+00:00"
},
{
"name": "doctrine/cache",
"version": "2.2.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
"reference": "1ca8f21980e770095a31456042471a57bc4c68fb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/cache/zipball/1ca8f21980e770095a31456042471a57bc4c68fb",
"reference": "1ca8f21980e770095a31456042471a57bc4c68fb",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": "~7.1 || ^8.0"
},
"conflict": {
"doctrine/common": ">2.2,<2.4"
},
"require-dev": {
"cache/integration-tests": "dev-master",
"doctrine/coding-standard": "^9",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"symfony/cache": "^4.4 || ^5.4 || ^6",
"symfony/var-exporter": "^4.4 || ^5.4 || ^6"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Common\\Cache\\": "lib/Doctrine/Common/Cache"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
}
],
"description": "PHP Doctrine Cache library is a popular cache implementation that supports many different drivers such as redis, memcache, apc, mongodb and others.",
"homepage": "https://www.doctrine-project.org/projects/cache.html",
"keywords": [
"abstraction",
"apcu",
"cache",
"caching",
"couchdb",
"memcached",
"php",
"redis",
"xcache"
],
"support": {
"issues": "https://github.com/doctrine/cache/issues",
"source": "https://github.com/doctrine/cache/tree/2.2.0"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fcache",
"type": "tidelift"
}
],
"time": "2022-05-20T20:07:39+00:00"
},
{
"name": "doctrine/dbal",
"version": "3.3.8",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
"reference": "f873a820227bc352d023791775a01f078a30dfe1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/dbal/zipball/f873a820227bc352d023791775a01f078a30dfe1",
"reference": "f873a820227bc352d023791775a01f078a30dfe1",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"composer-runtime-api": "^2",
"doctrine/cache": "^1.11|^2.0",
"doctrine/deprecations": "^0.5.3|^1",
"doctrine/event-manager": "^1.0",
"php": "^7.3 || ^8.0",
"psr/cache": "^1|^2|^3",
"psr/log": "^1|^2|^3"
},
"require-dev": {
"doctrine/coding-standard": "9.0.0",
"jetbrains/phpstorm-stubs": "2022.1",
"phpstan/phpstan": "1.8.2",
"phpstan/phpstan-strict-rules": "^1.3",
"phpunit/phpunit": "9.5.21",
"psalm/plugin-phpunit": "0.17.0",
"squizlabs/php_codesniffer": "3.7.1",
"symfony/cache": "^5.2|^6.0",
"symfony/console": "^2.7|^3.0|^4.0|^5.0|^6.0",
"vimeo/psalm": "4.24.0"
},
"suggest": {
"symfony/console": "For helpful console commands such as SQL execution and import of files."
},
"bin": [
"bin/doctrine-dbal"
],
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\DBAL\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
}
],
"description": "Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.",
"homepage": "https://www.doctrine-project.org/projects/dbal.html",
"keywords": [
"abstraction",
"database",
"db2",
"dbal",
"mariadb",
"mssql",
"mysql",
"oci8",
"oracle",
"pdo",
"pgsql",
"postgresql",
"queryobject",
"sasql",
"sql",
"sqlite",
"sqlserver",
"sqlsrv"
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
"source": "https://github.com/doctrine/dbal/tree/3.3.8"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
"type": "tidelift"
}
],
"time": "2022-08-05T15:35:35+00:00"
},
{
"name": "doctrine/deprecations",
"version": "v1.0.0",
"source": {
"type": "git",
"url": "https://github.com/doctrine/deprecations.git",
"reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de",
"reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": "^7.1|^8.0"
},
"require-dev": {
"doctrine/coding-standard": "^9",
"phpunit/phpunit": "^7.5|^8.5|^9.5",
"psr/log": "^1|^2|^3"
},
"suggest": {
"psr/log": "Allows logging deprecations via PSR-3 logger implementation"
},
"type": "library",
"autoload": {
"psr-4": {
"Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.",
"homepage": "https://www.doctrine-project.org/",
"support": {
"issues": "https://github.com/doctrine/deprecations/issues",
"source": "https://github.com/doctrine/deprecations/tree/v1.0.0"
},
"time": "2022-05-02T15:47:09+00:00"
},
{
"name": "doctrine/event-manager",
"version": "1.1.1",
"source": {
"type": "git",
"url": "https://github.com/doctrine/event-manager.git",
"reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/doctrine/event-manager/zipball/41370af6a30faa9dc0368c4a6814d596e81aba7f",
"reference": "41370af6a30faa9dc0368c4a6814d596e81aba7f",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": "^7.1 || ^8.0"
},
"conflict": {
"doctrine/common": "<2.9@dev"
},
"require-dev": {
"doctrine/coding-standard": "^6.0",
"phpunit/phpunit": "^7.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Doctrine\\Common\\": "lib/Doctrine/Common"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Guilherme Blanco",
"email": "guilhermeblanco@gmail.com"
},
{
"name": "Roman Borschel",
"email": "roman@code-factory.org"
},
{
"name": "Benjamin Eberlei",
"email": "kontakt@beberlei.de"
},
{
"name": "Jonathan Wage",
"email": "jonwage@gmail.com"
},
{
"name": "Johannes Schmitt",
"email": "schmittjoh@gmail.com"
},
{
"name": "Marco Pivetta",
"email": "ocramius@gmail.com"
}
],
"description": "The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.",
"homepage": "https://www.doctrine-project.org/projects/event-manager.html",
"keywords": [
"event",
"event dispatcher",
"event manager",
"event system",
"events"
],
"support": {
"issues": "https://github.com/doctrine/event-manager/issues",
"source": "https://github.com/doctrine/event-manager/tree/1.1.x"
},
"funding": [
{
"url": "https://www.doctrine-project.org/sponsorship.html",
"type": "custom"
},
{
"url": "https://www.patreon.com/phpdoctrine",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/doctrine%2Fevent-manager",
"type": "tidelift"
}
],
"time": "2020-05-29T18:28:51+00:00"
},
{
"name": "doctrine/inflector",
"version": "2.0.4",
@ -2472,6 +2837,61 @@
],
"time": "2021-12-04T23:24:31+00:00"
},
{
"name": "psr/cache",
"version": "3.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/cache.git",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"reference": "aa5030cfa5405eccfdcb1083ce040c2cb8d253bf",
"shasum": "",
"mirrors": [
{
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
"preferred": true
}
]
},
"require": {
"php": ">=8.0.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
}
},
"autoload": {
"psr-4": {
"Psr\\Cache\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for caching libraries",
"keywords": [
"cache",
"psr",
"psr-6"
],
"support": {
"source": "https://github.com/php-fig/cache/tree/3.0.0"
},
"time": "2021-02-03T23:26:27+00:00"
},
{
"name": "psr/container",
"version": "2.0.2",

View File

@ -21,7 +21,7 @@ public function up()
$table->string('password')->nullable();
// 积分(8位小数点)
$table->double('drops', 8, 6)->default(0);
$table->double('drops', 60, 8)->default(0);
$table->rememberToken();
$table->timestamps();

View File

@ -21,13 +21,13 @@ public function up()
$table->string('payment')->index();
// amount
$table->decimal('amount', 8, 2)->default(0);
$table->double('amount', 60, 8)->default(0);
// 汇率
$table->integer('rate')->default(1);
// 实际收入
$table->double('total', 8, 6)->default(0);
$table->double('total', 60, 8)->default(0);
$table->boolean('status')->default(0)->index();

View File

@ -27,7 +27,7 @@ public function up()
$table->string('payment')->index();
// amount
$table->double('amount', 8, 6)->default(0);
$table->double('amount', 60, 8)->default(0);
$table->timestamps();

View File

@ -28,7 +28,7 @@ public function up()
$table->foreignIdFor(User::class)->index();
// price
$table->double('price', 8, 6)->index();
$table->double('price', 60, 8)->index();
// config
$table->json('configuration')->nullable();

View File

@ -1,6 +1,7 @@
<?php
use App\Models\User;
use App\Models\User\Host;
use App\Models\Module\ProviderModule;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
@ -24,7 +25,7 @@ public function up()
$table->integer('progress')->default(0);
// status
$table->enum('status', ['pending', 'done', 'success', 'failed', 'error', 'cancelled', 'processing'])->index();
$table->enum('status', ['pending', 'done', 'success', 'failed', 'error', 'cancelled', 'processing', 'need_operation'])->index();
// user id
$table->foreignIdFor(User::class)->index();
@ -32,6 +33,9 @@ public function up()
// provider module id
$table->foreignIdFor(ProviderModule::class)->index();
// host id
$table->foreignIdFor(Host::class)->index();
$table->timestamps();
});
}