*/ 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]); } }