12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace App\Crontab;
- use EasySwoole\Crontab\JobInterface;
- use App\Com\SmtpSend;
- use EasySwoole\EasySwoole\Config;
- use App\Models\WarningBody;
- use EasySwoole\Mysqli\QueryBuilder;
- use EasySwoole\ORM\DbManager;
- use EasySwoole\EasySwoole\Logger;
- class ElasticSearchGoodsCrontab implements JobInterface
- {
- public function jobName(): string
- {
-
- return 'ElasticSearchGoodsCrontab';
- }
- public function crontabRule(): string
- {
-
-
- return '*/10 * * * *';
- }
- public function run()
- {
-
- $welfare_api_set = Config::getInstance()->getConf('WELFARE_API');
- $goods = $this->getUpdateGoods();
- foreach($goods as $key=>$value){
- $res = $this->http_request(
- $welfare_api_set['url'],
- ['goodsid'=>$value['id'],'goods_body'=>json_encode($value)]
- );
-
- Logger::getInstance()->notice("商品ID{$value['id']}导入结果:{$res}\n");
- }
-
- }
-
- protected function getUpdateGoods()
- {
- $where = ' g.`updatetime`>'.(time()-1800);
- $que_sql = "SELECT * FROM ims_superdesk_shop_goods g
- WHERE {$where};
- ";
- $queryBuild = new QueryBuilder();
- $queryBuild->raw($que_sql);
- $res_data = DbManager::getInstance()->query($queryBuild, true, 'default')->toArray();
- return $res_data['result'];
- }
-
- protected function http_rquest($url,$data){
- $opts = array(
- 'http' => array(
- 'method' => 'POST',
- 'content' => http_build_query($data),
- )
- );
- $context = stream_context_create($opts);
- $response = file_get_contents($url,false,$context);
- return $response;
- }
- public function onException(\Throwable $throwable)
- {
-
- }
- }
|