| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- namespace app\librarys;
- use app\models\DiyOnlineTemplate;
- use app\models\Option;
- use app\models\Store;
- /***
- * Class Application
- * @package app\librarys
- */
- class WebApplication extends \yii\web\Application
- {
- /**
- * Application constructor.
- * @param null $config
- * @throws \yii\base\InvalidConfigException
- * @throws \Exception
- */
- public function __construct($config = null)
- {
- $getParams = $_GET;
- $route = isset($getParams['r']) ? $getParams['r'] : null;
- if ($route && strpos($route, 'plugin') !== false) {
- if (preg_match('/client\/v(\d+)\/plugin\/(.*)/', $route, $matches)) {
- // 客户端插件
- $_GET['r'] = sprintf('client/v%d/plugin/callback', $matches[1]);
- $_GET['callback'] = $matches[2];
- } else {
- // 后台插件
- $callback = str_replace('admin/plugins/', '', $route);
- $_GET['r'] = 'admin/plugins/callback';
- $_GET['callback'] = $callback;
- }
- }
- parent::__construct($config);
- }
- public function isSaas()
- {
- if ($param = \Yii::$app->getRequest()->get('r')) {
- $paramArr = explode('/', $param);
- switch ($paramArr[0]) {
- case 'admin':
- return true;
- break;
- case 'client':
- //根据 self_mini 和 mini_id 参数判断是否saas
- if (\Yii::$app->request->get('self_mini') && \Yii::$app->request->get('mini_id')) {
- return true;
- }
- break;
- default:
- return true;
- break;
- }
- } else {
- return $this->prod_is_duli();
- }
- // //根据 self_mini 和 mini_id 参数判断是否saas
- // if (\Yii::$app->request->get('self_mini') && \Yii::$app->request->get('mini_id')) {
- // return true;
- // }
- // //根据 username 参数判断是否saas
- // $username = input_params('username');
- // if ($username) {
- // $admin = Admin::findByUsername($username);
- // if ($username == 'admin' || $admin->type == Admin::ADMIN_TYPE_SUPPLIER || $admin->type == Admin::ADMIN_TYPE_DEFAULT) {
- // return true;
- // }
- // }
- // //根据 Authorization 参数判断是否saas
- // $headers = \Yii::$app->getRequest()->getHeaders();
- // if ($headers->has('Authorization')) {
- // $token = \Yii::$app->jwt->getPayload();
- // if (!empty($token)) {
- // $admin = Admin::findByUsername($token['username']);
- // if ($admin->username == 'admin' || $admin->type === Admin::ADMIN_TYPE_SAAS_STAFF || Admin::ADMIN_TYPE_DEFAULT) {
- // return true;
- // }
- // }
- // }
- // return false;
- }
- public function removeMenu($params, $menuKey)
- {
- array_walk($params, function ($value, $key) use ($menuKey) {
- if (in_array($value['key'], $menuKey)) {
- unset($key, $params);
- }
- });
- }
- /** 是否有独立小程序
- * @return bool
- */
- public function prod_is_duli()
- {
- $store_id = get_store_id();
- if ($store_id) {
- $selfMini = Option::get("self_mini", $store_id, 'store')['value'];
- if ($selfMini == 1) {
- return true;
- }
- }
- return false;
- // $plugin = \Yii::$app->getAttr('plugin');
- // $is_duli_store_auth = false;
- // if (in_array('duli_store', $plugin['union'])) {
- // $is_duli_store_auth = true;
- // }
- // return $is_duli_store_auth;
- }
- /** 获取在线模板
- */
- public function getTemplateList()
- {
- $list = DiyOnlineTemplate::find()->orderBy(['id' => SORT_ASC])->asArray()->all();
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'list' => $list
- ]
- ];
- }
- /** 模板内容
- * @param $id
- * @return array
- */
- public function getTemplateItem($id)
- {
- $data = DiyOnlineTemplate::findOne(['id' => $id]);
- return [
- 'code' => 0,
- 'msg' => 'success',
- 'data' => [
- 'template' => $data->template
- ]
- ];
- }
- // ------------------未修改-start--------------
- public function getPermission($storeBusinessModel, $storeId)
- {
- return require \Yii::$app->basePath . '/config/saas_store_permission.php';
- }
- public function prod_is_dandianpu()
- {
- return true;
- // $storeId = get_params('store_id');
- // $store = Store::findOne($storeId);
- // if (!empty($store) && $store->business_model == 1){
- // return true;
- // }
- // return false;
- }
- public function filterMenu($params, $filter = 1)
- {
- return $params;
- }
- public function prod_is_shangmengduli()
- {
- return true;
- }
- public function getAttr($attr)
- {
- $str = '{"prod":"dandianpu","client":{"store":["wechat_mini_program","alipay_mini_program"],"union":[]},"plugin":{"store":["scan_order","shareholder_sharing","shake_video","adopt","trace","service_home","intelligentMatchScene","GPT","yinbao","scanCodePay","cashier","cityDelivery","alipayPromotion","videoShop","tuiN","storeLocalDelivery","ActivityOrderRebateSelf"],"union":["duli_store","saasMarketingWeChatVipCard","jushuitan","maiyatian","localDelivery"]}}';
- $attrArr = json_decode($str, true);
- return empty($attr) ? $attrArr : $attrArr[$attr];
- }
- public function prod_is_shangmeng()
- {
- return false;
- }
- public function prod_is_saas()
- {
- return false;
- }
- //系统是否过期
- public function isExpired()
- {
- return false;
- }
- public function getAuthSwitch($type)
- {
- return true;
- }
- //marketingManage_thirdCategory_cityDelivery
- public function prod_hide_city_delivery()
- {
- $storeInfo = Store::findOne(['id' => get_store_id()]);
- if (empty($storeInfo['auth']) || in_array('marketingManage_thirdCategory_cityDelivery', json_decode($storeInfo['auth'], true))) {
- return false;
- }
- return true;
- }
- // ------------------未修改-end--------------
- /** (新)是否有独立小程序
- * @return bool
- */
- public function new_prod_is_duli($storeId)
- {
- $selfMini = Option::get("self_mini", $storeId, 'store')['value'];
- if ($selfMini == 1) {
- return true;
- }
- return false;
- }
- public function __get($name)
- {
- // 兼容旧写法 Yii::$app->req
- if ($name === 'req') {
- return $this->getRequest();
- }
-
- return parent::__get($name);
- }
- }
|