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

166 lines
4.7 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) || empty($storeId)){
  68. $error[] = ['user_id'=>$userId,'store_id'=>$storeId];
  69. break;
  70. }
  71. $userType = 0;
  72. $moneyType = 0;
  73. $sourceId = $value->order_id;
  74. $sourceType = 0;
  75. // 判断是否存在 总账
  76. $exist = DB::table($newTableName)
  77. ->where('user_id',$userId)
  78. ->where('user_type',5)
  79. ->where('source_id',$value->order_id)
  80. ->where('source_type',0)
  81. ->where('money_type')
  82. ->exists();
  83. $desc = '';
  84. $comment = '';
  85. if(!$exist){
  86. $newData =[
  87. 'user_id'=>$userId,
  88. 'user_type'=>$userType,
  89. 'money'=>$value->money,
  90. 'money_type'=>$moneyType,
  91. 'source_id'=>$sourceId,
  92. 'source_type'=>$sourceType,
  93. 'desc'=>$desc,
  94. 'comment'=>$comment,
  95. 'status'=>1,
  96. 'created_at' => time(),
  97. 'updated_at' => time(),
  98. ];
  99. $res = DB::table($newTableName)->insert($newData);
  100. if(!$res){
  101. $error[] = ['id'=>$userId];
  102. break;
  103. }
  104. }
  105. // 判断是否存在 详细账
  106. $mod = bcmod((string)$userId, '5', 0);
  107. $newSubTableName = $newTableName.'_'.$mod;
  108. $existSub = DB::table($newSubTableName)->where('id',$userId)->exists();
  109. if(!$existSub){
  110. $newData =[
  111. 'id'=>$userId,
  112. 'nick_name'=>$value->name,
  113. 'avatar'=>$value->img,
  114. 'openid'=>$value->openid,
  115. 'total_score'=>$value->total_score,
  116. 'wallet'=>$value->wallet,
  117. 'real_name'=>$value->user_name,
  118. 'tel'=>$value->user_tel,
  119. 'unionid'=>$value->unionid,
  120. 'created_at' => strtotime($value->join_time),
  121. 'updated_at' => $value->updated_at,
  122. ];
  123. $res = DB::table($newSubTableName)->insert($newData);
  124. if(!$res){
  125. $error[] = ['id'=>$userId];
  126. break;
  127. }
  128. }
  129. $bar->advance();
  130. }
  131. $bar->finish();
  132. var_dump([time()-$startTime]);
  133. var_dump($error);
  134. return 0;
  135. }
  136. public function getMoneyType($type,$note)
  137. {
  138. }
  139. }