DatabaseSeeder.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Database\Seeders;
  3. // use Illuminate\Database\Console\Seeds\WithoutModelEvents;
  4. use App\Models\Auth\AdminGroup;
  5. use App\Models\Auth\AdminPermission;
  6. use App\Models\Goods\Category;
  7. use App\Models\Goods\Goods;
  8. use App\Models\Goods\GoodsCategoryMap;
  9. use App\Models\Goods\GoodsSku;
  10. use App\Models\Goods\Spec;
  11. use App\Models\Goods\SpecAttr;
  12. use App\Models\Setting;
  13. use App\Models\User\User;
  14. use App\Models\User\UserCompany;
  15. use App\Modules\Admin\Services\UserService;
  16. use Faker\Provider\Image;
  17. use Faker\Provider\Text;
  18. use Illuminate\Database\Seeder;
  19. use Illuminate\Support\Facades\DB;
  20. class DatabaseSeeder extends Seeder
  21. {
  22. protected $user;
  23. /**
  24. * Seed the application's database.
  25. *
  26. * @return void
  27. */
  28. public function run()
  29. {
  30. $this->auth();
  31. $this->user = User::create([
  32. "password" => app(User::class)->hashPassword("111111"),
  33. "email" => "liantiao@lientiao.com",
  34. "status" => User::STATUS_OK,
  35. "group_id" => 1,
  36. "phone" => 15012341234,
  37. "extra" => [
  38. "permissions" => [1, 2],
  39. ],
  40. ]);
  41. User::create([
  42. "password" => hashid_encode("111111"),
  43. "email" => "normal@lientiao.com",
  44. "status" => User::STATUS_OK,
  45. "group_id" => 2,
  46. "phone" => 13012341234,
  47. ]);
  48. $this->company();
  49. Setting::create([
  50. "type" => Setting::TYPE_BANNER,
  51. "key" => "banner1",
  52. "value" => ["is_use" => 1, "imageUrl" => "https://fendi-liaona.oss-cn-hangzhou.aliyuncs.com/yimei/logo/20230427/0db2bfbd1d3eccd33e03894128efdab1.png", "sort" => 9],
  53. ]);
  54. Setting::create([
  55. "type" => Setting::TYPE_HOT_KEYWORD,
  56. "key" => "hot_keyword",
  57. "value" => ["热搜词1", "热搜词2"],
  58. ]);
  59. $this->goods();
  60. }
  61. public function goods()
  62. {
  63. Spec::truncate();
  64. SpecAttr::truncate();
  65. Category::truncate();
  66. Goods::truncate();
  67. GoodsCategoryMap::truncate();
  68. Spec::create(["name" => "颜色"]);
  69. Spec::create(["name" => "大小"]);
  70. SpecAttr::create(["spec_id" => 1, "name" => "红色"]);
  71. SpecAttr::create(["spec_id" => 1, "name" => "白色"]);
  72. SpecAttr::create(["spec_id" => 2, "name" => "大号"]);
  73. SpecAttr::create(["spec_id" => 2, "name" => "小号"]);
  74. Category::create(["name" => "一级分类", "thumb" => Image::imageUrl(300, 300), "level" => 1, "parent_id" => 0]);
  75. Category::create(["name" => "一级分类", "thumb" => Image::imageUrl(300, 300), "level" => 2, "parent_id" => 1]);
  76. Goods::create(["name" => "测试商品", "image_list" => [Image::imageUrl(), Image::imageUrl()], "spec" => [1, 2]]);
  77. GoodsCategoryMap::create(["goods_id" => 1, "category_id" => 2]);
  78. }
  79. public function company()
  80. {
  81. UserCompany::create(["name" => "测试企业", "tax_no" => "ooxx", "user_id" => $this->user->id]);
  82. }
  83. private function auth()
  84. {
  85. AdminGroup::truncate();
  86. AdminPermission::truncate();
  87. AdminGroup::create(["name" => "超级管理员"]);
  88. AdminGroup::create(["name" => "普通管理员"]);
  89. AdminGroup::create(["name" => "员工"]);
  90. AdminPermission::create(["name" => "权限1", "code" => "code1"]);
  91. AdminPermission::create(["name" => "权限2", "code" => "code2"]);
  92. }
  93. }