PushDataToSupplier.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php declare(strict_types=1);
  2. namespace app\api\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\facade\Cache;
  7. use think\facade\Config;
  8. use think\facade\Db;
  9. //推送数据到供应商api
  10. class PushDataToSupplier extends Command
  11. {
  12. private $key = 'gys_push_data';//供应商推送数据的key,本目录下配置文件读取不到,所以指定在这里,轻易不要修改,要和其他地方保持一致
  13. protected function configure()
  14. {
  15. // parent::configure(); // TODO: Change the autogenerated stub
  16. $this->setName('PushDataToSupplier')->setDescription('推送数据到供应商api');
  17. }
  18. protected function execute(Input $input, Output $output)
  19. {
  20. $da = Cache::store('redis')->handler()->rpop($this->key);
  21. // $da = json_encode([
  22. // 'supplierNo' => 'QS2203150147019298',
  23. // 'type' => 'cgd',//cgd销售订单,online上线结果
  24. // 'data' => ['name' => '张三'],
  25. // ], JSON_UNESCAPED_UNICODE);
  26. if ($da) {
  27. $da = json_decode($da, true);
  28. //有推送地址
  29. $res = Db::name('development')
  30. ->field('id,push_url')
  31. ->where('supplierNo', $da['supplierNo'])
  32. ->where('push_url', '<>', '')
  33. ->withAttr('push_url', function ($val) {
  34. return explode(',', $val);
  35. })
  36. ->findOrEmpty();
  37. if ($res) {
  38. $insert = [];
  39. foreach ($res['push_url'] as $url){
  40. $response = curl_request($url,$da);
  41. $insert[]=[
  42. 'supplierNo'=>$da['supplierNo'],
  43. 'push_url'=>$url,
  44. 'type'=>$da['type'],
  45. 'data'=>json_encode($da,JSON_UNESCAPED_UNICODE),
  46. 'response'=>$response
  47. ];
  48. }
  49. if($insert) Db::name('push_log')->insertAll($insert);
  50. }
  51. }
  52. // return parent::execute($input, $output); // TODO: Change the autogenerated stub
  53. //订阅?
  54. //哪些数据?
  55. //订单
  56. //产品上线的状态
  57. //数据格式
  58. }
  59. }