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

84 lines
2.2 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\v3\Store as StoreModel;
  5. use Illuminate\Support\Facades\DB;
  6. class SetStoreBalance extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'migrateData:setStoreBalance';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command 在user_balance表添加商户钱包';
  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. * 先判断是否存在,不存在则添加一条店铺的钱包记录
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. $oldData = DB::table('ims_cjdc_store')->get();
  38. var_dump('start_time:'.date('H:i:s',time()));
  39. $bar = $this->output->createProgressBar(count($oldData));
  40. $bar->start();
  41. $data = [];
  42. $newData = [];
  43. foreach ($oldData as $key => $value){
  44. // 查询店铺是否存在balance
  45. $exist = DB::table('lanzu_user_balance')
  46. ->where('source_id',$value->id)
  47. ->where('user_type',5)
  48. ->first();
  49. if(empty($exist)){
  50. $newData[] = [
  51. 'source_id' => $value->id,
  52. 'user_type' => 5,
  53. 'balance' => 0,
  54. 'created_at' => time(),
  55. 'updated_at' => time()
  56. ];
  57. }else{
  58. $data[] = [
  59. 'store_id' => $value->id,
  60. 'balance_id' => $exist->id
  61. ];
  62. }
  63. $bar->advance();
  64. }
  65. // 添加到新表
  66. $res = DB::table('lanzu_user_balance')->insert($newData);
  67. $bar->finish();
  68. var_dump(' end_time: '.date('H:i:s',time()));
  69. var_dump('new_total: '.count($newData));
  70. var_dump('exist: '.count($data));
  71. var_dump('res: '.$res);
  72. // var_dump($data);
  73. return 0;
  74. }
  75. }