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

71 lines
1.8 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. // 如果表不存在则创建
  39. if(!Schema::hasTable('lanzu_store_users')){
  40. Schema::create('lanzu_store_users',function (Blueprint $table){
  41. $table->id();
  42. });
  43. }
  44. $account = DB::table('ims_cjdc_account')->get();
  45. $bar = $this->output->createProgressBar(count($account));
  46. $bar->start();
  47. foreach ($account as $ka => $va){
  48. $data = [];
  49. $storeUsers = DB::table('lanzu_store_users')->find($va->uid);
  50. if(!empty($storeUsers)){
  51. $data =[
  52. 'user_category'=>$va->role,
  53. 'store_id'=>$va->storeid
  54. ];
  55. DB::table('lanzu_store_users')->where('id',$va->uid)->update($data);
  56. }
  57. $bar->advance();
  58. }
  59. $bar->finish();
  60. return 0;
  61. }
  62. }