| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\controllers;
- use app\constants\OptionSetting;
- use app\librarys\KuaiDi100\KuaiDi100;
- use app\models\AboutArticle;
- use app\models\AppNavbar;
- use app\models\BrowseLog;
- use app\models\Coupon;
- use app\models\District;
- use app\models\Goods;
- use app\models\GoodsBrand;
- use app\models\Option;
- use app\models\Shop;
- use app\models\Store;
- use app\utils\Address\Address;
- use yii\helpers\Json;
- use app\utils\Tools;
- use app\models\WechatConfig;
- use app\constants\StoreImageFrom;
- use app\modules\alliance\models\ConfigForm;
- use app\modules\admin\models\StoreForm;
- use app\modules\alliance\models\ShareQrcodeForm;
- //use app\modules\client\models\v1\TopicForm;
- use app\modules\alliance\models\TopicListForm;
- use app\modules\alliance\models\TopicTypeForm;
- use app\modules\alliance\models\GoodsAttrInfoForm;
- use app\modules\alliance\models\CommentListForm;
- use app\modules\alliance\models\GoodsListForm;
- use app\modules\alliance\models\TopicForm;
- use app\modules\client\models\v1\GoodsBrandForm;
- use app\modules\alliance\models\CatListForm;
- use app\models\Admin;
- class DefaultController extends BaseController
- {
- /**
- * 领券中心
- * @return \yii\web\Response
- */
- public function actionSaasCouponList()
- {
- $page = get_params('page',1);
- $pageSize = get_params('pageSize',20);
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => Coupon::getAllianceList($page,$pageSize, [], get_store_id()) ]);
- }
- /**
- * 获取商盟设置
- */
- public function actionAlliance()
- {
- if (cache()->get('AllianceConfig') && false) {
- $config = cache()->get('AllianceConfig');
- } else {
- $config = ConfigForm::getConfig();
- cache()->set('AllianceConfig', $config, 60 * 60);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $config
- ]);
- }
- /**
- * 获取当前具体位置
- * @return \yii\web\Response
- */
- public function actionLocationContent()
- {
- $longitude = (float)$_REQUEST['longitude']; //用户当前定位的经度
- $latitude = (float)$_REQUEST['latitude']; //用户当前定位的纬度
- $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', '')['value'];
- if (get_store_id() > 0) {
- $tencent_map_key = Option::get(OptionSetting::TENCENT_MAP_KEY, get_store_id(), 'pay', Option::get(OptionSetting::TENCENT_MAP_KEY, get_store_id(), 'store', '')['value'] ?: $tencent_map_key)['value'];
- }
- $place_url = 'https://apis.map.qq.com/ws/geocoder/v1/?location=' . $latitude . ',' . $longitude . '&key=' . $tencent_map_key;
- $json_place = file_get_contents($place_url);
- $place_arr = json_decode($json_place, true);
- $address = $place_arr['result']['address_component'];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $address
- ]);
- }
- /**
- * 获取规格详情
- * @return mixed
- */
- public function actionGoodsAttrInfo()
- {
- $form = new GoodsAttrInfoForm();
- $form->attributes = get_params();
- return $this->asJson($form->search());
- }
- /**
- * 获取所有地区
- * @return \yii\web\Response
- */
- public function actionDistrict()
- {
- $list = District::getAll();
- return $this->asJson([
- 'code' => 0,
- 'data' => $list
- ]);
- }
-
- /**
- * 根据位置解析地址
- */
- public function actionAddressSmart()
- {
- $store_id = get_store_id();
- $address = get_params('address');
- $tencent_map_key = Option::get(OptionSetting::TENCENT_MAP_KEY, $store_id, 'pay', Option::get(OptionSetting::TENCENT_MAP_KEY, $store_id, 'store', '')['value'])['value'];
- //通过地址信息获取经纬度
- if (empty($tencent_map_key)) {
- $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', '')['value'];
- }
- $url = 'https://apis.map.qq.com/ws/geocoder/v1/?';
- $params = [
- 'key' => $tencent_map_key,
- 'address' => $address,
- ];
- $url .= http_build_query($params);
- $json = file_get_contents($url);
- $tencent_result = json_decode($json, true);
- if ($tencent_result['status'] === 0) {
- $address_area = $tencent_result['result']['address_components']['province'] .
- $tencent_result['result']['address_components']['city'] .
- $tencent_result['result']['address_components']['district'] .
- $tencent_result['result']['title'];
- } else {
- $address_area = $address;
- }
- $res = $this->addressSmart(['address' => $address_area]);
- return $this->asJson([
- 'code' => 0,
- 'data' => $res
- ]);
- }
- public function addressSmart($params = []) {
- $res = Address::smart($params['address'], false);
- $province_id = District::find()->where(['and', ['like', 'name', $res['province']], ['level' => 'province']])->one()->id;
- $city_id = District::findOne(['name' => $res['city'], 'level' => 'city'])->id;
- $region_id = District::findOne(['name' => $res['region'], 'level' => 'district'])->id;
- if (!$province_id || !$city_id || !$region_id) {
- $province_id = District::findOne(['name' => '其他', 'level' => 'province'])->id;
- $city_id = District::findOne(['name' => '其他', 'level' => 'city'])->id;
- $region_id = District::findOne(['name' => '其他', 'level' => 'district'])->id;
- $res['province'] = '其他';
- $res['city'] = '其他';
- $res['region'] = '其他';
- }
- $res['province_id'] = $province_id;
- $res['city_id'] = $city_id;
- $res['region_id'] = $region_id;
- return $res;
- }
- /**
- * 获取商城设置
- */
- public function actionStoreInfo()
- {
- $longitude = get_params('longitude', 0); //用户当前定位的经度
- $latitude = get_params('latitude', 0); //用户当前定位的纬度
- $store_id = get_store_id();
- $storeInfo = Store::find()->where(['id'=>$store_id,'is_delete'=>0])->select('address,recommend_keyword,coordinate,name,logo,sales,rank,per_spend,tags,user_name,contact_tel,open_status,s_time,e_time,self_rebate_switch,self_rebate_value,transfer_profit')->asArray()->one();
- if(!$storeInfo){
- return $this->asJson([
- 'code' => 1,
- 'msg' => '不存在店铺信息',
- ]);
- }
- if($storeInfo['coordinate']){
- $coordinateInfo = explode(",",$storeInfo['coordinate']);
- if(isset($coordinateInfo[0]) && isset($coordinateInfo[1])) {
- $storeInfo['distance'] = Tools::getDistance($latitude, $longitude, $coordinateInfo[0], $coordinateInfo[1]);
- }else{
- $storeInfo['distance'] = 0;
- }
- }
- if($storeInfo['self_rebate_switch']){
- if($storeInfo['transfer_profit']>0){
- $storeInfo['rebate'] = sprintf("%.2f", 100 * ($storeInfo['self_rebate_value'] / 100 ) * ($storeInfo['transfer_profit'] / 100 ) );
- }else{
- $storeInfo['rebate'] = 0;
- }
- }else{
- $storeInfo['rebate'] = 0;
- }
- $storeInfo['goods_send_profit'] = Option::get('goods_send_profit', $store_id, 'store', 0)['value'];
- $storeInfo['goods_take_price'] = Option::get('goods_take_price', $store_id, 'store', 0)['value'];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $storeInfo
- ]);
- }
- /**
- * 获取商城设置
- */
- public function actionStore()
- {
- // 服务器图片
- $form = new StoreImageFrom();
- $wxappImg = $form->search();
- $store = null;
- if (get_store_id() > 0) {
- $store = Store::find()->where(['id' => get_store_id()])->select('id, name, logo, kefu_id')->asArray()->one();
- }
- $saasUser = get_saas_user();
- if ($saasUser) {
- $store_admin = Admin::find()->where(['mobile' => $saasUser->mobile, 'is_delete' => 0, 'type' => 'store'])->orderBy('id DESC')->one();
- if (!$store_admin) {
- $store_admin = Admin::find()->where(['saas_user_id' => $saasUser->id, 'is_delete' => 0, 'type' => 'store'])->orderBy('id DESC')->one();
- }
- //此处兼容服务端系统将客服以及云仓功能放入店铺里
- try {
- $payload = \Yii::$app->jwt->getPayload();
- $store_admin_id = $payload['store_admin_id'];
- if ($store_admin_id > 0) {
- $StoreMiniAdmin = \app\models\StoreAdmin::findOne(['id' => $store_admin_id, 'status' => 1, 'is_delete' => 0]);
- $store_id = $StoreMiniAdmin->store_id;
- } else {
- $admin = \app\models\Admin::findOne(['id' => $payload['admin_id']]);
- $store_id = $admin->type_id;
- }
- } catch (\Exception $e) {
- $store_id = $store_admin->type_id;
- }
- if ($store_id) {
- $store = Store::find()->where(['id' => $store_id, 'is_delete' => 0])
- ->select('id, name, logo, kefu_id')->asArray()->one();
- }
- }
- $alliance_service_article = AboutArticle::find()->where(['type' => AboutArticle::TYPE_SERVICE, 'is_delete' => 0])
- ->select(['id'])->asArray()->one();
- $alliance_privacy_article = AboutArticle::find()->where(['type' => AboutArticle::TYPE_PRIVACY, 'is_delete' => 0])
- ->select(['id'])->asArray()->one();
- $store['client_service_id'] = $alliance_service_article['id'] ?? 0;
- $store['client_privacy_id'] = $alliance_privacy_article['id'] ?? 0;
- $store['is_dandianpu'] = \Yii::$app->prod_is_dandianpu();
- $store['is_duli'] = \Yii::$app->prod_is_duli();
- $store['is_saas'] = \Yii::$app->prod_is_saas();
- $store['is_shangmeng'] = \Yii::$app->prod_is_shangmeng();
- $store['platform_gh_id'] = Option::get('platform_gh_id', 0, 'saas')['value'];
- $config =[
- 'images'=>$wxappImg,
- 'store' => $store,
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $config
- ]);
- }
- /**
- * 添加浏览记录
- */
- public function actionBrowse()
- {
- if (get_saas_user_id() > 0) {
- $start = strtotime(date('Y-m-d',time()));
- $form = BrowseLog::find()->where([
- 'log_id' => get_params('id'),
- 'type' => get_params('type'),
- 'store_id' => get_store_id(),
- 'user_id' => 0,
- 'saas_id' => get_saas_user_id(),
- 'is_delete' => 0
- ])->andWhere([
- ">",
- 'created_at',
- $start
- ])->one();
- $form = $form ?: new BrowseLog();
- $form->log_id = get_params('id');
- $form->type = get_params('type');
- $form->store_id = get_store_id();
- $form->user_id = 0;
- $form->saas_id = get_saas_user_id();
- $form->created_at = time();
- $form->save();
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success'
- ]);
- }
- /**
- * 浏览记录列表
- */
- public function actionBrowseList()
- {
- $choose_day = get_params('day');
- if (!empty($choose_day)) {
- $day = strtotime($choose_day);
- } else {
- $day = strtotime(date('Y-m-d', time()));
- }
- $browse_list = BrowseLog::find()->where([
- 'type' => 0,
- //'store_id' => get_store_id(),
- 'user_id' => 0,
- 'saas_id' => get_saas_user_id(),
- 'is_delete' => 0
- ])->andWhere(['>', 'created_at', $day])->andWhere(['<=', 'created_at', $day + 3600 * 24])->all();
- $re_arr = [];
- foreach ($browse_list as $k => $v) {
- $goods_info = Goods::find()->alias('g')
- //->leftJoin(["s"=>Store::tableName()],"g.store_id=s.id")
- ->select('g.id,g.name,g.cover_pic,g.price,g.store_id')->where([
- 'g.id' => $v['log_id'],
- //'store_id' => get_store_id()
- ])->asArray()->one();
- if($goods_info['store_id'] > 0){
- $storeInfo = Store::find()->alias('s')->leftJoin(['w'=>WechatConfig::tableName()],'s.id = w.store_id')->where(['s.id'=>$goods_info['store_id'],'s.is_delete'=>0,'w.type'=>1,'w.is_delete'=>0])->select('w.app_id wechat_app_id,s.id,s.name,s.logo,s.address,s.category_id,s.sales,s.rank,s.per_spend,s.coordinate,s.business_model')->asArray()->one();
- if (!$storeInfo) {
- $goods_info['storeInfo'] = [];
- }else{
- $goods_info['storeInfo'] = $storeInfo;
- }
- }
- $goods_info['log_id'] = $v['id'];
- $re_arr[] = $goods_info;
- }
- $browse_list_shop = BrowseLog::find()->where([
- 'type' => 1,
- 'store_id' => get_store_id(),
- 'user_id' => 0,
- 'saas_id' => get_saas_user_id(),
- 'is_delete' => 0
- ])->andWhere(['>', 'created_at', $day])->andWhere(['<=', 'created_at', $day + 3600 * 24])->all();
- $re_shop_arr = [];
- // 门店浏览记录
- foreach ($browse_list_shop as $k => $v) {
- $shops_info = Shop::find()->select(['id', 'name', 'cover_url as logo', 'mobile as tel', 'score'])->where([
- 'id' => $v['log_id'],
- 'store_id' => get_store_id()
- ])->asArray()->one();
- $shops_info['log_id'] = $v['id'];
- $re_shop_arr[] = $shops_info;
- }
- $data = [
- 're_arr' => $re_arr,
- 're_shop_arr' => $re_shop_arr
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- }
- /**
- * 删除商品浏览记录
- */
- public function actionDelGoodsLog()
- {
- $del_id = get_params('id');
- $del_list = get_params('list');
- if (!empty($del_id)) {
- $log_info = BrowseLog::find()->where([
- 'id' => $del_id,
- 'type' => 0,
- //'store_id' => get_store_id(),
- 'user_id' => 0,
- 'saas_id' => get_saas_user_id(),
- 'is_delete' => 0
- ])->one();
- $log_info->is_delete = 1;
- if ($log_info->save()) {
- return $this->asJson(['code' => 0, 'msg' => '删除成功']);
- } else {
- return $this->asJson(['code' => 1, 'msg' => '删除失败']);
- }
- } else if(!empty($del_list)) {
- $del_list_arr = explode(',', $del_list);
- foreach ($del_list_arr as $v) {
- $log_info = BrowseLog::find()->where([
- 'id' => $v,
- 'type' => 0,
- //'store_id' => get_store_id(),
- 'user_id' => 0,
- 'saas_id' => get_saas_user_id(),
- 'is_delete' => 0
- ])->one();
- $log_info->is_delete = 1;
- $log_info->save();
- }
- return $this->asJson(['code' => 0, 'msg' => '删除成功']);
- }
- }
- /**
- * 文章详情
- * @return \yii\web\Response
- */
- public function actionArticleDetail()
- {
- $id = get_params('id');
- if ($id == 'about_us') {
- $model = AboutArticle::findOne(['type' => AboutArticle::TYPE_ABOUT_US, 'is_delete' => 0]);
- if (!$model) {
- $model = new AboutArticle();
- $model->name = '关于我们';
- $model->store_id = -1;
- $model->type = AboutArticle::TYPE_ABOUT_US;
- $model->desc = '关于我们';
- $model->save();
- }
- $data = [
- 'id' => $model->id,
- 'title' => $model->name,
- 'content' => $model->desc,
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- } else {
- $model = AboutArticle::find()->where([
- 'is_delete' => 0,
- 'id' => $id,
- ])->select('id,name as title,desc as content')->asArray()->one();
- if (empty($model)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '内容不存在'
- ]);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $model
- ]);
- }
- }
- public function actionGoodsQrcode()
- {
- $form = new ShareQrcodeForm();
- $form->attributes = \Yii::$app->request->get();
- $form->store_id = get_store_id();
- $form->type = 0;
- $form->user = get_user();
- $form->user_id = 0;
- $form->saas_id = get_saas_user_id();
- return $this->asJson($form->search());
- }
-
- /**
- * 商品评价列表
- * @return \yii\web\Response
- */
- public function actionCommentList()
- {
- $form = new CommentListForm();
- $form->attributes = get_params();
- return $this->asJson($form->search());
- }
- /**
- * 默认商品列表
- */
- public function actionGoodsList()
- {
- $form = new GoodsListForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 获取品牌列表
- */
- public function actionGetBrandList()
- {
- $list = GoodsBrand::getList(get_store_id());
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $list
- ]
- ]);
- }
- /**
- * 专题列表
- * @return \yii\web\Response
- */
- public function actionTopicList()
- {
- $form = new TopicListForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 专题详情
- * @return \yii\web\Response
- */
- public function actionTopic()
- {
- $form = new TopicForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- if (get_user_id() > 0) {
- $form->user_id = get_user_id();
- }
- return $this->asJson($form->search());
- }
- /**
- * 专题分类
- * @return \yii\web\Response
- */
- public function actionTopicType()
- {
- $form = new TopicTypeForm();
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 专题海报
- * @return \yii\web\Response
- */
- public function actionTopicQrcode()
- {
- $form = new ShareQrcodeForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->type = 6;
- if (get_user_id() > 0) {
- $form->user = get_user();
- $form->user_id = get_user_id();
- }
- return $this->asJson($form->search());
- }
- /**
- * 分类列表
- */
- public function actionCatList()
- {
- $form = new CatListForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 地址识别
- */
- public function actionAddressRecognition() {
- try {
- $store_id = get_store_id();
- $content = post_params('content');
- if (empty(trim($content))) {
- throw new \Exception('缺少必填参数');
- }
- $kuaiDi100UseChange = Option::get(OptionSetting::KUAIDI100_USE_CHANGE, $store_id, 'kuaidi100')['value'];
- if($kuaiDi100UseChange == 1){
- //获取配置信息
- $key = Option::get(OptionSetting::KUAIDI100_SECRET_KEY_NEW, $store_id, 'kuaidi100')['value'];
- $secret = Option::get(OptionSetting::KUAIDI100_SECRET_SECRET_NEW, $store_id, 'kuaidi100')['value'];
- $kuaiDi100Api = new KuaiDi100(['key' => $key, 'secret' => $secret]);
- $result = $kuaiDi100Api->addressResolution($content);
- if($result['code'] != 200){
- throw new \Exception($result['message']);
- }
- $address = [
- 'name' => $result['data']['result'][0]['name'],
- 'mobile' => $result['data']['result'][0]['mobile'][0]
- ];
- $address_area = $result['data']['result'][0]['xzq']['fullName'] . '' . $result['data']['result'][0]['xzq']['subArea'];
- }else{
- $secret_key = Option::get(OptionSetting::KUAIDI100_SECRET_KEY, 0, 'saas')['value'];
- $secret_secret = Option::get(OptionSetting::KUAIDI100_SECRET_SECRET, 0, 'saas')['value'];
- $secret_code = Option::get(OptionSetting::KUAIDI100_SECRET_CODE, 0, 'saas')['value'];
- $secret_sign = Option::get(OptionSetting::KUAIDI100_SECRET_SIGN, 0, 'saas')['value'];
- $secret_sign_ = strtoupper(md5($secret_key . $secret_secret));
- if (!empty($secret_sign)) {
- //验证信息 (感觉没必要)
- if ($secret_sign !== $secret_sign_) {
- throw new \Exception('验证签名失败');
- }
- }
- $params = 'secret_key=' . $secret_key . '&';
- $params .= 'secret_code=' . $secret_code .'&';
- $params .= 'secret_sign=' . $secret_sign_ .'&';
- $params .= 'content=' . $content;
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_POST,1);
- curl_setopt($ch,CURLOPT_HEADER,0);
- curl_setopt($ch,CURLOPT_URL,'http://cloud.kuaidi100.com/api');
- curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- $result = curl_exec($ch);
- $result = json_decode($result, true);
- if ($result['code'] !== 200) {
- throw new \Exception($result['message']);
- }
- // $result = [
- // 'code' => 200,
- // "message" => "success",
- // "data"=> [
- // [
- // 'address' => "建业智慧港1308",
- // 'mobile' => ['15538531881'],
- // 'name' => '张三',
- // 'content' => "张三,15538531881,河南省洛阳市洛龙区建业智慧港1308",
- // 'xzq' => [
- // 'code' => 410311,
- // 'province' => "河南",
- // 'city' => '洛阳市',
- // 'level' => 3,
- // 'district' => '洛龙区',
- // 'pCode' => '410300',
- // 'fullName' => '河南,洛阳市,洛龙区',
- // 'subArea' => '建业智慧港1308'
- // ]
- // ]
- // ]
- // ];
- $address = [
- 'name' => $result['data'][0]['name'],
- 'mobile' => $result['data'][0]['mobile'][0]
- ];
- $address_area = $result['data'][0]['xzq']['fullName'] . '' . $result['data'][0]['xzq']['subArea'];
- }
- //通过地址信息获取经纬度
- $tencent_map_key = Option::get('tencent_map_key', 0, 'saas', '')['value'];
- $url = 'https://apis.map.qq.com/ws/geocoder/v1/?';
- $params = [
- 'key' => $tencent_map_key,
- 'address' => $address_area,
- ];
- $url .= http_build_query($params);
- $json = file_get_contents($url);
- $tencent_result = json_decode($json, true);
- if ($tencent_result['status'] !== 0) {
- throw new \Exception($tencent_result['message']);
- }
- $address['latitude'] = $tencent_result['result']['location']['lat'];
- $address['longitude'] = $tencent_result['result']['location']['lng'];
- $address_area = $tencent_result['result']['address_components']['province'] .
- $tencent_result['result']['address_components']['city'] .
- $tencent_result['result']['address_components']['district'] .
- $tencent_result['result']['title'];
- $smart = $this->addressSmart(['address' => $address_area]);
- $address['addr'] = $result['data']['result'][0]['xzq']['subArea'];
- $address = array_merge($address, $smart);
- return $this->asJson([
- 'code' => 0,
- 'msg' => '识别成功',
- 'data' => $address
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- }
|