商品列表、分类管理、客户等级

This commit is contained in:
liu
2026-08-05 19:28:53 +08:00
parent dfa471bf22
commit 258df92e6c
36 changed files with 472 additions and 516 deletions
@@ -1,30 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\CustomerLevelModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 客户等级工厂(确定性序列数据,无需 Faker)
*
* @extends Factory<CustomerLevelModel>
*/
class CustomerLevelModelFactory extends Factory
{
protected $model = CustomerLevelModel::class;
private static int $sequence = 0;
public function definition(): array
{
$seq = ++self::$sequence;
return [
'name' => '客户等级' . $seq,
'sort' => $seq,
'status' => CustomerLevelModel::STATUS_NORMAL,
'remark' => '',
];
}
}
@@ -1,49 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\ProductModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 商品工厂(确定性序列数据,无需 Faker)
*
* @extends Factory<ProductModel>
*/
class ProductModelFactory extends Factory
{
protected $model = ProductModel::class;
private const NAMES = ['大白菜', '土豆', '西红柿', '黄瓜', '苹果', '香蕉'];
private const SPECS = ['500g/袋', '10斤/箱', '散装', '25斤/袋'];
private const GRADES = ['特级', '一级', '二级'];
private const UNITS = ['斤', '箱', '袋'];
private static int $sequence = 0;
public function definition(): array
{
$seq = ++self::$sequence;
return [
'category_id' => 0,
'supplier_id' => 0,
'name' => self::NAMES[$seq % count(self::NAMES)] . $seq,
'spec' => self::SPECS[$seq % count(self::SPECS)],
'grade' => self::GRADES[$seq % count(self::GRADES)],
'unit' => self::UNITS[$seq % count(self::UNITS)],
'image' => '',
'sort' => $seq,
'status' => ProductModel::STATUS_ON,
'remark' => '',
];
}
/**
* 下架商品
*/
public function off(): static
{
return $this->state(fn () => ['status' => ProductModel::STATUS_OFF]);
}
}
@@ -1,29 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\ProductPriceModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 商品等级价格工厂(product_id / level_id 需调用方指定;无需 Faker)
*
* @extends Factory<ProductPriceModel>
*/
class ProductPriceModelFactory extends Factory
{
protected $model = ProductPriceModel::class;
private static int $sequence = 0;
public function definition(): array
{
$seq = ++self::$sequence;
return [
'product_id' => 0,
'level_id' => 0,
'price' => number_format(random_int(100, 10000) / 100 + $seq * 0.01, 2, '.', ''),
];
}
}
@@ -1,43 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\PurchaseOrderModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 采购单工厂(无需 Faker
*
* @extends Factory<PurchaseOrderModel>
*/
class PurchaseOrderModelFactory extends Factory
{
protected $model = PurchaseOrderModel::class;
private static int $sequence = 0;
public function definition(): array
{
$seq = ++self::$sequence;
return [
'purchase_no' => 'PO' . str_pad((string) $seq, 12, '0', STR_PAD_LEFT),
'purchase_date' => now()->toDateString(),
'status' => PurchaseOrderModel::STATUS_PENDING,
'total_quantity' => 0,
'total_weight' => 0,
'estimate_amount' => 0,
'actual_amount' => 0,
'operator_id' => 0,
'remark' => '',
];
}
/**
* 指定采购日期
*/
public function onDate(string $date): static
{
return $this->state(fn () => ['purchase_date' => $date]);
}
}
-51
View File
@@ -1,51 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\StoreModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 门店工厂(确定性序列数据,无需 Faker)
*
* @extends Factory<StoreModel>
*/
class StoreModelFactory extends Factory
{
protected $model = StoreModel::class;
private static int $sequence = 0;
public function definition(): array
{
$seq = ++self::$sequence;
return [
'name' => '测试门店' . $seq,
'code' => 'S' . str_pad((string) $seq, 6, '0', STR_PAD_LEFT),
'level_id' => 0,
'contact' => '联系人' . $seq,
'phone' => '138' . str_pad((string) $seq, 8, '0', STR_PAD_LEFT),
'address' => '测试地址' . $seq . '号',
'payment_cycle_days' => $seq % 8,
'status' => StoreModel::STATUS_NORMAL,
'remark' => '',
];
}
/**
* 停用门店
*/
public function disabled(): static
{
return $this->state(fn () => ['status' => StoreModel::STATUS_DISABLED]);
}
/**
* 指定回款周期(天)
*/
public function paymentCycle(int $days): static
{
return $this->state(fn () => ['payment_cycle_days' => $days]);
}
}
@@ -1,42 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\StoreOrderItemModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 门店订单明细工厂(order_id / store_id / product_id 需调用方指定;
* amount 未显式指定时按 price × quantity 自动计算;无需 Faker
*
* @extends Factory<StoreOrderItemModel>
*/
class StoreOrderItemModelFactory extends Factory
{
protected $model = StoreOrderItemModel::class;
public function definition(): array
{
return [
'order_id' => 0,
'store_id' => 0,
'product_id' => 0,
'product_name' => '测试商品',
'product_spec' => '500g/袋',
'price' => number_format(random_int(100, 5000) / 100, 2, '.', ''),
'quantity' => number_format(random_int(100, 10000) / 100, 2, '.', ''),
'weight' => 0,
'amount' => 0,
'remark' => '',
];
}
public function configure(): static
{
return $this->afterMaking(function (StoreOrderItemModel $item): void {
if ((float) $item->amount === 0.0 && (float) $item->price > 0 && (float) $item->quantity > 0) {
$item->amount = bcmul((string) $item->price, (string) $item->quantity, 2);
}
});
}
}
@@ -1,50 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\StoreOrderModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 门店订单工厂(store_id 需调用方指定;无需 Faker)
*
* @extends Factory<StoreOrderModel>
*/
class StoreOrderModelFactory extends Factory
{
protected $model = StoreOrderModel::class;
private static int $sequence = 0;
public function definition(): array
{
$seq = ++self::$sequence;
return [
'order_no' => 'SO' . str_pad((string) $seq, 12, '0', STR_PAD_LEFT),
'store_id' => 0,
'order_date' => now()->toDateString(),
'total_quantity' => 0,
'total_weight' => 0,
'total_amount' => 0,
'status' => StoreOrderModel::STATUS_PENDING,
'remark' => '',
];
}
/**
* 指定订货日期
*/
public function onDate(string $date): static
{
return $this->state(fn () => ['order_date' => $date]);
}
/**
* 已汇总(已被采购单归集)
*/
public function summarized(): static
{
return $this->state(fn () => ['status' => StoreOrderModel::STATUS_SUMMARIZED]);
}
}
@@ -1,43 +0,0 @@
<?php
namespace Database\Factories;
use App\Models\SupplierModel;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* 供应商工厂(确定性序列数据,无需 Faker)
*
* @extends Factory<SupplierModel>
*/
class SupplierModelFactory extends Factory
{
protected $model = SupplierModel::class;
private const MAIN_PRODUCTS = ['蔬菜', '水果', '蔬菜/水果', '肉禽蛋'];
private static int $sequence = 0;
public function definition(): array
{
$seq = ++self::$sequence;
return [
'name' => '测试供应商' . $seq,
'contact' => '联系人' . $seq,
'phone' => '139' . str_pad((string) $seq, 8, '0', STR_PAD_LEFT),
'address' => '供应商地址' . $seq . '号',
'main_products' => self::MAIN_PRODUCTS[$seq % count(self::MAIN_PRODUCTS)],
'status' => SupplierModel::STATUS_NORMAL,
'remark' => '',
];
}
/**
* 停用供应商
*/
public function disabled(): static
{
return $this->state(fn () => ['status' => SupplierModel::STATUS_DISABLED]);
}
}
-69
View File
@@ -1,69 +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' => '',
'type' => UserModel::TYPE_PENDING,
'store_id' => 0,
'supplier_id' => 0,
'status' => UserModel::STATUS_NORMAL,
'last_login_at' => null,
];
}
/**
* 已绑定门店的门店用户
*/
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,
]);
}
/**
* 停用账号
*/
public function disabled(): static
{
return $this->state(fn () => ['status' => UserModel::STATUS_DISABLED]);
}
}
@@ -16,7 +16,7 @@ return new class extends Migration
if (! Schema::hasTable('customer_level')) {
Schema::create('customer_level', function (Blueprint $table) {
$table->increments('id')->comment('等级ID');
$table->integer('icon')->nullable()->comment('等级图标ID');
$table->integer('icon_id')->nullable()->comment('等级图标ID');
$table->string('name', 50)->comment('等级名称(如:一级客户、二级客户)');
$table->integer('sort')->default(0)->comment('排序');
$table->integer('status')->default(1)->comment('状态(1正常 0停用)');
@@ -17,7 +17,7 @@ return new class extends Migration
Schema::create('product_category', function (Blueprint $table) {
$table->increments('id')->comment('分类ID');
$table->integer('parent_id')->default(0)->comment('父级分类ID0为顶级)');
$table->integer('icon')->nullable()->comment('商品图标');
$table->integer('icon_id')->nullable()->comment('商品图标');
$table->string('name', 50)->comment('分类名称');
$table->integer('sort')->default(0)->comment('排序(采购单导出按此排序)');
$table->integer('status')->default(1)->comment('状态(1正常 0停用)');
@@ -36,8 +36,8 @@ return new class extends Migration
$table->string('name', 100)->comment('品名');
$table->string('spec', 100)->default('')->comment('规格/包规');
$table->string('unit', 20)->default('斤')->comment('计价单位(斤/件/箱等)');
$table->string('images', 255)->default('')->comment('商品图片');
$table->text('content')->default('')->comment('商品图文详情');
$table->string('image_ids', 255)->default('')->comment('商品图片');
$table->text('content')->comment('商品图文详情');
$table->integer('sort')->default(0)->comment('排序');
$table->integer('shelf_life')->default(0)->comment('保质期');
$table->integer('stock')->default(0)->comment('库存');
@@ -47,6 +47,7 @@ return new class extends Migration
$table->integer('sort')->default(0)->comment('排序(导出用)');
$table->integer('is_sent')->default(0)->comment('是否已发送供应商(1已发送 0未发送)');
$table->timestamp('sent_at')->nullable()->comment('发送时间');
$table->timestamp('supplier_confirmed_at')->nullable()->comment('供应商确认接单时间(NULL未确认)');
$table->string('remark', 255)->default('')->comment('备注');
$table->timestamps();
$table->index(['purchase_id'], 'purchase_order_item_purchase_index');
@@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* 待确认事项 #7(已批准):供应商小程序确认接单状态落库
*/
public function up(): void
{
if (! Schema::hasColumn('purchase_order_item', 'supplier_confirmed_at')) {
Schema::table('purchase_order_item', function (Blueprint $table) {
$table->timestamp('supplier_confirmed_at')->nullable()->after('sent_at')->comment('供应商确认接单时间(NULL未确认)');
});
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
if (Schema::hasColumn('purchase_order_item', 'supplier_confirmed_at')) {
Schema::table('purchase_order_item', function (Blueprint $table) {
$table->dropColumn('supplier_confirmed_at');
});
}
}
};
+1
View File
@@ -368,6 +368,7 @@ class PermissionSeeder extends Seeder
['type' => 'rule', 'name' => '编辑文件夹', 'key' => 'system.file.group.update'],
['type' => 'rule', 'name' => '删除文件夹', 'key' => 'system.file.group.delete'],
['type' => 'rule', 'name' => '查询文件列表', 'key' => 'system.file.list.query'],
['type' => 'rule', 'name' => '查看文件详情', 'key' => 'system.file.list.show'],
['type' => 'rule', 'name' => '上传文件', 'key' => 'system.file.list.upload'],
['type' => 'rule', 'name' => '下载文件', 'key' => 'system.file.list.download'],
['type' => 'rule', 'name' => '删除文件', 'key' => 'system.file.list.delete'],
+4 -2
View File
@@ -56,8 +56,10 @@ class SysDataSeeder extends Seeder
['id' => 5, 'name' => '系统附件', 'sort' => 4, 'describe' => '系统附件分组', 'created_at' => $date, 'updated_at' => $date],
['id' => 6, 'name' => '其他文件', 'sort' => 5, 'describe' => '其他文件分组', 'created_at' => $date, 'updated_at' => $date],
['id' => 7, 'name' => '临时文件', 'sort' => 6, 'describe' => '临时文件分组,用于存放临时上传的文件', 'created_at' => $date, 'updated_at' => $date],
['id' => 8, 'name' => '等级图片', 'sort' => 7, 'describe' => '存放等级图', 'created_at' => $date, 'updated_at' => $date],
['id' => 9, 'name' => '分类图片', 'sort' => 8, 'describe' => '存放商品分类图', 'created_at' => $date, 'updated_at' => $date],
['id' => 8, 'name' => '等级图片', 'sort' => 7, 'describe' => '存放等级图', 'created_at' => $date, 'updated_at' => $date],
['id' => 9, 'name' => '分类图片', 'sort' => 8, 'describe' => '存放商品分类图', 'created_at' => $date, 'updated_at' => $date],
['id' => 10, 'name' => '商品封面图片', 'sort' => 9, 'describe' => '存放商品封面图片', 'created_at' => $date, 'updated_at' => $date],
['id' => 11, 'name' => '商品详情图片', 'sort' => 10, 'describe' => '存放商品详情图片', 'created_at' => $date, 'updated_at' => $date],
]);
}
}