链街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.

163 lines
4.6 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. $m = ['120'=>['sort'=>'12'],'12'=>['sort'=>'3'],'112'=>['sort'=>'2'],'110'=>['sort'=>'120']];
  37. var_dump($m);
  38. return 0;
  39. $oldTableName = 'ims_cjdc_store_account';
  40. $newTableName = 'lanzu_financial_record';
  41. // 判断表是否存在
  42. if(!Schema::hasTable($oldTableName)){
  43. var_dump('旧表不存在');
  44. return 0;
  45. }
  46. if(!Schema::hasTable($newTableName)){
  47. var_dump('新表不存在');
  48. return 0;
  49. }
  50. $desc='用户店铺首单奖励';
  51. $comment='用户当面付商户奖励';
  52. $desc='新用户下单奖励';
  53. $comment='用户当面付商户奖励';
  54. $desc = '线上外卖订单收入';
  55. $comment = '用户订单完成';
  56. $desc = '线下当面付订单收入';
  57. $comment = '用户订单完成';
  58. $desc = '线上订单退款';
  59. $comment = '线上订单退款到微信';
  60. $desc = '商户提现';
  61. $comment = '商户提现打款';
  62. $oldData = DB::table($oldTableName)->orderBy('id','asc')->get();
  63. $bar = $this->output->createProgressBar(count($oldData));
  64. $bar->start();
  65. $startTime = time();
  66. $error = [];
  67. foreach ($oldData as $key => $value){
  68. $storeId = $value->store_id;
  69. $userId = $value->user_id;
  70. if(empty($userId)){
  71. $error[] = ['id'=>$userId];
  72. break;
  73. }
  74. // 判断是否存在 总账
  75. $exist = DB::table($newTableName)
  76. ->where('user_id',$userId)
  77. ->where('user_type',5)
  78. ->where('source_id',$value->order_id)
  79. ->where('source_type',0)
  80. ->where('money_type')
  81. ->exists();
  82. if(!$exist){
  83. $newData =[
  84. 'id'=>$userId,
  85. 'nick_name'=>$value->name,
  86. 'avatar'=>$value->img,
  87. 'openid'=>$value->openid,
  88. 'total_score'=>$value->total_score,
  89. 'wallet'=>$value->wallet,
  90. 'real_name'=>$value->user_name,
  91. 'tel'=>$value->user_tel,
  92. 'unionid'=>$value->unionid,
  93. 'created_at' => strtotime($value->join_time),
  94. 'updated_at' => $value->updated_at,
  95. ];
  96. $res = DB::table($newTableName)->insert($newData);
  97. if(!$res){
  98. $error[] = ['id'=>$userId];
  99. break;
  100. }
  101. }
  102. // 判断是否存在 详细账
  103. $mod = bcmod((string)$userId, '5', 0);
  104. $newSubTableName = $newTableName.'_'.$mod;
  105. $existSub = DB::table($newSubTableName)->where('id',$userId)->exists();
  106. if(!$existSub){
  107. $newData =[
  108. 'id'=>$userId,
  109. 'nick_name'=>$value->name,
  110. 'avatar'=>$value->img,
  111. 'openid'=>$value->openid,
  112. 'total_score'=>$value->total_score,
  113. 'wallet'=>$value->wallet,
  114. 'real_name'=>$value->user_name,
  115. 'tel'=>$value->user_tel,
  116. 'unionid'=>$value->unionid,
  117. 'created_at' => strtotime($value->join_time),
  118. 'updated_at' => $value->updated_at,
  119. ];
  120. $res = DB::table($newSubTableName)->insert($newData);
  121. if(!$res){
  122. $error[] = ['id'=>$userId];
  123. break;
  124. }
  125. }
  126. $bar->advance();
  127. }
  128. $bar->finish();
  129. var_dump([time()-$startTime]);
  130. var_dump($error);
  131. return 0;
  132. }
  133. }