canvasToClientRmReasons.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\Client;
  4. use Illuminate\Console\Command;
  5. use Illuminate\Support\Facades\Http;
  6. class canvasToClientRmReasons extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'canvas:toClientRmReasons';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Canvas -> client RM reasons';
  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. $clients = Client::where('shadow_pro_id', null)->get();
  37. $this->info("Processing ".count($clients)." clients");
  38. $successCount = 0;
  39. foreach($clients as $client){
  40. $this->info("Processing client:: ".$client->cell_number);
  41. $canvasJson = $client->canvas_data;
  42. if(!$canvasJson){
  43. $this->info("No canvas");
  44. continue;
  45. }
  46. $canvas = json_decode($canvasJson, true);
  47. $dx = isset($canvas['dx'])?$canvas['dx']:null;
  48. if(!$dx){
  49. $this->info("No DX");
  50. continue;
  51. }
  52. $dxItems = $dx['items'];
  53. $positionIndex = 0;
  54. foreach($dxItems as $dxItem){
  55. if(!isset($dxItem['icd'])){
  56. $this->info("DX item has no icd");
  57. continue;
  58. }
  59. if(!isset($dxItem['title'])){
  60. $this->info("DX item has no title");
  61. continue;
  62. }
  63. $icd = $dxItem['icd'];
  64. $description = $dxItem['title'];
  65. $this->info('Client UID: '.$client->uid.' icd:'.$icd.' description:'.$description);
  66. $javaResponse = $this->submitToJava([
  67. 'clientUid'=>$client->uid,
  68. 'icd'=>$icd,
  69. 'description'=>$description,
  70. 'secret'=>'superman2021',
  71. 'cellNumber'=>2025507072,
  72. 'positionIndex' => $positionIndex
  73. ]);
  74. $this->info("Java response: ".json_encode($javaResponse));
  75. $positionIndex++;
  76. }
  77. $successCount++;
  78. }
  79. $this->info("success count: ".$successCount);
  80. }
  81. private function submitToJava($data)
  82. {
  83. $url = config('stag.backendUrl') . '/dev/createClientRmReason';
  84. $response = Http::asForm()
  85. ->withHeaders([
  86. ])
  87. ->post($url, $data)
  88. ->json();
  89. return $response;
  90. }
  91. }