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

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