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

94 lines
2.7 KiB

  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Schema;
  7. class SetStoreUsers extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'migrateData:SetStoreUsers';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command 店铺的账号表整理';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. * 店铺的登录账号,店长、店员
  33. * 将旧账号表的关联的店铺id和角色洗到新的店铺账号表
  34. * @return int
  35. */
  36. public function handle()
  37. {
  38. $oldAccount = 'ims_cjdc_account';
  39. $oldTable = 'ims_users';
  40. $newTable = 'lanzu_store_users';
  41. $oldData = DB::table($oldTable)->get();
  42. $account = DB::table($oldAccount)->select('uid','role','storeid')->get()->toArray();
  43. $accountArr = array_column($account,null,'uid');
  44. $bar = $this->output->createProgressBar(count($account));
  45. $bar->start();
  46. $accountStr = '已经存在的账号id:';
  47. $newData = [];
  48. foreach ($oldData as $k => $v){
  49. $exist = DB::table($newTable)->where('id',$v->uid)->exists();
  50. if($exist){
  51. $accountStr .= ','.$v->uid;
  52. }else{
  53. $newData[] =[
  54. 'id' => $v->uid,
  55. 'openid' => $v->openid ?? '',
  56. 'username' => $v->username ?? '',
  57. 'password' => $v->password ?? '',
  58. 'salt' => $v->salt ?? '',
  59. 'register_type' => 0,
  60. 'status' => $v->status ?? 0,
  61. 'join_ip' => $v->joinip ?? '',
  62. 'last_visit_time' => $v->lastvisit ?? 0,
  63. 'last_ip' => $v->lastip ?? '',
  64. 'token' => $v->token ?? '',
  65. 'token_expire' => $v->token_expire ?? '',
  66. 'remark' => $v->remark ?? '',
  67. 'created_at' => $v->joindate ?? 0,
  68. 'updated_at' => time(),
  69. 'user_category'=> isset($accountArr[$v->uid]) ? $accountArr[$v->uid]->role ?? 0 : 0,
  70. 'store_id'=> isset($accountArr[$v->uid]) ? $accountArr[$v->uid]->storeid ?? 0 : 0,
  71. ];
  72. }
  73. }
  74. DB::table($newTable)->insert($newData);
  75. $bar->finish();
  76. var_dump($accountStr);
  77. return 0;
  78. }
  79. }