1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php declare(strict_types=1);
- namespace app\api\command;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\facade\Cache;
- use think\facade\Config;
- use think\facade\Db;
- //推送数据到供应商api
- class PushDataToSupplier extends Command
- {
- private $key = 'gys_push_data';//供应商推送数据的key,本目录下配置文件读取不到,所以指定在这里,轻易不要修改,要和其他地方保持一致
- protected function configure()
- {
- // parent::configure(); // TODO: Change the autogenerated stub
- $this->setName('PushDataToSupplier')->setDescription('推送数据到供应商api');
- }
- protected function execute(Input $input, Output $output)
- {
- $da = Cache::store('redis')->handler()->rpop($this->key);
- // $da = json_encode([
- // 'supplierNo' => 'QS2203150147019298',
- // 'type' => 'cgd',//cgd销售订单,online上线结果
- // 'data' => ['name' => '张三'],
- // ], JSON_UNESCAPED_UNICODE);
- if ($da) {
- $da = json_decode($da, true);
- //有推送地址
- $res = Db::name('development')
- ->field('id,push_url')
- ->where('supplierNo', $da['supplierNo'])
- ->where('push_url', '<>', '')
- ->withAttr('push_url', function ($val) {
- return explode(',', $val);
- })
- ->findOrEmpty();
- if ($res) {
- $insert = [];
- foreach ($res['push_url'] as $url){
- $response = curl_request($url,$da);
- $insert[]=[
- 'supplierNo'=>$da['supplierNo'],
- 'push_url'=>$url,
- 'type'=>$da['type'],
- 'data'=>json_encode($da,JSON_UNESCAPED_UNICODE),
- 'response'=>$response
- ];
- }
- if($insert) Db::name('push_log')->insertAll($insert);
- }
- }
- // return parent::execute($input, $output); // TODO: Change the autogenerated stub
- //订阅?
- //哪些数据?
- //订单
- //产品上线的状态
- //数据格式
- }
- }
|