| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\queue\redis\slow;
- use app\extra\life\data\Store;
- use app\model\hx\HxAgent;
- use app\model\hx\HxStorePoi;
- use app\model\system\SystemConfig;
- use Webman\RedisQueue\Consumer;
- class SyncPoi implements Consumer
- {
- /**
- * 消费队列名
- * 同步POI门店
- * @var string
- */
- public string $queue = "poi-sync";
- /**
- * 连接配置
- * @var string
- */
- public string $connection = "default";
- public function consume($data): bool
- {
- try {
- if (empty($data['account'])) return true;
- $hasMore = true;
- $config = (new HxAgent)->where("agent_id",$data['account'])->findOrEmpty();
- $config['version'] = "res";
- if ($config->isEmpty()) return true;
- $page = 1;
- $mode = (new HxStorePoi);
- while ($hasMore) {
- $result = (new Store)->config($config->toArray())->token()->getStoreData($config['account'],$page);
- if (empty($result)) {
- $hasMore = false;
- break;
- }
- if (empty($result['total'])) {
- $hasMore = false;
- echo getDateFull()."==第{$page}页==数据获取结束\n";
- break;
- }
- $totalPage = ceil($result['total'] / 2);
- if ($page >= $totalPage) {
- $hasMore = false;
- }
- foreach ($result['pois'] as $key=>$val) {
- $poi = $mode->where("poi_id",$val['poi']['poi_id'])->findOrEmpty();
- $inData = $val['poi'];
- $inData['agent_id'] = $data['account'];
- if ($poi->isEmpty()) {
- $inData['poi_address'] = $val['poi']['address'];
- $inData['order_start'] = "08:00";
- $inData['order_end'] = "22:00";
- $inData['poi_account_id'] = $val['account']['poi_account']['account_id'];
- echo "写入新数据===".getDateFull()."===".$inData['poi_id']."\n";
- $poi->strict(false)->insertGetId($inData);
- } else {
- echo "更新数据===".getDateFull()."===".$inData['poi_id']."\n";
- $poi->update_at = getDateFull();
- $poi->poi_address = $val['poi']['address'];
- $poi->latitude = $inData['latitude'];
- $poi->longitude = $inData['longitude'];
- $poi->poi_name = $inData['poi_name'];
- $poi->save();
- }
- }
- echo getDateFull()."-页码:{$page}\n";
- $page ++;
- }
- } catch (\Throwable $throwable) {
- echo getDateFull()."==获取POI失败\n";
- echo $throwable->getMessage()."\n";
- echo $throwable->getFile()."【".$throwable->getLine()."】\n";
- }
- return true;
- }
- }
|