123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace Database\Seeders;
- // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
- use App\Models\Auth\AdminGroup;
- use App\Models\Auth\AdminPermission;
- use App\Models\Goods\Category;
- use App\Models\Goods\Goods;
- use App\Models\Goods\GoodsCategoryMap;
- use App\Models\Goods\GoodsSku;
- use App\Models\Goods\Spec;
- use App\Models\Goods\SpecAttr;
- use App\Models\Setting;
- use App\Models\User\User;
- use App\Models\User\UserCompany;
- use App\Modules\Admin\Services\UserService;
- use Faker\Provider\Image;
- use Faker\Provider\Text;
- use Illuminate\Database\Seeder;
- use Illuminate\Support\Facades\DB;
- class DatabaseSeeder extends Seeder
- {
- protected $user;
- /**
- * Seed the application's database.
- *
- * @return void
- */
- public function run()
- {
- $this->auth();
- $this->user = User::create([
- "password" => app(User::class)->hashPassword("111111"),
- "email" => "liantiao@lientiao.com",
- "status" => User::STATUS_OK,
- "group_id" => 1,
- "phone" => 15012341234,
- "extra" => [
- "permissions" => [1, 2],
- ],
- ]);
- User::create([
- "password" => hashid_encode("111111"),
- "email" => "normal@lientiao.com",
- "status" => User::STATUS_OK,
- "group_id" => 2,
- "phone" => 13012341234,
- ]);
- $this->company();
- Setting::create([
- "type" => Setting::TYPE_BANNER,
- "key" => "banner1",
- "value" => ["is_use" => 1, "imageUrl" => "https://fendi-liaona.oss-cn-hangzhou.aliyuncs.com/yimei/logo/20230427/0db2bfbd1d3eccd33e03894128efdab1.png", "sort" => 9],
- ]);
- Setting::create([
- "type" => Setting::TYPE_HOT_KEYWORD,
- "key" => "hot_keyword",
- "value" => ["热搜词1", "热搜词2"],
- ]);
- $this->goods();
- }
- public function goods()
- {
- Spec::truncate();
- SpecAttr::truncate();
- Category::truncate();
- Goods::truncate();
- GoodsCategoryMap::truncate();
- Spec::create(["name" => "颜色"]);
- Spec::create(["name" => "大小"]);
- SpecAttr::create(["spec_id" => 1, "name" => "红色"]);
- SpecAttr::create(["spec_id" => 1, "name" => "白色"]);
- SpecAttr::create(["spec_id" => 2, "name" => "大号"]);
- SpecAttr::create(["spec_id" => 2, "name" => "小号"]);
- Category::create(["name" => "一级分类", "thumb" => Image::imageUrl(300, 300), "level" => 1, "parent_id" => 0]);
- Category::create(["name" => "一级分类", "thumb" => Image::imageUrl(300, 300), "level" => 2, "parent_id" => 1]);
- Goods::create(["name" => "测试商品", "image_list" => [Image::imageUrl(), Image::imageUrl()], "spec" => [1, 2]]);
- GoodsCategoryMap::create(["goods_id" => 1, "category_id" => 2]);
- }
- public function company()
- {
- UserCompany::create(["name" => "测试企业", "tax_no" => "ooxx", "user_id" => $this->user->id]);
- }
- private function auth()
- {
- AdminGroup::truncate();
- AdminPermission::truncate();
- AdminGroup::create(["name" => "超级管理员"]);
- AdminGroup::create(["name" => "普通管理员"]);
- AdminGroup::create(["name" => "员工"]);
- AdminPermission::create(["name" => "权限1", "code" => "code1"]);
- AdminPermission::create(["name" => "权限2", "code" => "code2"]);
- }
- }
|