| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\client\controllers\v1;
- use app\constants\OptionSetting;
- use app\librarys\KuaiDi100\KuaiDi100;
- use app\models\AboutArticle;
- use app\models\AccessoriesWorks;
- use app\models\AppNavbar;
- use app\models\BrowseLog;
- use app\models\BuyGoodsLog;
- use app\models\Coupon;
- use app\models\District;
- use app\models\Goods;
- use app\models\GoodsBrand;
- use app\models\Insurance;
- use app\models\Mch;
- use app\models\Md;
- use app\models\Option;
- use app\models\Order;
- use app\models\SaasCategory;
- use app\models\Shop;
- use app\models\Store;
- use app\models\StoreImageSearchSetting;
- use app\models\User;
- use app\modules\client\models\v1\CommentListForm;
- use app\modules\client\models\v1\GoodsAttrInfoForm;
- use app\modules\client\models\v1\IndexForm;
- use app\modules\client\controllers\BaseController;
- use app\modules\client\models\v1\CatListForm;
- use app\modules\client\models\v1\EvaluateCenterForm;
- use app\modules\client\models\v1\GoodsListForm;
- use app\modules\client\models\v1\IntelligentMatchForm;
- use app\modules\client\models\v1\SearchForm;
- use app\modules\client\models\v1\ShareQrcodeForm;
- use app\modules\client\models\v1\ShopForm;
- use app\modules\client\models\v1\ShopListForm;
- use app\modules\client\models\v1\StoreConfigForm;
- use app\modules\client\models\v1\TopicForm;
- use app\modules\client\models\v1\TopicListForm;
- use app\modules\client\models\v1\TopicTypeForm;
- use app\modules\client\models\v1\UploadForm;
- use app\utils\Address\Address;
- use app\utils\TiiaHelper;
- use yii\helpers\Json;
- use app\modules\admin\models\MchForm;
- use app\modules\admin\models\mochat\MochatForm;
- class DefaultController extends BaseController
- {
- /**
- * 获取商城设置
- */
- public function actionStore()
- {
- if (cache()->get('StoreConfig') && false) {
- $config = cache()->get('StoreConfig');
- } else {
- $config = StoreConfigForm::getConfig(get_store_id());
- cache()->set('StoreConfig', $config, 60 * 60);
- }
- if(!cache_lock(['scrm_MSG_TYPE_CLICK_STORE', get_store_id(), MochatForm::MSG_TYPE_CLICK_STORE, get_saas_user_id()], (24 - date('H')) * 3600)){
- MochatForm::sendMsg(1, get_store_id(), MochatForm::MSG_TYPE_CLICK_STORE, get_saas_user_id());
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $config,
- 'getClientConfig' => StoreConfigForm::getClientConfig(get_store_id(), get_mini_id()),
- ]);
- }
- /**
- * 商户设置
- */
- public function actionMchSetting()
- {
- $store_id = get_store_id();
- $form = new MchForm();
- $form->attributes = all_params();
- $form->store_id = $store_id;
- $result = $form->mchSetting();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'ok',
- 'data' => $result,
- ]);
- }
- /**
- * 入驻商
- */
- public function actionMch()
- {
- $mch_id = input_params('mch_id');
- $store_id = get_store_id();
- $form = new MchForm();
- $form->attributes = all_params();
- $form->store_id = $store_id;
- $form->mch_id = $mch_id;
- $result = $form->mchInfo();
- return $this->asJson($result);
- }
- /**
- * 入驻商
- */
- public function actionMchList()
- {
- $store_id = get_store_id();
- $form = new MchForm();
- $form->attributes = all_params();
- $form->store_id = $store_id;
- $form->orderByDis = get_params('orderByDis', 1);
- $form->is_open = Mch::IS_OPEN_TRUE;
- $result = $form->mchList();
- return $this->asJson($result);
- }
- /**
- * 入驻商注册
- */
- public function actionMchReg()
- {
- $store_id = get_store_id();
- $user_id = get_user_id();
- $saas_user_id = get_saas_user_id();
- $form = new MchForm();
- $form->attributes = all_params();
- $form->store_id = $store_id;
- $form->user_id = $user_id;
- $form->saas_id = $saas_user_id;
- $result = $form->mchReg();
- return $this->asJson($result);
- }
- /**
- * 入驻商注册记录
- */
- public function actionMchRegInfo()
- {
- $store_id = get_store_id();
- $user_id = get_user_id();
- $form = new MchForm();
- $form->store_id = $store_id;
- $form->user_id = $user_id;
- $result = $form->mchAuditList();
- return $this->asJson($result);
- }
- /**
- * 入驻商分类列表
- */
- public function actionMchCommonCatList()
- {
- $store_id = get_store_id();
- $form = new MchForm();
- $form->attributes = all_params();
- $form->store_id = $store_id;
- $form->is_show = 1;
- $result = $form->mchCommonCatList();
- return $this->asJson($result);
- }
- /**
- * 入驻商商品分类
- */
- public function actionMchCat()
- {
- $mch_id = input_params('mch_id');
- $goodsCatList = MchForm::goodsCatList($mch_id, 1);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $goodsCatList,
- ]);
- }
- /**
- * 入驻商访客
- */
- public function actionMchVisit()
- {
- $form = new MchForm();
- $form->mch_id = get_mch_id();
- $result = $form->mchVisit(input_params('date'), 1);
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $result,
- ]);
- }
- /**
- * 送礼配置
- */
- public function actionGivingGiftsConf()
- {
- $conf = \app\modules\admin\models\givingGifts\GivingGiftsForm::conf(get_store_id());
- return $this->asJson([
- 'code' => 0,
- 'data' => $conf,
- ]);
- }
- public function actionGetArea() {
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'area' => file_get_contents('web/v1/statics/area/area.json'),
- 'province' => file_get_contents('web/v1/statics/area/province.json'),
- 'city' => file_get_contents('web/v1/statics/area/city.json')
- ]
- ]);
- }
- /**
- * 平台小程序信息接口
- */
- public function actionPlatform()
- {
- if (cache()->get('PlatformConfig') && false) {
- $config = cache()->get('PlatformConfig');
- } else {
- $config = StoreConfigForm::getPlatformConfig();
- cache()->set('PlatformConfig', $config, 60 * 60);
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $config
- ]);
- }
- /**
- * 获取导航栏配置
- */
- public function actionNavbar()
- {
- return $this->asJson([
- 'code' => 0,
- 'data' => AppNavbar::getNavbar(get_store_id())
- ]);
- }
- /**
- * 获取首页DIY信息
- */
- public function actionIndex()
- {
- $form = new IndexForm();
- $form->store_id = get_store_id();
- $form->_platform = \Yii::$app->request->get('_platform');
- $form->page_id = \Yii::$app->request->get('page_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());
- }
- /**
- * 获取规格详情
- * @return mixed
- */
- public function actionGoodsAttrInfo()
- {
- $form = new GoodsAttrInfoForm();
- $form->attributes = get_params();
- $form->is_pt = get_params('is_pt', 0);
- return $this->asJson($form->search());
- }
- /**
- * 判断是否多城市版本
- * @return \yii\web\Response
- */
- public function actionStoreType()
- {
- return $this->asJson([
- 'code' => 0,
- 'data' => 0
- ]);
- }
- /**
- * 获取所有地区
- * @return \yii\web\Response
- */
- public function actionDistrict()
- {
- $list = District::getAll();
- return $this->asJson([
- 'code' => 0,
- 'data' => $list
- ]);
- }
- /**
- * 顶部导航栏颜色
- * @return \yii\web\Response
- */
- public function actionNavigationBarColor()
- {
- $navigation_bar_color = Option::get('navigation_bar_color', get_store_id(), 'navbar',Json::encode( [
- 'frontColor' => '#000000',
- 'backgroundColor' => '#ffffff',
- ]));
- return $this->asJson([
- 'code' => 0,
- 'data' => Json::decode($navigation_bar_color['value'])
- ]);
- }
- /**
- * 评价中心
- */
- public function actionEvaluateCenter()
- {
- $form = new EvaluateCenterForm();
- $form->store_id = get_store_id();
- $form->attributes = get_params();
- return $this->asJson($form->search());
- }
- /**
- * 添加浏览记录
- */
- public function actionBrowse()
- {
- if (get_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' => get_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 = get_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' => get_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()->select('id, name, cover_pic, price')->where([
- 'id' => $v['log_id'],
- 'store_id' => get_store_id()
- ])->asArray()->one();
- $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' => get_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' => get_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' => get_user_id(),
- 'is_delete' => 0
- ])->one();
- $log_info->is_delete = 1;
- $log_info->save();
- }
- return $this->asJson(['code' => 0, 'msg' => '删除成功']);
- }
- }
- /**
- * 删除门店浏览记录
- */
- public function actionDelShopLog()
- {
- $del_id = get_params('id');
- if (!empty($del_id)) {
- $log_info = BrowseLog::find()->where([
- 'id' => $del_id,
- 'type' => 1,
- 'store_id' => get_store_id(),
- 'user_id' => get_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' => '删除失败']);
- }
- }
- }
- /**
- * 分类列表
- */
- public function actionCatList()
- {
- $form = new CatListForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 搜索页搜索分类
- */
- public function actionCats()
- {
- $form = new SearchForm();
- return $this->asJson($form->cats());
- }
- /**
- * 搜索页搜索接口
- */
- public function actionSearch()
- {
- $form = new SearchForm();
- $form->attributes = get_params();
- $form->cat = json_decode(get_params('cat'));
- $form->store_id = get_store_id();
- return $this->asJson($form->search());
- }
- /**
- * 默认商品列表
- */
- public function actionGoodsList()
- {
- $form = new GoodsListForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- $form->mch_id = get_mch_id();
- $form->user_id = get_user_id();
- $form->is_accessories = get_params('is_accessories',0);
- return $this->asJson($form->search());
- }
- /**
- * 获取品牌列表
- */
- public function actionGetBrandList()
- {
- $list = GoodsBrand::getList(get_store_id());
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $list
- ]
- ]);
- }
- /**
- * 上传图片
- */
- public function actionUploadImage()
- {
- $form = new UploadForm();
- $form->store_id = get_store_id();
- // return $this->asJson($_FILES);
- return $this->asJson($form->uploadFile('image', 'image'));
- }
- /**
- * 专题列表
- * @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());
- }
- /**
- * 门店列表
- * @return \yii\web\Response
- */
- public function actionShopList()
- {
- $form = new ShopListForm();
- $form->store_id = get_store_id();
- $form->user = get_user();
- $form->attributes = get_params();
- return $this->asJson($form->search());
- }
- /**
- * 门店详情
- * @return \yii\web\Response
- */
- public function actionShopDetail()
- {
- $form = new ShopForm();
- $form->store_id = get_store_id();
- $form->user = get_user();
- $form->attributes = get_params();
- return $this->asJson($form->search());
- }
- /**
- * 获取当前具体位置
- * @return \yii\web\Response
- */
- public function actionLocationContent()
- {
- $longitude = $_REQUEST['longitude']; //用户当前定位的经度
- $latitude = $_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 ?? [
- 'city' => '',
- 'district' => '',
- 'nation' => '',
- 'province' => '',
- 'street' => '',
- 'street_number' => '',
- ]
- ]);
- }
- /**
- * 文章详情
- * @return \yii\web\Response
- */
- public function actionArticleDetail()
- {
- $id = get_params('id');
- if ($id == 'about_us') {
- $model = AboutArticle::find()->where([
- 'store_id' => get_store_id(),
- 'is_delete' => 0,
- ])->orderBy('id ASC')->one();
- if (!$model) {
- $model = new AboutArticle();
- $model->name = '关于我们';
- $model->store_id = get_store_id();
- $model->desc = '关于我们';
- $model->save();
- }
- $data = [
- 'id' => $model->id,
- 'title' => $model->name,
- 'content' => $model->desc,
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- } elseif ($id == 'pt_rules') {
- $model = AboutArticle::find()->where([
- 'store_id' => get_store_id(),
- 'type' => 1,
- 'is_delete' => 0
- ])->one();
- if (!$model) {
- $model = new AboutArticle();
- $model->name = '拼团规则';
- $model->store_id = get_store_id();
- $model->desc = '拼团规则';
- $model->type = 1;
- $model->save();
- }
- $data = [
- 'id' => $model->id,
- 'title' => $model->name,
- 'content' => $model->desc,
- ];
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => $data
- ]);
- } elseif ($id == 'holder_agreement') {
- $holder_agreement = Option::get('holder_agreement', get_store_id(), 'store', '')['value'];
- $data = [
- 'title' => '股东协议',
- 'content' => $holder_agreement,
- ];
- 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
- ]);
- }
- }
- /**
- * 文章列表
- * @return \yii\web\Response
- */
- public function actionArticleList()
- {
- $list = AboutArticle::find()->where([
- 'store_id' => get_store_id(),
- 'is_delete' => 0
- ])->andWhere(['>', 'id' , 1])->orderBy('sort DESC,created_at DESC')
- ->select('id,name as title')->asArray()->all();
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => ['list' => $list]
- ]);
- }
- /**
- * 领券中心
- * @return \yii\web\Response
- */
- public function actionCouponList()
- {
- $coupon_id = intval(input_params('coupon_id', 0));
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => ['list' => Coupon::getList(0, 0, 1, [], $coupon_id)]]);
- }
- /**
- * 领券中心
- * @return \yii\web\Response
- */
- public function actionSaasCouponList()
- {
- return $this->asJson(['code' => 0, 'msg' => 'success', 'data' => ['list' => Coupon::getList(0, 0, 1)]]);
- }
- 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 = get_user_id();
- return $this->asJson($form->search());
- }
- /**
- * 购买数据
- */
- public function actionBuyData()
- {
- $key = "buy_data";
- $cache = cache()->get($key);
- $data = null;
- if ($data) {
- $data = json_decode($cache);
- $cha_time = time() - (int)$data->time;
- }
- unset($data->time);
- if ($data && $data->store_id == get_store_id()) {
- $user = mb_strlen($data->user, 'UTF-8') > 5 ? mb_substr($data->user, 0, 4, 'UTF-8') . '...' : $data->user;
- $address = mb_strlen($data->address, 'UTF-8') > 8 ? mb_substr($data->address, 0, 7, 'UTF-8') . '...' : $data->address;
- $data->url = '/goods/goods/goods?id=' . $data->goods;
- $data->content = $user . '购买了' . $address;
- return $this->asJson([
- 'code' => 0,
- 'data' => $data,
- 'cha_time' => $cha_time,
- 'md5' => md5(json_encode($data)),
- ]);
- } else {
- return $this->asJson([
- 'code' => 1,
- 'data' => null
- ]);
- }
- }
- /**
- * 根据位置解析地址
- */
- 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'];
- } else {
- $address_area = $address;
- }
- $res = $this->addressSmart(['address' => $address_area]);
- return $this->asJson([
- 'code' => 0,
- 'data' => $res
- ]);
- }
- public function addressSmart($params = []) {
- $res = $params['address'];
- if (is_string($params['address'])) {
- $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'] ?? $res['district'], '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['region'] = $res['region'] ?: $res['district'];
- $res['province_id'] = $province_id;
- $res['city_id'] = $city_id;
- $res['region_id'] = $region_id;
- return $res;
- }
- /**
- * 上传图片后返回相似的商品ID
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/17 11:05
- */
- public function actionSearchImage(){
- $tiia = new TiiaHelper();
- $postData = post_params();
- $status = Option::get('tencent_image_setting_status',0,'saas')['value'];
- if($status == 0){
- return $this->asJson(['code'=>1,'msg'=>'平台未开启以图搜图功能']);
- }
- $storeImageSetting = StoreImageSearchSetting::findOne(['store_id'=>get_store_id()]);
- $res = $tiia::searchImage($storeImageSetting->group_id,$postData['image']);
- if($res['code'] == 0){
- $goodsId = array_column($res['data']['ImageInfos'],'EntityId');
- }else{
- $goodsId = [];
- }
- // $goodsId = [1,2,3,4,5,6,7];
- return $this->asJson(['code'=>0,'data'=>$goodsId]);
- }
- /**
- * 获取智配页面数据
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/28 15:20
- */
- public function actionIntelligentMatch(){
- $form = new IntelligentMatchForm();
- $form->store_id = get_store_id();
- $form->goods_id = get_params('goods_id');
- $result = $form->getIntelligentMatch();
- return $this->asJson($result);
- }
- /**
- * 根据场景分类获取场景
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/28 15:24
- */
- public function actionIntelligentScene(){
- $form = new IntelligentMatchForm();
- $form->store_id = get_store_id();
- $form->cat_id = get_params('cat_id');
- $result = $form->getScene();
- return $this->asJson($result);
- }
- /**
- * 生成用户智配作品图 分享使用
- * @return void|\yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/30 09:37
- */
- public function actionMakeWorks(){
- if(empty(post_params('image'))){
- return $this->asJson(['code'=>1,'msg'=>'图片链接不能为空']);
- }
- $model = new AccessoriesWorks();
- $model->user_id = get_user_id();
- $model->user_name = User::findOne(get_user_id())->nickname;
- $model->store_id = get_store_id();
- $model->image = post_params('image');
- $model->goods_ids = post_params('goods_id');
- $model->created_at = time();
- if($model->save()){
- return $this->asJson(['code' => 0, 'data' => ['works_id'=>$model->id], 'msg' => '配置信息保存成功']);
- }
- }
- /**
- * 获取分享页面的信息
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/30 13:48
- */
- public function actionGetWorksItem(){
- $id = get_params('id',0);
- $item = AccessoriesWorks::findOne($id);
- if(!$item){
- return $this->asJson(['code'=>1,'msg'=>'作品不存在']);
- }
- $goodsId = explode(',',$item['goods_ids']);
- $goodsList = Goods::find()->where(['id'=>$goodsId,'status'=>1,'store_id' => get_store_id()])->asArray()->all();
- foreach ($goodsList as &$value){
- $goods = Goods::findOne($value['id']);
- $value['attr_group_list'] = $goods->getAttrGroupList();
- $value['num'] = $goods->getNum();
- }
- return $this->asJson(['code'=>0,'data'=>[
- 'works' => $item,
- 'goods_list' => $goodsList
- ]]);
- }
- /* begin 2023/12/11 15:58:20 WPing丶 */
- /**
- * 模块名:actionGetInsurance
- * 代码描述:通过手机号获取保单
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/12/11 15:58:42
- * @param int phone 手机号
- */
- public function actionGetInsurance()
- {
- $phone = get_params('phone');
- $Insurance = Insurance::find()->where(['phone' => $phone, 'store_id' => get_store_id()])->asArray()->one();
- $Insurance['insurance_size'] = $this->getFileSize($Insurance['insurance']);
- $Insurance['report_size'] = $this->getFileSize($Insurance['report']);
- if($Insurance){
- return $this->asJson([
- 'code' => 0,
- 'data' => $Insurance,
- 'msg' => '查找成功'
- ]);
- }else{
- return $this->asJson([
- 'code' => 1,
- 'msg' => '未找到保单'
- ]);
- }
- }
- /**
- * 模块名:getFileSize
- * 代码描述:获取远程文件大小
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/12/20 16:33:30
- * @param string url 远程文件地址
- */
- public function getFileSize($url) {
- // 使用 cURL 初始化
- $ch = curl_init($url);
- // 设置 cURL 选项,让其仅获取头部信息
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_NOBODY, true);
- // 执行 cURL 请求
- $response = curl_exec($ch);
- // 关闭 cURL 资源
- curl_close($ch);
- // 解析头部信息,获取文件大小
- $headers = explode("\n", $response);
- foreach ($headers as $header) {
- if (strpos($header, 'Content-Length:') !== false) {
- $size = trim(str_replace('Content-Length:', '', $header));
- return $this->formatSizeUnits($size);
- break;
- }
- }
- }
- /**
- * 模块名:formatSizeUnits
- * 代码描述:字节数转化
- * 作者:WPing丶
- * 请求方式:GET
- * 创建时间:2023/12/20 16:34:28
- * @param int bytes 字节数
- */
- function formatSizeUnits($bytes) {
- $units = array('B', 'KB', 'MB', 'GB', 'TB');
-
- $i = 0;
- while ($bytes >= 1024 && $i < count($units) - 1) {
- $bytes /= 1024;
- $i++;
- }
-
- return round($bytes, 2) . ' ' . $units[$i];
- }
- /* end */
- // 获取商品购买记录
- public function actionBuyGoodsLog(){
- $goodsId = get_params('goods_id');
- $time = get_params('time',0);
- $itemQuery = BuyGoodsLog::find()->where(['goods_id'=>$goodsId,'store_id'=>get_store_id()])->andWhere(['>','created_at', time() - 3 * 24 * 3600]);
- if($time){
- $itemQuery->andWhere(['<','created_at',$time]);
- }
- $item = $itemQuery->orderBy('created_at DESC')->asArray()->one();
- if($item){
- $item['nickname'] = func_substr_replace($item['nickname'],'*',1,mb_strlen($item['nickname'],'utf-8') - 1);
- }
- return $this->asJson(['code'=>0,'data'=>$item]);
- }
- /**
- * 扫码获取二维码门店信息
- * @return \yii\web\Response
- * @author: hankaige
- * @Time: 2024/4/16 10:41
- */
- public function actionGetMdInfo(){
- $mdId = get_params('md_id');
- if(empty($mdId)){
- return $this->asJson(['code'=>1,'msg' => '门店ID不能为空']);
- }
- $mdInfo = Md::find()->where(['id'=>$mdId,'store_id'=>get_store_id()])->asArray()->one();
- if($mdInfo){
- return $this->asJson(['code'=>0,'data'=>$mdInfo]);
- }else{
- return $this->asJson(['code'=>1,'msg'=>'门店不存在']);
- }
- }
- /**
- * 地址识别
- */
- public function actionAddressRecognition() {
- try {
- $store_id = get_store_id();
- $content = post_params('content');
- if (empty(trim($content))) {
- throw new \Exception('缺少必填参数');
- }
- $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'];
- }
- if (empty(trim($tencent_map_key))) {
- 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, $store_id, 'kuaidi100')['value'];
- $secret_code = Option::get(OptionSetting::KUAIDI100_SECRET_CODE, $store_id, 'kuaidi100')['value'];
- $secret_secret = Option::get(OptionSetting::KUAIDI100_SECRET_SECRET, $store_id, 'kuaidi100')['value'];
- $secret_sign = Option::get(OptionSetting::KUAIDI100_SECRET_SIGN, $store_id, 'kuaidi100')['value'];
- if (empty($secret_key) || empty($secret_secret) || empty($secret_code)) {
- $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'];
- }
- $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 = array_merge($address, $smart);
- $address['addr'] = $result['data']['result'][0]['xzq']['subArea'];
- return $this->asJson([
- 'code' => 0,
- 'msg' => '识别成功',
- 'data' => $address
- ]);
- } catch (\Exception $e) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- //获取商城分类
- public function actionGetStoreCategory()
- {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- 'list' => SaasCategory::getList()
- ]
- ]);
- }
- //获取商城列表
- public function actionGetStoreList() {
- try {
- $mch_common_cat_id = get_params('mch_common_cat_id');
- $name = get_params('name');
- $orderByDis = get_params('orderByDis');
- $orderByAi = get_params('orderByAi');
- $lng = get_params('lng', '0') ?: '0';
- $lat = get_params('lat', '0') ?: '0';
- $dis = get_params('dis');
- $pageNo = input_params('pageNo', input_params('page', 1)) ?: 1;
- $pageSize = input_params('pageSize', \Yii::$app->params['pageSize']) ?: \Yii::$app->params['pageSize'];
- $type = intval(get_params('type', 0));
- //查询非独立运营店铺
- $self_mini_store_id = Option::find()->where(['name' => 'self_mini', 'group' => 'store', 'value' => 0])
- ->select('store_id')->column();
- //查询未加入共享流量的店铺 给过滤掉
- $filter_store_id = Option::find()->where([
- 'name' => 'is_store_traffic_sharing',
- 'group' => 'store',
- 'value' => 0,
- 'store_id' => $self_mini_store_id ?: [0]
- ])->select('store_id')->column();
- $store_id = array_values(array_diff($self_mini_store_id, $filter_store_id));
- $saasUser = get_saas_user();
- if ($type) {
- //已购店铺
- if (!$saasUser) {
- return $this->asJson([
- 'code' => 401,
- 'msg' => '登录失败'
- ]);
- }
- $trade_status_str = implode(',', [
- Order::ORDER_FLOW_NO_SEND,
- Order::ORDER_FLOW_SEND,
- Order::ORDER_FLOW_CONFIRM
- ]);
- $store_id_str = implode(',', $store_id ?: [0]);
- $user_table = User::tableName();
- $order_table = Order::tableName();
- $scan_order_table = \app\plugins\scanCodePay\models\Order::tableName();
- $order_sql = "SELECT o.* FROM {$user_table} u LEFT JOIN (
- SELECT user_id, store_id, pay_time, pay_price from {$order_table} WHERE trade_status IN ({$trade_status_str}) UNION ALL
- SELECT user_id, store_id, created_at pay_time, total_price pay_price FROM {$scan_order_table} WHERE is_pay = 1
- ) o ON u.id = o.user_id
- WHERE u.is_delete = 0 AND o.user_id IS NOT NULL ";
- $order_sql_ = $order_sql . " AND u.binding = '{$saasUser->mobile}' AND u.store_id in ({$store_id_str}) GROUP BY o.store_id ";
- $store_id = array_values(array_column(\Yii::$app->db->createCommand($order_sql_)->queryAll(), 'store_id'));
- }
- $store_table_name = Store::tableName();
- $sql = "select s.* from (select id, name, logo, province_id, city_id, district_id, address, contact_tel tel, category_id,
- acos(cos({$lat}*pi()/180 )*cos(latitude*pi()/180)*cos({$lng}*pi()/180 -longitude*pi()/180)+sin({$lat}*pi()/180 )
- *sin(latitude*pi()/180))*6370996.81 as dis from {$store_table_name} where is_delete = 0) as s";
- $store_id_str = implode(',', $store_id ?: [0]);
- $sql .= " where s.id in ({$store_id_str}) ";
- if (!is_null($mch_common_cat_id) && $mch_common_cat_id > 0) {
- $sql .= " and s.category_id = {$mch_common_cat_id} ";
- }
- if (!empty($name)) {
- $name = trim($name);
- $sql .= " AND s.name LIKE '%{$name}%' ";
- }
- if ($dis) {
- $sql .= " AND s.dis <= {$dis} ";
- }
- $orderByStr = '';
- if ($orderByAi) {
- $orderByStr = ' order by s.id ASC';
- }
- if ($orderByDis) {
- $orderByStr = ' order by s.dis asc';
- }
- if (empty($orderByStr)) {
- $orderByStr = ' order by s.id DESC';
- }
- $sql .= $orderByStr;
- $totalCount = \Yii::$app->db->createCommand($sql)->query()->count();
- $pageInitNum = ($pageNo - 1) * $pageSize;
- $sql .= " LIMIT {$pageSize} OFFSET {$pageInitNum}";
- $list = \Yii::$app->db->createCommand($sql)->queryAll();
- // $pagination = pagination_make($query);
- foreach ($list as &$item) {
- $item['dis'] = $item['dis'] ?: 0;
- if(isset($item['dis'])){
- $item['dis_str'] = $item['dis'] > 1000 ? (round($item['dis'] / 1000, 2) . 'km') : (round($item['dis'], 0) . 'm');
- }
- $item['province'] = \app\models\District::findOne($item['province_id'])->name ?: '';
- $item['city'] = \app\models\District::findOne($item['city_id'])->name ?: '';
- $item['district'] = \app\models\District::findOne($item['district_id'])->name ?: '';
- $item['address'] = $item['province'] . $item['city'] . $item['district'] . $item['address'];
- if (empty($item['name'])) {
- $item['name'] = Option::get('name', $item['id'], 'store', '')['value'];
- }
- if (empty($item['logo'])) {
- $item['logo'] = Option::get('web_log', $item['id'], 'web', '')['value'];
- }
- $item['order_count'] = $item['order_total_price'] = 0;
- $item['order_labels'] = '';
- if ($type) {
- //已购店铺
- $user = User::findOne(['store_id' => $item['id'], 'is_delete' => 0, 'binding' => $saasUser->mobile]);
- if ($user) {
- $user_order_data = \Yii::$app->db->createCommand($order_sql . " AND u.id = {$user->id} ORDER BY o.pay_time DESC ")->queryAll();
- $item['order_count'] = count($user_order_data);
- $item['order_total_price'] = floor_num(array_sum(array_column($user_order_data ?: [], 'pay_price')) ?: 0, 2);
- if ($user_order_data) {
- $first_order = $user_order_data[0];
- $first_order_time = $first_order['pay_time'];
- $diff_time = time() - $first_order_time;
- if ($diff_time <= 86400) {
- $item['order_labels'] = '你今天买过的店';
- } else {
- $day = floor($diff_time / 86400);
- $item['order_labels'] = "你{$day}天前买过的店";
- }
- }
- }
- }
- }
- return $this->asJson([
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'totalCount' => $totalCount,
- 'list' => $list,
- 'pageNo' => $pageNo,
- 'pageSize' => $pageSize,
- ],
- ]);
- } catch (\Exception $e) {
- \Yii::error($e);
- return $this->asJson([
- 'code' => 1,
- 'msg' => $e->getMessage()
- ]);
- }
- }
- }
|