链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
4.5 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Schema;
  6. class MigrateStoreAccount extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'migrateData:storeAccount';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command 迁移商户流水数据';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. $oldTableName = 'ims_cjdc_store_account';
  37. $newTableName = 'lanzu_financial_record';
  38. // 判断表是否存在
  39. if(!Schema::hasTable($oldTableName)){
  40. var_dump('旧表不存在');
  41. return 0;
  42. }
  43. if(!Schema::hasTable($newTableName)){
  44. var_dump('新表不存在');
  45. return 0;
  46. }
  47. $desc='用户店铺首单奖励';
  48. $comment='用户当面付商户奖励';
  49. $desc='新用户下单奖励';
  50. $comment='用户当面付商户奖励';
  51. $desc = '线上外卖订单收入';
  52. $comment = '用户订单完成';
  53. $desc = '线下当面付订单收入';
  54. $comment = '用户订单完成';
  55. $desc = '线上订单退款';
  56. $comment = '线上订单退款到微信';
  57. $desc = '商户提现';
  58. $comment = '商户提现打款';
  59. $oldData = DB::table($oldTableName)->orderBy('id','asc')->get();
  60. $bar = $this->output->createProgressBar(count($oldData));
  61. $bar->start();
  62. $startTime = time();
  63. $error = [];
  64. foreach ($oldData as $key => $value){
  65. $storeId = $value->store_id;
  66. $userId = $value->user_id;
  67. if(empty($userId)){
  68. $error[] = ['id'=>$userId];
  69. break;
  70. }
  71. // 判断是否存在 总账
  72. $exist = DB::table($newTableName)
  73. ->where('user_id',$userId)
  74. ->where('user_type',5)
  75. ->where('source_id',$value->order_id)
  76. ->where('source_type',0)
  77. ->where('money_type')
  78. ->exists();
  79. if(!$exist){
  80. $newData =[
  81. 'id'=>$userId,
  82. 'nick_name'=>$value->name,
  83. 'avatar'=>$value->img,
  84. 'openid'=>$value->openid,
  85. 'total_score'=>$value->total_score,
  86. 'wallet'=>$value->wallet,
  87. 'real_name'=>$value->user_name,
  88. 'tel'=>$value->user_tel,
  89. 'unionid'=>$value->unionid,
  90. 'created_at' => strtotime($value->join_time),
  91. 'updated_at' => $value->updated_at,
  92. ];
  93. $res = DB::table($newTableName)->insert($newData);
  94. if(!$res){
  95. $error[] = ['id'=>$userId];
  96. break;
  97. }
  98. }
  99. // 判断是否存在 详细账
  100. $mod = bcmod((string)$userId, '5', 0);
  101. $newSubTableName = $newTableName.'_'.$mod;
  102. $existSub = DB::table($newSubTableName)->where('id',$userId)->exists();
  103. if(!$existSub){
  104. $newData =[
  105. 'id'=>$userId,
  106. 'nick_name'=>$value->name,
  107. 'avatar'=>$value->img,
  108. 'openid'=>$value->openid,
  109. 'total_score'=>$value->total_score,
  110. 'wallet'=>$value->wallet,
  111. 'real_name'=>$value->user_name,
  112. 'tel'=>$value->user_tel,
  113. 'unionid'=>$value->unionid,
  114. 'created_at' => strtotime($value->join_time),
  115. 'updated_at' => $value->updated_at,
  116. ];
  117. $res = DB::table($newSubTableName)->insert($newData);
  118. if(!$res){
  119. $error[] = ['id'=>$userId];
  120. break;
  121. }
  122. }
  123. $bar->advance();
  124. }
  125. $bar->finish();
  126. var_dump([time()-$startTime]);
  127. var_dump($error);
  128. return 0;
  129. }
  130. }