| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace addons\StarChain\common\services;
- use addons\StarChain\common\listeners\RegionImportListener;
- use addons\StarChain\common\models\Region;
- use common\enums\RabbitMqEnum;
- use Yii;
- /**
- * 地址服务
- */
- class RegionService extends BaseService
- {
- /**
- * 导入地址
- *
- * @param string $region_code
- * @return boolean
- */
- public function import($region_code = '')
- {
- Yii::$app->services->rabbitMq->push(
- RabbitMqEnum::EXCHANGE_ORDER,
- RabbitMqEnum::TASK_QUEUE,
- [
- 'mall_id' => $this->mall_id,
- 'region_code' => $region_code,
- ],
- RegionImportListener::class,
- 'async_handle'
- );
- return true;
- }
- /**
- * 任务执行导入
- *
- * @param string $region_code
- * @return boolean
- */
- public function taskImport($region_code = '')
- {
- $list = $this->api->getRegionByCodeOpen($region_code);
- if (empty($list)) {
- return true;
- }
- $list = array_map(function ($v) {
- $arr['region_id'] = $v['id'];
- $arr['name'] = $v['name'];
- $arr['region_code'] = $v['regionCode'];
- $arr['parent_code'] = $v['parentCode'];
- $arr['parent_name'] = $v['parentName'];
- $arr['region_full_name'] = $v['regionFullName'];
- $arr['region_full_codes'] = $v['regionFullCodes'];
- $arr['longitude'] = $v['longitude'];
- $arr['latitude'] = $v['latitude'];
- $arr['initial'] = $v['initial'];
- $arr['region_level'] = $v['regionLevel'];
- return $arr;
- }, $list);
- foreach ($list as $v) {
- $this->import($v['region_code']);
- }
- Region::batchInsert($list, false);
- }
- }
|