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;
- class PushDataToSupplier extends Command
- {
- private $key = 'gys_push_data';
- protected function configure()
- {
- $this->setName('PushDataToSupplier')->setDescription('推送数据到供应商api');
- }
- protected function execute(Input $input, Output $output)
- {
- $da = Cache::store('redis')->handler()->rpop($this->key);
- 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);
- }
- }
-
-
-
-
-
- }
- }
|