WebApplication.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. namespace app\librarys;
  3. use app\models\DiyOnlineTemplate;
  4. use app\models\Option;
  5. use app\models\Store;
  6. /***
  7. * Class Application
  8. * @package app\librarys
  9. */
  10. class WebApplication extends \yii\web\Application
  11. {
  12. /**
  13. * Application constructor.
  14. * @param null $config
  15. * @throws \yii\base\InvalidConfigException
  16. * @throws \Exception
  17. */
  18. public function __construct($config = null)
  19. {
  20. $getParams = $_GET;
  21. $route = isset($getParams['r']) ? $getParams['r'] : null;
  22. if ($route && strpos($route, 'plugin') !== false) {
  23. if (preg_match('/client\/v(\d+)\/plugin\/(.*)/', $route, $matches)) {
  24. // 客户端插件
  25. $_GET['r'] = sprintf('client/v%d/plugin/callback', $matches[1]);
  26. $_GET['callback'] = $matches[2];
  27. } else {
  28. // 后台插件
  29. $callback = str_replace('admin/plugins/', '', $route);
  30. $_GET['r'] = 'admin/plugins/callback';
  31. $_GET['callback'] = $callback;
  32. }
  33. }
  34. parent::__construct($config);
  35. }
  36. public function isSaas()
  37. {
  38. if ($param = \Yii::$app->getRequest()->get('r')) {
  39. $paramArr = explode('/', $param);
  40. switch ($paramArr[0]) {
  41. case 'admin':
  42. return true;
  43. break;
  44. case 'client':
  45. //根据 self_mini 和 mini_id 参数判断是否saas
  46. if (\Yii::$app->request->get('self_mini') && \Yii::$app->request->get('mini_id')) {
  47. return true;
  48. }
  49. break;
  50. default:
  51. return true;
  52. break;
  53. }
  54. } else {
  55. return $this->prod_is_duli();
  56. }
  57. // //根据 self_mini 和 mini_id 参数判断是否saas
  58. // if (\Yii::$app->request->get('self_mini') && \Yii::$app->request->get('mini_id')) {
  59. // return true;
  60. // }
  61. // //根据 username 参数判断是否saas
  62. // $username = input_params('username');
  63. // if ($username) {
  64. // $admin = Admin::findByUsername($username);
  65. // if ($username == 'admin' || $admin->type == Admin::ADMIN_TYPE_SUPPLIER || $admin->type == Admin::ADMIN_TYPE_DEFAULT) {
  66. // return true;
  67. // }
  68. // }
  69. // //根据 Authorization 参数判断是否saas
  70. // $headers = \Yii::$app->getRequest()->getHeaders();
  71. // if ($headers->has('Authorization')) {
  72. // $token = \Yii::$app->jwt->getPayload();
  73. // if (!empty($token)) {
  74. // $admin = Admin::findByUsername($token['username']);
  75. // if ($admin->username == 'admin' || $admin->type === Admin::ADMIN_TYPE_SAAS_STAFF || Admin::ADMIN_TYPE_DEFAULT) {
  76. // return true;
  77. // }
  78. // }
  79. // }
  80. // return false;
  81. }
  82. public function removeMenu($params, $menuKey)
  83. {
  84. array_walk($params, function ($value, $key) use ($menuKey) {
  85. if (in_array($value['key'], $menuKey)) {
  86. unset($key, $params);
  87. }
  88. });
  89. }
  90. /** 是否有独立小程序
  91. * @return bool
  92. */
  93. public function prod_is_duli()
  94. {
  95. $store_id = get_store_id();
  96. if ($store_id) {
  97. $selfMini = Option::get("self_mini", $store_id, 'store')['value'];
  98. if ($selfMini == 1) {
  99. return true;
  100. }
  101. }
  102. return false;
  103. // $plugin = \Yii::$app->getAttr('plugin');
  104. // $is_duli_store_auth = false;
  105. // if (in_array('duli_store', $plugin['union'])) {
  106. // $is_duli_store_auth = true;
  107. // }
  108. // return $is_duli_store_auth;
  109. }
  110. /** 获取在线模板
  111. */
  112. public function getTemplateList()
  113. {
  114. $list = DiyOnlineTemplate::find()->orderBy(['id' => SORT_ASC])->asArray()->all();
  115. return [
  116. 'code' => 0,
  117. 'msg' => 'success',
  118. 'data' => [
  119. 'list' => $list
  120. ]
  121. ];
  122. }
  123. /** 模板内容
  124. * @param $id
  125. * @return array
  126. */
  127. public function getTemplateItem($id)
  128. {
  129. $data = DiyOnlineTemplate::findOne(['id' => $id]);
  130. return [
  131. 'code' => 0,
  132. 'msg' => 'success',
  133. 'data' => [
  134. 'template' => $data->template
  135. ]
  136. ];
  137. }
  138. // ------------------未修改-start--------------
  139. public function getPermission($storeBusinessModel, $storeId)
  140. {
  141. return require \Yii::$app->basePath . '/config/saas_store_permission.php';
  142. }
  143. public function prod_is_dandianpu()
  144. {
  145. return true;
  146. // $storeId = get_params('store_id');
  147. // $store = Store::findOne($storeId);
  148. // if (!empty($store) && $store->business_model == 1){
  149. // return true;
  150. // }
  151. // return false;
  152. }
  153. public function filterMenu($params, $filter = 1)
  154. {
  155. return $params;
  156. }
  157. public function prod_is_shangmengduli()
  158. {
  159. return true;
  160. }
  161. public function getAttr($attr)
  162. {
  163. $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"]}}';
  164. $attrArr = json_decode($str, true);
  165. return empty($attr) ? $attrArr : $attrArr[$attr];
  166. }
  167. public function prod_is_shangmeng()
  168. {
  169. return false;
  170. }
  171. public function prod_is_saas()
  172. {
  173. return false;
  174. }
  175. //系统是否过期
  176. public function isExpired()
  177. {
  178. return false;
  179. }
  180. public function getAuthSwitch($type)
  181. {
  182. return true;
  183. }
  184. //marketingManage_thirdCategory_cityDelivery
  185. public function prod_hide_city_delivery()
  186. {
  187. $storeInfo = Store::findOne(['id' => get_store_id()]);
  188. if (empty($storeInfo['auth']) || in_array('marketingManage_thirdCategory_cityDelivery', json_decode($storeInfo['auth'], true))) {
  189. return false;
  190. }
  191. return true;
  192. }
  193. // ------------------未修改-end--------------
  194. /** (新)是否有独立小程序
  195. * @return bool
  196. */
  197. public function new_prod_is_duli($storeId)
  198. {
  199. $selfMini = Option::get("self_mini", $storeId, 'store')['value'];
  200. if ($selfMini == 1) {
  201. return true;
  202. }
  203. return false;
  204. }
  205. public function __get($name)
  206. {
  207. // 兼容旧写法 Yii::$app->req
  208. if ($name === 'req') {
  209. return $this->getRequest();
  210. }
  211. return parent::__get($name);
  212. }
  213. }