小程序登录优化

This commit is contained in:
liu
2026-08-10 08:55:22 +08:00
parent c6f69c5c55
commit df7631c7a9
25 changed files with 954 additions and 549 deletions
-14
View File
@@ -29,9 +29,7 @@ class UserModelFactory extends Factory
'unionid' => '',
'phone' => '',
'avatar' => '',
'type' => UserModel::TYPE_PENDING,
'store_id' => 0,
'supplier_id' => 0,
'status' => UserModel::STATUS_NORMAL,
'last_login_at' => null,
];
@@ -43,22 +41,10 @@ class UserModelFactory extends Factory
public function forStore(int $storeId): static
{
return $this->state(fn () => [
'type' => UserModel::TYPE_STORE,
'store_id' => $storeId,
]);
}
/**
* 已绑定供应商的供应商用户
*/
public function forSupplier(int $supplierId): static
{
return $this->state(fn () => [
'type' => UserModel::TYPE_SUPPLIER,
'supplier_id' => $supplierId,
]);
}
/**
* 停用账号
*/
@@ -1,47 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
if (! Schema::hasTable('user')) {
Schema::create('user', function (Blueprint $table) {
$table->increments('id')->comment('用户ID');
$table->string('username', 20)->nullable()->unique()->comment('用户名(微信注册用户可为空)');
$table->string('password', 100)->nullable()->comment('密码(微信注册用户可为空)');
$table->string('nickname', 20)->default('')->comment('昵称');
$table->string('email', 50)->default('')->comment('邮箱');
$table->timestamp('email_verified_at')->nullable();
// 小程序用户扩展字段(微信授权登录,自动识别门店/供应商身份)
$table->string('openid', 64)->nullable()->unique()->comment('微信OpenID(小程序用户唯一标识)');
$table->string('unionid', 64)->default('')->comment('微信UnionID');
$table->string('phone', 20)->default('')->comment('手机号(微信授权获取,用于匹配门店/供应商)');
$table->string('avatar', 255)->default('')->comment('头像');
$table->integer('type')->default(0)->comment('用户类型(0待绑定 1门店 2供应商)');
$table->integer('store_id')->default(0)->comment('关联门店IDtype=1时有效)');
$table->integer('supplier_id')->default(0)->comment('关联供应商IDtype=2时有效)');
$table->integer('status')->default(1)->comment('状态(1正常 0停用)');
$table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
$table->rememberToken();
$table->timestamps();
$table->index(['type', 'store_id'], 'user_type_store_index');
$table->comment('APP用户表(含小程序用户)');
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('user');
}
};
@@ -8,10 +8,34 @@ return new class extends Migration
{
/**
* Run the migrations.
* 基础档案:客户等级、门店、供应商、消息通知(小程序用户已并入 user 表)
* 基础档案
*/
public function up(): void
{
if (! Schema::hasTable('user')) {
Schema::create('user', function (Blueprint $table) {
$table->increments('id')->comment('用户ID');
$table->string('username', 20)->nullable()->unique()->comment('用户名');
$table->string('password', 100)->nullable()->comment('密码');
$table->string('nickname', 20)->default('')->comment('昵称');
$table->string('email', 50)->default('')->comment('邮箱');
$table->timestamp('email_verified_at')->nullable();
// 小程序用户扩展字段
$table->string('openid', 64)->nullable()->unique()->comment('微信OpenID');
$table->string('unionid', 64)->default('')->comment('微信UnionID');
$table->string('phone', 20)->default('')->comment('手机号');
$table->string('avatar', 255)->default('')->comment('头像');
$table->integer('store_id')->default(0)->comment('关联门店ID');
$table->integer('status')->default(1)->comment('状态(1正常 0停用)');
$table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
$table->rememberToken();
$table->timestamps();
$table->index('store_id', 'user_type_index');
$table->index('openid', 'user_openid_index');
$table->comment('APP用户表(含小程序用户)');
});
}
// 客户等级表(价格体系按等级定价)
if (! Schema::hasTable('customer_level')) {
Schema::create('customer_level', function (Blueprint $table) {
@@ -35,7 +59,7 @@ return new class extends Migration
$table->string('contact', 50)->default('')->comment('联系人');
$table->string('phone', 20)->default('')->comment('联系电话');
$table->string('address', 255)->default('')->comment('门店地址');
$table->integer('payment_cycle_days')->default(0)->comment('回款周期(天),门店可自行修改,影响对账单应结算日期');
$table->integer('payment_cycle_days')->default(0)->comment('回款周期(天)');
$table->integer('status')->default(1)->comment('状态(1正常 0停用)');
$table->string('remark', 255)->default('')->comment('备注');
$table->timestamps();
@@ -62,8 +86,7 @@ return new class extends Migration
});
}
// 消息通知表(订单状态变更、价格调整等通知)
// 小程序用户已并入 user 表,不再单独建 mini_user 表
// 消息通知表
if (! Schema::hasTable('notice')) {
Schema::create('notice', function (Blueprint $table) {
$table->increments('id')->comment('通知ID');
@@ -86,6 +109,7 @@ return new class extends Migration
*/
public function down(): void
{
Schema::dropIfExists('user');
Schema::dropIfExists('customer_level');
Schema::dropIfExists('store');
Schema::dropIfExists('supplier');