create_product_tables.php.stub 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /*
  3. * This file is part of ibrand/product.
  4. *
  5. * (c) iBrand <https://www.ibrand.cc>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. use Illuminate\Support\Facades\Schema;
  11. use Illuminate\Database\Schema\Blueprint;
  12. use Illuminate\Database\Migrations\Migration;
  13. class CreateProductTables extends Migration
  14. {
  15. /**
  16. * Run the migrations.
  17. *
  18. * @return void
  19. */
  20. public function up()
  21. {
  22. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  23. //品牌表
  24. if (!Schema::hasTable($prefix . 'goods_brand')) {
  25. Schema::create($prefix . 'goods_brand', function (Blueprint $table) {
  26. $table->increments('id');
  27. $table->string('name'); //品牌名称
  28. $table->string('description')->nullable(); //描述
  29. $table->integer('is_show')->default(1); //是否可见,1可见,0不可见
  30. $table->integer('sort')->default(99); //排序(越小越靠前)
  31. $table->string('url')->nullable(); //品牌网址
  32. $table->string('logo')->nullable(); //品牌logo
  33. $table->timestamps();
  34. $table->softDeletes();
  35. });
  36. }
  37. if (!Schema::hasTable($prefix . 'goods_spec')) {
  38. Schema::create($prefix . 'goods_spec', function (Blueprint $table) {
  39. $table->increments('id');
  40. $table->string('name');
  41. $table->string('display_name');
  42. $table->tinyInteger('type')->default(1);
  43. $table->timestamps();
  44. $table->softDeletes();
  45. });
  46. }
  47. if (!Schema::hasTable($prefix . 'goods_spec_value')) {
  48. Schema::create($prefix . 'goods_spec_value', function (Blueprint $table) {
  49. $table->increments('id');
  50. $table->unsignedInteger('spec_id');
  51. $table->string('name');
  52. /*$table->string('rgb')->nullable();
  53. $table->string('color')->nullable();
  54. $table->tinyInteger('status')->default(1);*/
  55. $table->timestamps();
  56. $table->softDeletes();
  57. });
  58. }
  59. if (!Schema::hasTable($prefix . 'goods_attribute')) {
  60. Schema::create($prefix . 'goods_attribute', function (Blueprint $table) {
  61. $table->increments('id');
  62. $table->tinyInteger('type')->default(1); //1 下拉列表 2 输入框
  63. $table->string('name')->nullable();
  64. $table->tinyInteger('is_search')->default(0);
  65. $table->tinyInteger('is_chart')->default(0);
  66. $table->timestamps();
  67. $table->softDeletes();
  68. });
  69. }
  70. if (!Schema::hasTable($prefix . 'goods_attribute_value')) {
  71. Schema::create($prefix . 'goods_attribute_value', function (Blueprint $table) {
  72. $table->increments('id');
  73. $table->unsignedInteger('attribute_id');
  74. $table->string('name');
  75. $table->timestamps();
  76. $table->softDeletes();
  77. });
  78. }
  79. if (!Schema::hasTable($prefix . 'goods_model')) {
  80. Schema::create($prefix . 'goods_model', function (Blueprint $table) {
  81. $table->increments('id');
  82. $table->string('name');
  83. $table->string('spec_ids');
  84. $table->timestamps();
  85. $table->softDeletes();
  86. });
  87. }
  88. if (!Schema::hasTable($prefix . 'goods_model_attribute_relation')) {
  89. Schema::create($prefix . 'goods_model_attribute_relation', function (Blueprint $table) {
  90. $table->increments('id');
  91. $table->unsignedInteger('model_id');
  92. $table->unsignedInteger('attribute_id');
  93. $table->timestamps();
  94. $table->softDeletes();
  95. });
  96. }
  97. if (!Schema::hasTable($prefix . 'goods')) {
  98. Schema::create($prefix . 'goods', function (Blueprint $table) {
  99. $table->increments('id');
  100. $table->string('name'); //商品名称
  101. $table->string('goods_no'); //商品货号
  102. $table->unsignedInteger('brand_id'); //品牌ID
  103. $table->unsignedInteger('model_id'); //模型ID
  104. //价格类数据
  105. $table->decimal('min_price', 15, 2); //销售价格
  106. $table->decimal('max_price', 15, 2); //销售价格
  107. $table->decimal('sell_price', 15, 2); //销售价格
  108. $table->decimal('market_price', 15, 2)->nullable(); // 市场价
  109. $table->decimal('min_market_price', 15, 2)->nullable(); // 市场价
  110. $table->decimal('cost_price', 15, 2)->nullable(); //成本价
  111. $table->decimal('weight', 15, 2)->nullable(); //重量
  112. $table->integer('store_nums')->default(0); //库存
  113. $table->string('img')->nullable(); //封面图
  114. $table->mediumText('content')->nullable(); //商品描述(mobile)
  115. $table->mediumText('contentpc')->nullable(); //商品描述(pc)
  116. $table->tinyInteger('sync')->default(0); //内容是否同步 0:不同步 1:同步至PC端 2:PC同步到移动端
  117. //统计类数据
  118. $table->integer('comment_count')->default(0); //评论次数
  119. $table->integer('visit_count')->default(0); //浏览次数
  120. $table->integer('favorite_count')->default(0); //收藏次数
  121. $table->integer('sale_count')->default(0); //销量
  122. $table->integer('grade')->default(0); //评分总数
  123. $table->string('tags')->nullable(); //标签
  124. $table->string('keywords')->nullable(); //SEO关键词
  125. $table->string('description')->nullable(); //SEO描述
  126. $table->tinyInteger('is_del')->default(0); //上架或者下架
  127. $table->tinyInteger('is_largess')->default(0); //是否赠品:0否 1是
  128. $table->tinyInteger('is_commend')->default(0); //是否推荐
  129. $table->tinyInteger('is_new')->default(0); // 是否新品
  130. $table->text('extra')->nullable();
  131. $table->timestamps();
  132. $table->softDeletes();
  133. });
  134. }
  135. if (!Schema::hasTable($prefix . 'goods_product')) {
  136. Schema::create($prefix . 'goods_product', function (Blueprint $table) {
  137. $table->increments('id');
  138. $table->unsignedInteger('goods_id'); //商品ID
  139. $table->integer('store_nums')->default(0); //库存
  140. $table->string('sku')->nullable(); //sku
  141. $table->decimal('sell_price', 15, 2); //销售价格
  142. $table->decimal('market_price', 15, 2)->nullable(); // 市场价
  143. $table->decimal('cost_price', 15, 2)->nullable(); //成本价
  144. $table->decimal('weight', 15, 2)->nullable(); //重量
  145. $table->tinyInteger('is_show')->default(1); // 是否上架销售
  146. $table->text('spec_ids')->nullable();
  147. $table->timestamps();
  148. $table->softDeletes();
  149. });
  150. }
  151. if (!Schema::hasTable($prefix . 'goods_category')) {
  152. Schema::create($prefix . 'goods_category', function (Blueprint $table) {
  153. $table->increments('id');
  154. $table->unsignedInteger('goods_id');
  155. $table->unsignedInteger('category_id');
  156. $table->timestamps();
  157. });
  158. }
  159. if (!Schema::hasTable($prefix . 'goods_attribute_relation')) {
  160. Schema::create($prefix . 'goods_attribute_relation', function (Blueprint $table) {
  161. $table->increments('id');
  162. $table->unsignedInteger('goods_id');
  163. $table->unsignedInteger('model_id');
  164. $table->unsignedInteger('attribute_id');
  165. $table->unsignedInteger('attribute_value_id');
  166. $table->string('attribute_value')->nullable();
  167. $table->timestamps();
  168. $table->softDeletes();
  169. });
  170. }
  171. if (!Schema::hasTable($prefix . 'goods_spec_relation')) {
  172. Schema::create($prefix . 'goods_spec_relation', function (Blueprint $table) {
  173. $table->increments('id');
  174. $table->unsignedInteger('goods_id');
  175. $table->unsignedInteger('spec_id');
  176. $table->unsignedInteger('spec_value_id');
  177. $table->string('alias')->nullable();
  178. $table->string('img')->nullable();
  179. $table->timestamps();
  180. $table->softDeletes();
  181. });
  182. }
  183. if (!Schema::hasTable($prefix . 'goods_photo')) {
  184. Schema::create($prefix . 'goods_photo', function (Blueprint $table) {
  185. $table->increments('id');
  186. $table->unsignedInteger('goods_id');
  187. $table->string('url');
  188. $table->integer('sort')->default(0);
  189. $table->string('code')->nullable();
  190. $table->tinyInteger('is_default')->default(1); // 是否主图
  191. $table->timestamps();
  192. $table->softDeletes();
  193. });
  194. }
  195. }
  196. /**
  197. * Reverse the migrations.
  198. *
  199. * @return void
  200. */
  201. public function down()
  202. {
  203. $prefix = config('ibrand.app.database.prefix', 'ibrand_');
  204. Schema::dropIfExists($prefix . 'goods_photo');
  205. Schema::dropIfExists($prefix . 'goods_spec_relation');
  206. Schema::dropIfExists($prefix . 'goods_attribute_relation');
  207. Schema::dropIfExists($prefix . 'goods_category');
  208. Schema::dropIfExists($prefix . 'goods_product');
  209. Schema::dropIfExists($prefix . 'goods');
  210. Schema::dropIfExists($prefix . 'goods_model_attribute_relation');
  211. Schema::dropIfExists($prefix . 'goods_model');
  212. Schema::dropIfExists($prefix . 'goods_attribute_value');
  213. Schema::dropIfExists($prefix . 'goods_attribute');
  214. Schema::dropIfExists($prefix . 'goods_specs_value');
  215. Schema::dropIfExists($prefix . 'goods_spec');
  216. Schema::dropIfExists($prefix . 'goods_brand');
  217. }
  218. }