调整后台发货和动态记录表
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUserSignTextsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_sign_texts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->text('title');
|
||||
$table->text('description')->nullable();
|
||||
$table->text('sub_description')->nullable();
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('user_sign_texts');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUserSignBannersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_sign_banners', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->boolean('type')->default(1);
|
||||
$table->text('title');
|
||||
$table->text('cover')->nullable();
|
||||
$table->boolean('status')->default(1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('user_sign_banners');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUserDynamicsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_dynamics', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('user_id')->index();
|
||||
$table->unsignedBigInteger('operator_id')->nullable()->index();
|
||||
$table->morphs('orderable');
|
||||
$table->string('remark')->nullable();
|
||||
$table->text('source')->nullable();
|
||||
$table->string('state')->nullable()->comment('状态');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('user_dynamics');
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Illuminate\Support\HigherOrderCollectionProxy;
|
||||
use Modules\Gout\Models\GoutCase;
|
||||
use Modules\User\Models\SignConfig;
|
||||
use Modules\User\Models\SignLog;
|
||||
use Modules\User\Models\User;
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace Modules\User\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Encore\Admin\Grid;
|
||||
use Encore\Admin\Layout\Content;
|
||||
use Modules\Gout\Models\GoutCase;
|
||||
use Modules\User\Models\UserStock;
|
||||
use Modules\User\Models\UserStockLog;
|
||||
|
||||
|
||||
23
modules/User/Http/Resources/UserAndIdentityResource.php
Normal file
23
modules/User/Http/Resources/UserAndIdentityResource.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserAndIdentityResource extends JsonResource
|
||||
{
|
||||
public function toArray($request): array
|
||||
{
|
||||
|
||||
return [
|
||||
'user_id' => $this->id,
|
||||
'username' => $this->username,
|
||||
'nickname' => $this->info->nickname ?? '',
|
||||
'avatar' => $this->info->avatar ?? '',
|
||||
'identity' => [
|
||||
'name' => $this->identityFirst()->name,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ use Modules\User\Models\Traits\HasStock;
|
||||
use Modules\User\Models\Traits\HasVipOrders;
|
||||
use Modules\User\Models\Traits\HasWechat;
|
||||
use Modules\User\Models\Order as UserOrder;
|
||||
use Modules\User\Traits\WithUserDynamic;
|
||||
use Overtrue\LaravelFavorite\Traits\Favoriter;
|
||||
use Overtrue\LaravelSubscribe\Traits\Subscriber;
|
||||
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||||
@@ -46,6 +47,7 @@ class User extends Authenticate
|
||||
Traits\HasRelations,
|
||||
Traits\HasSign;
|
||||
|
||||
use WithUserDynamic;
|
||||
const STATUS_INIT = 1;
|
||||
const STATUS_REFUND = 2;
|
||||
|
||||
|
||||
27
modules/User/Models/UserDynamic.php
Normal file
27
modules/User/Models/UserDynamic.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Models;
|
||||
|
||||
|
||||
use App\Models\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Modules\User\Traits\BelongsToUser;
|
||||
|
||||
class UserDynamic extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
|
||||
/**
|
||||
* Notes: 关联模型
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/3/17 13:57
|
||||
* @return MorphTo
|
||||
*/
|
||||
public function orderable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
}
|
||||
66
modules/User/Traits/WithUserDynamic.php
Normal file
66
modules/User/Traits/WithUserDynamic.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\User\Traits;
|
||||
|
||||
use App\Models\Model;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Modules\User\Models\UserDynamic;
|
||||
|
||||
trait WithUserDynamic
|
||||
{
|
||||
|
||||
/**
|
||||
* Notes: 关联动态数据
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/3/17 13:59
|
||||
* @return MorphMany
|
||||
*/
|
||||
public function userDynamics(): MorphMany
|
||||
{
|
||||
return $this->morphMany(UserDynamic::class, 'orderable');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 我的动态
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/3/17 14:00
|
||||
* @return mixed
|
||||
*/
|
||||
public function dynamics()
|
||||
{
|
||||
return $this->hasMany(UserDynamic::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes: 添加动态
|
||||
*
|
||||
* @Author: 玄尘
|
||||
* @Date: 2023/3/17 14:01
|
||||
* @param Model $model
|
||||
* @param int $user_id
|
||||
* @param int $operator_id 操作人
|
||||
* @param string|null $remark
|
||||
* @param array|null $source
|
||||
* @return Builder|\Illuminate\Database\Eloquent\Model
|
||||
*/
|
||||
public function addDynamic(
|
||||
Model $model,
|
||||
int $user_id = 0,
|
||||
int $operator_id = 0,
|
||||
string $remark = null,
|
||||
array $source = null
|
||||
) {
|
||||
return UserDynamic::query()
|
||||
->create([
|
||||
'user_id' => $user_id,
|
||||
'operator_id' => $operator_id,
|
||||
'orderable_type' => get_class($model),
|
||||
'orderable_id' => $model->getKey(),
|
||||
'remark' => $remark,
|
||||
'source' => $source,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user