where(['store_id' => $store_id]); if (!empty($keyword)) { $query->andWhere(['like', 'key_word', $keyword]); } $query->andWhere([ 'and', ['!=', 'key_word', ''], ['!=', 'key_word', 'null'] ]); $recommend_key = array_column(Json::decode(Store::findOne($store_id)->recommend_keyword) ?: [], 'value'); $list = $query->orderBy(['virtual_sales' => SORT_DESC, 'created_at' => SORT_DESC])->select('key_word')->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'recommend_key' => $recommend_key, 'data' => empty($list) ? $list : array_column($list, 'key_word') ]); } public function actionRecommendKey() { return $this->asJson( [ 'code' => 0, 'msg' => 'success', 'data' => Json::decode(Store::findOne(get_store_id())->recommend_keyword) ] ); } public function actionGoodsList() { $form = new GoodsListForm(); $form->store_id = get_store_id(); $form->attributes = get_params(); $form->type = get_params('type', -1); return $this->asJson($form->newSearch()); } /** * 用户收货地址列表 * @return \yii\web\Response */ public function actionUserAddress() { $user_id = get_saas_user_id(); $address = Address::find()->where(['user_id' => $user_id, 'is_delete' => 0])->select('name, mobile, province, city, district, detail, latitude, longitude')->asArray()->all(); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $address ]); } /** * 店铺列表 */ public function actionList() { $form = new StoreListForm(); $form->attributes = get_params(); return $this->asJson($form->list()); } /** * 店铺列表搜索配置参数 */ public function actionSearchParams() { $form = new StoreListForm(); $form->attributes = get_params(); return $this->asJson($form->config()); } /** * @return \yii\web\Response * 获取商城信息 */ public function actionGetInfo() { $id = get_params('store_id'); try { $data = Store::find()->where(['id' => $id, 'is_delete' => 0])->select('id, name, logo')->asArray()->one(); return $this->asJson([ 'code' => 0, 'msg' => '获取成功', 'data' => $data ?: [ 'id' => $id, 'name' => '', 'logo' => '' ] ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 0, 'msg' => $e->getMessage(), 'data' => [ 'id' => $id, 'name' => '', 'logo' => '' ] ]); } } /** * 店铺销量 */ public function actionSales() { $form = new StoreListForm(); return $this->asJson($form->sales()); } public function actionUserInfo() { $is_open_combine = Option::get(OptionSetting::STORE_COMBINE_PAY, get_store_id(), 'recharge')['value']; return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'user' => get_user(), 'is_open_combine' => intval($is_open_combine) ] ]); } public function actionJsConfig() { $api = post_params('api', []); $url = post_params('url', []); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => Wechat::getTicketConfig($api, $url) ]); } public function actionSearchHotel() { $form = new GoodsListForm(); $form->store_id = get_store_id(); $form->attributes = get_params(); return $this->asJson($form->searchHotel()); } /** * 小程序是否开启审核 */ public function actionMpAudit() { // $dan_audit_status = 0; // // if (is_platform()) { // $audit_status = 0; // $is_ali_shenhe = 0; // $is_component_ali_shenhe = 0; // } else { // $audit_status = Option::get('is_shenhe', get_store_id(), 'wechat', 0)['value']; // $is_ali_shenhe = Option::get('is_ali_shenhe', get_store_id(), 'wechat', 0)['value']; // $is_component_ali_shenhe = Option::get('is_component_ali_shenhe', get_store_id(), 'wechat', 0)['value']; // } // if ((int)$audit_status === 0 && (int)$is_ali_shenhe !== 0) { // if (is_alipay_platform()) { // $audit_status = 1; // } // if (is_wechat_platform()) { // $is_ali_shenhe = 0; // } // } // if ((int)$audit_status !== 0 && (int)$is_ali_shenhe === 0) { // if (is_alipay_platform()) { // $audit_status = 0; // } // } // if ((int)$audit_status !== 0 && (int)$is_ali_shenhe !== 0) { // if (is_alipay_platform()) { // $audit_status = 1; // $is_ali_shenhe = 0; // if ((int)$is_component_ali_shenhe === 1) { // $audit_status = 1; // $is_ali_shenhe = 1; // } // } // if (is_wechat_platform()) { // $audit_status = 1; // $is_ali_shenhe = 0; // } // } $data = Store::mpAudit(get_store_id()); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, // 'data' => [ // 'status' => $audit_status, // 'is_ali_shenhe' => $is_ali_shenhe, // 'article' => $article // ] ]); } /** * 根据聚合码id获取store_id * @return \yii\web\Response * @throws \yii\base\InvalidConfigException * @author Syan mzsongyan@gmail.com * @date 2022-09-02 */ public function actionGetStoreByAggregate() { $id = \get_params('id'); $data = AggregateSaasQrcode::findOne(['id' => $id]); return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => [ 'store_id' => $data ? $data->store_id : 0, ], ]); } public function actionAllianceAppInfo() { $data = Option::get([ 'name', OptionSetting::PLATFORM_APP_STORE_ANDROID, OptionSetting::PLATFORM_APP_STORE_IOS, OptionSetting::PLATFORM_STORE_APP_LOGO, OptionSetting::PLATFORM_STORE_APP_BG, ], 0, 'saas'); $arr = []; foreach ($data as $item) { $arr[$item['name']] = $item['value']; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $arr, ]); } // 获取登录信息 public function actionStoreAppInfo() { try { $keys = [ OptionSetting::APP_STORE_ANDROID, OptionSetting::APP_STORE_ANDROID_VERSION, OptionSetting::APP_STORE_IOS, OptionSetting::STORE_APP_LOGO, OptionSetting::STORE_APP_BG, ]; $data = Option::get($keys, get_store_id(), 'app'); $data['one_store_app_android'] = Option::get('one_store_app_android', 0, 'saas');//供应链安卓app地址 $data['one_store_app_android_version'] = Option::get('one_store_app_android_version', 0, 'saas');//供应链安卓app版本 if (empty($data)) { $data = [ OptionSetting::APP_STORE_ANDROID => '', OptionSetting::APP_STORE_ANDROID_VERSION => '', OptionSetting::APP_STORE_IOS => '', OptionSetting::STORE_APP_LOGO => '', OptionSetting::STORE_APP_BG => '', 'one_store_app_android' => '',//供应链安卓app地址 'one_store_app_android_version' => '',//供应链安卓app版本 ]; } else { $arr = []; foreach ($data as $value) { $index = array_search($value['name'], $keys); unset($keys[$index]); $arr[$value['name']] = $value['value']; } foreach ($keys as $key) { $arr[$key] = ''; } $data = $arr; } $store_name = Option::get(OptionSetting::STORE_NAME, get_store_id(), 'store')['value']; $data = array_merge($data, [ 'store_name' => $store_name ]); //目前供应链没有自己商城app 修改升级所需参数 故替换 if (\Yii::$app->prod_is_dandianpu()) { $data[OptionSetting::APP_STORE_ANDROID] = $data['one_store_app_android']; $data[OptionSetting::APP_STORE_ANDROID_VERSION] = $data['one_store_app_android_version']; } return $this->asJson([ 'code' => 0, 'msg' => 'success', 'data' => $data, ]); } catch (\Exception $e) { return $this->asJson([ 'code' => 1, 'msg' => $e->getMessage() ]); } } //判断是单店铺且平台设置供应链为不可切换店铺时返回店铺id public function actionGetStoreSwitch() { //is_switch_store 是否需要切换店铺 $is_switch_store = false; $store_id = (int)post_params('store_id');//get_store_id不行 get_params('store_id')先获取 拿到的数据不对 $code = post_params('code', ''); $is_dandianpu = \Yii::$app->prod_is_dandianpu(); $token = ''; //判断是单店铺模式 if ($is_dandianpu) { //如果当前店铺是有独立小程序店铺,就不跳转 $self_mini = \app\models\Option::get('self_mini', $store_id, 'store', 0)['value']; if (!intval($self_mini)) { //判断平台设置是否锁定来源店铺 $lock_store = Option::get('one_store_lock_store', 0, 'saas', 0)['value']; if (intval($lock_store)) { //获取注册时店铺id $saas_user = get_saas_user(); if ($saas_user) { //如果是非运营人员就做判断 $storeOperations = StoreOperations::findOne(['saas_id' => $saas_user->id, 'is_delete' => 0]); if (empty($storeOperations) || intval($storeOperations->status) === 0) { //注册店铺id与当前店铺不一致就执行 if ($saas_user->store_id > 0 && intval($saas_user->store_id) !== $store_id) { //如果跳转店铺是没有独立小程序店铺,就跳转 $self_mini = \app\models\Option::get('self_mini', $saas_user->store_id, 'store', 0)['value']; if (!intval($self_mini)) { $store_id = $saas_user->store_id; $is_switch_store = true; } } } } else { $this->addUserLockStore($code, $store_id, $is_switch_store, $token); } } if ($store_id <= 0) { $store_id = \app\models\Option::get('one_store_default_store', 0, 'saas', 1)['value']; } } } $store = Store::findOne($store_id); $copyright = Option::get('copyright', $store_id, 'store', '')['value']; $copyright = json_decode($copyright, true) ?: [ 'type' => 1, 'mini_url' => [ 'name' => '商城首页', 'link' => '/pages/home/home', 'open_type' => "switchtab", 'params' => [] ], 'mobile' => $store_admin->mobile ?? '', 'logo' => $store->logo ?: (Option::get('logo', get_store_id(), 'store')['value'] ?: Option::get('web_log', get_store_id(), 'web')['value']), 'copyright' => $store->name ?? '' ]; $copyright['type'] = intval($copyright['type']); return $this->asJson([ 'code' => 0, 'data' => [ 'is_switch_store' => $is_switch_store, 'store_id' => $store_id, 'copyright' => $copyright, 'token' => $token ] ]); } //用户锁定店铺记录 //https://docs.qq.com/doc/DWUdjZGNEQmtNaHFX第八条 public function addUserLockStore($code, &$store_id, &$is_switch_store = false, &$token = '') { // $is_switch_store = false; $user = get_user(); if (!$user && $code) { //用户未登陆时 获取openid来分辨用户 [$wechat_open_id, $ali_user_id, $ali_open_id] = (new UserForm())->getOpenId($code, [ 'wechat_open_id' => '', 'ali_user_id' => '', 'ali_open_id' => '', ]); //如果微信openid存在 if (!empty($wechat_open_id)) { //查询当前小程序的用户是否存在 $user = User::findOne(['wechat_open_id' => $wechat_open_id, 'is_delete' => 0]); //查询是否存在锁定关系 $userLockStoreLog = UserLockStoreLog::findOne(['is_delete' => 0, 'wechat_open_id' => $wechat_open_id]); } //如果支付宝userid存在 if (!empty($ali_user_id)) { //查询用户是否存在 $user = User::findOne(['alipay_open_id' => $ali_user_id, 'is_delete' => 0]); //查询是否存在锁定关系 $userLockStoreLog = UserLockStoreLog::findOne(['is_delete' => 0, 'ali_user_id' => $ali_user_id]); } //如果支付宝openid存在 if (!empty($ali_open_id)) { //查询当前小程序的用户是否存在 $user = User::findOne(['ali_openId' => $ali_open_id, 'is_delete' => 0]); //查询是否存在锁定关系 $userLockStoreLog = UserLockStoreLog::findOne(['is_delete' => 0, 'ali_openId' => $ali_open_id]); } //查询到小程序用户信息 查询saas_user绑定的store_id if (!empty($user)) { //通过 $saasUser = SaasUser::findOne(['mobile' => $user->binding, 'is_delete' => 0]); } if (!empty($saasUser)) { $lock_store_id = $saasUser->store_id; } else { if (empty($userLockStoreLog)) { $userLockStoreLog = new UserLockStoreLog(); $userLockStoreLog->store_id = $store_id; $userLockStoreLog->wechat_open_id = $wechat_open_id; $userLockStoreLog->ali_user_id = $ali_user_id; $userLockStoreLog->ali_openId = $ali_open_id; if (is_wechat_platform()) { $userLockStoreLog->type = UserLockStoreLog::TYPE_WX; } if (is_alipay_platform()) { $userLockStoreLog->type = UserLockStoreLog::TYPE_ALI; } if (is_app_platform()) { $userLockStoreLog->type = UserLockStoreLog::TYPE_APP; } if (is_h5()) { $userLockStoreLog->type = UserLockStoreLog::TYPE_H5; } $userLockStoreLog->saas_id = $saasUser->id ?? 0; $userLockStoreLog->save(); } $lock_store_id = $userLockStoreLog->store_id; } } else { $saasUser = SaasUser::findOne(['mobile' => $user->binding, 'is_delete' => 0]); $lock_store_id = $saasUser->store_id; } if (!empty($saasUser)) { $token = $saasUser->access_token; $storeOperations = StoreOperations::findOne(['saas_id' => $saasUser->id, 'is_delete' => 0]); } if (empty($storeOperations) || intval($storeOperations->status) === 0) { //注册店铺id与当前店铺不一致就执行 if ($lock_store_id > 0 && intval($lock_store_id) !== $store_id) { //如果跳转店铺是没有独立小程序店铺,就允许切换店铺 $self_mini = \app\models\Option::get('self_mini', $lock_store_id, 'store', 0)['value']; if (!intval($self_mini)) { $is_switch_store = true; } } } if ($is_switch_store) { $store_id = $lock_store_id; } } }