2021_03_09_172210_change_price_model_table.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class ChangePriceModelTable extends Migration
  6. {
  7. protected $tables = ["owner_storage_price_models","owner_price_operations","owner_price_logistics","owner_price_expresses","owner_price_direct_logistics"];
  8. /**
  9. * Run the migrations.
  10. *
  11. * @return void
  12. */
  13. public function up()
  14. {
  15. foreach(\App\Authority::query()->where("name","like","客户管理%")->get() as $authority){
  16. $name = mb_substr($authority->name,2);
  17. $authority->update(["name"=>"项目".$name,"alias_name"=>"项目".$name]);
  18. };
  19. foreach ($this->tables as $table){
  20. Schema::table($table,function (Blueprint $table){
  21. $table->char("operation",1)->index()->nullable()->comment("操作类型");
  22. $table->bigInteger("target_id")->index()->nullable()->comment("目标ID");
  23. });
  24. }
  25. \App\Authority::query()->firstOrCreate(["name"=>"项目管理-项目-计费模型-审核"],["name"=>"项目管理-项目-计费模型-审核","alias_name"=>"项目管理-项目-计费模型-审核"]);
  26. }
  27. /**
  28. * Reverse the migrations.
  29. *
  30. * @return void
  31. */
  32. public function down()
  33. {
  34. foreach(\App\Authority::query()->where("name","like","项目管理%")->get() as $authority){
  35. $name = mb_substr($authority->name,2);
  36. $authority->update(["name"=>"客户".$name,"alias_name"=>"客户".$name]);
  37. };
  38. foreach ($this->tables as $table){
  39. Schema::table($table,function (Blueprint $table){
  40. $table->dropColumn("operation",1);
  41. $table->dropColumn("target_id");
  42. });
  43. }
  44. \App\Authority::query()->where("name","项目管理-项目-计费模型-审核")->delete();
  45. }
  46. /*TODO 可回滚数据功能:1.增加两个字段 operation(哪种类型操作) target_id(映射目标)
  47. 2.新增操作:未审核时增加operation为C
  48. 修改前提,对应的映射目标不可被查看修改
  49. 3.修改操作:当前修改对象是否为被标记过对象,是->直接修改当前对象 否->生成标记对象
  50. 3.删除操作:当前删除对象是否为被标记过对象,是->目标是否存在(是->删除当前对象,将目标对象标记为删除 否->将当前对象标记为删除) 否->将当前对象标记为删除
  51. 审核操作:被标记为C的删除标记信息 被标记为U的删除目标对象与当前对象的标记信息 被标记为D的直接删除
  52. 恢复操作:被标记为C的直接删除 被标记为U的删除当前对象 被标记为D的删除当前对象的标记信息
  53. */
  54. }