小程序用户改用门店登录

This commit is contained in:
liu
2026-08-20 13:46:04 +08:00
parent 6d9f02d831
commit c1d490134e
251 changed files with 689 additions and 2727 deletions
+12
View File
@@ -23,6 +23,10 @@ class StoreModelFactory extends Factory
return [
'name' => '测试门店' . $seq,
'code' => 'S' . str_pad((string) $seq, 6, '0', STR_PAD_LEFT),
'username' => 'store' . $seq,
'password' => password_hash('123456', PASSWORD_DEFAULT),
'avatar' => '',
'last_login_at' => null,
'level_id' => 0,
'contact' => '联系人' . $seq,
'phone' => '138' . str_pad((string) $seq, 8, '0', STR_PAD_LEFT),
@@ -41,6 +45,14 @@ class StoreModelFactory extends Factory
return $this->state(fn () => ['status' => StoreModel::STATUS_DISABLED]);
}
/**
* 指定登录密码(明文,入库自动哈希)
*/
public function withPassword(string $password): static
{
return $this->state(fn () => ['password' => password_hash($password, PASSWORD_DEFAULT)]);
}
/**
* 指定回款周期(天)
*/
-55
View File
@@ -1,55 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\UserModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 小程序用户工厂(微信登录自动生成,供测试使用;无需 Faker)
*
* @extends Factory<UserModel>
*/
class UserModelFactory extends Factory
{
protected $model = UserModel::class;
private static int $sequence = 0;
public function definition(): array
{
$seq = ++self::$sequence;
return [
'username' => null,
'password' => null,
'nickname' => '微信用户' . $seq,
'email' => '',
'openid' => 'openid_' . str_pad((string) $seq, 16, '0', STR_PAD_LEFT),
'unionid' => '',
'phone' => '',
'avatar' => '',
'store_id' => 0,
'status' => UserModel::STATUS_NORMAL,
'last_login_at' => null,
];
}
/**
* 已绑定门店的门店用户
*/
public function forStore(int $storeId): static
{
return $this->state(fn () => [
'store_id' => $storeId,
]);
}
/**
* 停用账号
*/
public function disabled(): static
{
return $this->state(fn () => ['status' => UserModel::STATUS_DISABLED]);
}
}
@@ -12,30 +12,6 @@ return new class extends Migration
*/
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) {
@@ -55,6 +31,11 @@ return new class extends Migration
$table->increments('id')->comment('门店ID');
$table->string('name', 100)->comment('门店名称');
$table->string('code', 50)->unique()->comment('门店编码');
// 登录账号字段(小程序端 账号 + 密码 登录)
$table->string('username', 20)->unique()->comment('登录账号');
$table->string('password', 100)->comment('登录密码');
$table->string('avatar', 255)->default('')->comment('头像');
$table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
$table->integer('level_id')->default(0)->comment('客户等级ID(决定商品价格)');
$table->string('contact', 50)->default('')->comment('联系人');
$table->string('phone', 20)->default('')->comment('联系电话');
@@ -63,10 +44,11 @@ return new class extends Migration
$table->decimal('total_purchase_amount', 12, 2)->default(0)->comment('总采购金额(只统计商品金额,账单支付后累加)');
$table->integer('status')->default(1)->comment('状态(1正常 0停用)');
$table->string('remark', 255)->nullable()->default('')->comment('备注');
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
$table->index(['level_id', 'status'], 'store_level_status_index');
$table->comment('门店表');
$table->comment('门店表(门店即用户,账号密码登录)');
});
}
@@ -91,7 +73,7 @@ return new class extends Migration
if (! Schema::hasTable('notice')) {
Schema::create('notice', function (Blueprint $table) {
$table->increments('id')->comment('通知ID');
$table->integer('user_id')->default(0)->comment('接收用户IDuser表,0为全员广播)');
$table->integer('store_id')->default(0)->comment('接收门店IDstore表,0为全员广播)');
$table->string('type', 20)->default('system')->comment('通知类型(order订单 price价格 system系统)');
$table->string('title', 100)->comment('标题');
$table->string('content', 500)->default('')->comment('内容');
@@ -99,7 +81,7 @@ return new class extends Migration
$table->integer('is_read')->default(0)->comment('是否已读(1已读 0未读)');
$table->timestamp('read_at')->nullable()->comment('阅读时间');
$table->timestamps();
$table->index(['user_id', 'is_read'], 'notice_user_read_index');
$table->index(['store_id', 'is_read'], 'notice_store_read_index');
$table->comment('消息通知表');
});
}
@@ -110,7 +92,6 @@ return new class extends Migration
*/
public function down(): void
{
Schema::dropIfExists('user');
Schema::dropIfExists('customer_level');
Schema::dropIfExists('store');
Schema::dropIfExists('supplier');
@@ -8,19 +8,19 @@ return new class extends Migration
{
/**
* Run the migrations.
* 小程序购物车(门店订货车):按用户归属,同商品唯一行、加购合并累加
* 小程序购物车(门店订货车):按门店归属,同商品唯一行、加购合并累加
*/
public function up(): void
{
if (! Schema::hasTable('cart')) {
Schema::create('cart', function (Blueprint $table) {
$table->increments('id')->comment('购物车项ID');
$table->integer('user_id')->comment('用户ID(购物车归属者)');
$table->integer('store_id')->comment('门店ID(购物车归属者)');
$table->integer('product_id')->comment('商品ID');
$table->decimal('quantity', 10, 2)->default(0)->comment('订货量');
$table->timestamps();
$table->unique(['user_id', 'product_id'], 'cart_user_product_unique');
$table->index(['user_id', 'created_at'], 'cart_user_created_index');
$table->unique(['store_id', 'product_id'], 'cart_store_product_unique');
$table->index(['store_id', 'created_at'], 'cart_store_created_index');
$table->comment('小程序购物车表(门店订货车)');
});
}
@@ -16,8 +16,7 @@ return new class extends Migration
Schema::create('payment', function (Blueprint $table) {
$table->increments('id')->comment('支付记录ID');
$table->string('payment_no', 32)->unique()->comment('支付单号');
$table->integer('store_id')->comment('门店ID');
$table->integer('user_id')->default(0)->comment('提交人(小程序用户ID');
$table->integer('store_id')->comment('门店ID(提交门店即支付人)');
$table->decimal('amount', 10, 2)->default(0)->comment('支付金额(= 关联账单总金额合计,提交时快照)');
$table->integer('pay_method')->comment('支付方式(1微信 2支付宝 3对公汇款)');
$table->string('voucher_ids', 255)->default('')->comment('汇款凭证图片ID(逗号分隔)');
-11
View File
@@ -135,17 +135,6 @@ class PermissionSeeder extends Seeder
['type' => 'rule', 'key' => 'customer.level.delete', 'name' => '删除'],
],
],
[
'type' => 'route',
'key' => 'customer.miniUser',
'name' => '小程序用户',
'path' => '/customer/mini-user',
'children' => [
['type' => 'rule', 'key' => 'customer.miniUser.query', 'name' => '查询'],
['type' => 'rule', 'key' => 'customer.miniUser.update', 'name' => '启用停用'],
['type' => 'rule', 'key' => 'customer.miniUser.bind', 'name' => '绑定主体'],
],
],
[
'type' => 'route',
'key' => 'customer.notice',
+1 -4
View File
@@ -16,8 +16,7 @@ class SysDataSeeder extends Seeder
// 系统设置初始数据
DB::table('sys_site_config_group')->insert([
['id' => 1, 'title' => '网站设置', 'key' => 'web', 'remark' => '网站基础设置', 'created_at' => $date, 'updated_at' => $date],
['id' => 2, 'title' => '小程序设置', 'key' => 'wechatMini', 'remark' => '小程序设置', 'created_at' => $date, 'updated_at' => $date],
['id' => 3, 'title' => '业务配置', 'key' => 'services', 'remark' => '小程序设置', 'created_at' => $date, 'updated_at' => $date],
['id' => 3, 'title' => '业务配置', 'key' => 'services', 'remark' => '业务附加配置', 'created_at' => $date, 'updated_at' => $date],
['id' => 4, 'title' => '支付配置', 'key' => 'pay', 'remark' => '网站的支付配置', 'created_at' => $date, 'updated_at' => $date],
]);
DB::table('sys_site_config_items')->insert([
@@ -25,8 +24,6 @@ class SysDataSeeder extends Seeder
['id' => 2, 'group_id' => 1, 'key' => 'logo', 'title' => '网站LOGO', 'describe' => '网站的LOGO,用于标识网站', 'values' => 'https://file.xinadmin.cn/file/favicons.ico', 'type' => 'Input','options' => "", 'sort' => 1, 'created_at' => $date, 'updated_at' => $date,],
['id' => 3, 'group_id' => 1, 'key' => 'subtitle', 'title' => '网站副标题', 'describe' => '网站副标题,展示在登录页面标题的下面', 'values' => 'Xin Admin 快速开发框架', 'type' => 'Input','options' => "", 'sort' => 2, 'created_at' => $date, 'updated_at' => $date,],
['id' => 4, 'group_id' => 1, 'key' => 'describe', 'title' => '网站描述', 'describe' => '网站的基本描述', 'values' => '没有描述', 'type' => 'TextArea','options' => "", 'sort' => 2, 'created_at' => $date, 'updated_at' => $date],
['id' => 5, 'group_id' => 2, 'key' => 'appid', 'title' => 'APPID', 'describe' => '小程序的APPID', 'values' => '没有描述', 'type' => 'Input','options' => "", 'sort' => 0, 'created_at' => $date, 'updated_at' => $date],
['id' => 6, 'group_id' => 2, 'key' => 'secret', 'title' => 'SecretKey', 'describe' => '小程序的SecretKey', 'values' => '没有描述', 'type' => 'Input','options' => "", 'sort' => 1, 'created_at' => $date, 'updated_at' => $date],
['id' => 7, 'group_id' => 3, 'key' => 'box_amount', 'title' => '周转筐金额', 'describe' => '周转筐的金额,用于附加业务金额的计算', 'values' => '', 'type' => 'InputNumber','props' => "min=0\nmax=10000\nstep=0.01", 'sort' => 0, 'created_at' => $date, 'updated_at' => $date],
['id' => 8, 'group_id' => 3, 'key' => 'tray_amount', 'title' => '周转托盘金额', 'describe' => '周转托盘的金额,用于附加金额的计算', 'values' => '', 'type' => 'InputNumber','props' => "min=0\nmax=10000\nstep=0.01", 'sort' => 1, 'created_at' => $date, 'updated_at' => $date],
['id' => 9, 'group_id' => 4, 'key' => 'wechat_qrcode', 'title' => '微信收款码', 'describe' => '微信收款码图片地址(在文件管理中上传收款码后复制图片链接,或直接填写文件ID),小程序付款页展示', 'values' => '', 'type' => 'Input','options' => "", 'sort' => 0, 'created_at' => $date, 'updated_at' => $date],