2020_10_20_134819_create_customers_table.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. use App\Authority;
  3. use Illuminate\Database\Migrations\Migration;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\Schema;
  6. class CreateCustomersTable extends Migration
  7. {
  8. protected $authNames=[
  9. '客户管理',
  10. '客户管理-项目',
  11. '客户管理-项目-报表',
  12. '客户管理-项目-查询',
  13. '客户管理-项目-录入',
  14. '客户管理-项目-面积',
  15. '客户管理-财务-即时账单',
  16. '客户管理-财务-账单确认',
  17. '计费模型-仓储',
  18. '计费模型-仓储-录入',
  19. '客户',
  20. '客户-查询',
  21. '客户-录入',
  22. '项目组',
  23. '项目组-查询',
  24. '项目组-录入',
  25. '作业类型',
  26. '作业类型-查询',
  27. '作业类型-录入',
  28. '特征',
  29. '特征-录入',
  30. '特征-查询',
  31. '计费模型-作业',
  32. '计费模型-作业-查询',
  33. '计费模型-作业-录入',
  34. ];
  35. /**
  36. * Run the migrations.
  37. *
  38. * @return void
  39. */
  40. public function up()
  41. {
  42. Schema::create('customers', function (Blueprint $table) {
  43. $table->id();
  44. $table->string('code')->unique()->comment('客户代码');
  45. $table->string('name')->comment('客户名称');
  46. $table->string('company_name')->comment('公司名称');
  47. $table->timestamps();
  48. });
  49. foreach ($this->authNames as $name){
  50. if(!Authority::query()->where('name',$name)->first())(new Authority(['name'=>$name,'alias_name'=>$name]))->save();
  51. }
  52. }
  53. /**
  54. * Reverse the migrations.
  55. *
  56. * @return void
  57. */
  58. public function down()
  59. {
  60. Schema::dropIfExists('customers');
  61. foreach ($this->authNames as $name){
  62. Authority::query()->where('name',$name)->delete();
  63. }
  64. }
  65. }