StoreConfigForm.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * @Author: your name
  9. * @Date: 2021-03-02 09:50:20
  10. * @LastEditTime: 2021-05-20 18:08:04
  11. * @LastEditors: Please set LastEditors
  12. * @Description: In User Settings Edit
  13. * @FilePath: \admin_php\modules\client\models\v1\StoreConfigForm.php
  14. */
  15. namespace app\modules\client\models\v1;
  16. use app\constants\OptionSetting;
  17. use app\constants\StoreImageFrom;
  18. use app\models\Admin;
  19. use app\models\AppNavbar;
  20. use app\models\District;
  21. use app\models\Option;
  22. use app\models\StoreOperations;
  23. use yii\base\BaseObject;
  24. use yii\base\Model;
  25. use yii\helpers\Json;
  26. use app\models\Store;
  27. class StoreConfigForm extends Model
  28. {
  29. public $store_id;
  30. public static function getClientConfig($store_id, $mini_id)
  31. {
  32. $ali_plugin_goodsDetail = Option::get(OptionSetting::ALI_MINI_PLUGIN_goodsDetail . (string)$mini_id, $store_id, 'store', null)['value'];
  33. if (is_null($ali_plugin_goodsDetail) && !\Yii::$app->prod_is_duli()) {
  34. $ali_plugin_goodsDetail = Option::get(OptionSetting::ALI_MINI_PLUGIN_goodsDetail . 0, 0, 'saas', 1)['value'];
  35. }
  36. return [
  37. OptionSetting::ALI_MINI_PLUGIN_goodsDetail => (int)$ali_plugin_goodsDetail,
  38. ];
  39. }
  40. public static function getConfig($store_id)
  41. {
  42. $contact_tel = Option::get(OptionSetting::STORE_CONTACT_TEL, $store_id);
  43. $store_name = Option::get(OptionSetting::STORE_NAME, $store_id);
  44. // 服务器图片
  45. $form = new StoreImageFrom();
  46. $share_form = new ShareForm();
  47. $wxappImg = $form->search();
  48. $lang = '';
  49. if (is_platform()) {
  50. $lang = Option::get('lang', 0, 'saas', 'zh-CN')['value'];
  51. } else {
  52. $lang = Option::get('language', get_store_id(), 'display', 'zh-CN')['value'];
  53. }
  54. $store = Store::findOne(get_store_id());
  55. $lat = '';
  56. $long = '';
  57. $distance = '未知距离';
  58. $coordinate = explode(',', $store->coordinate);
  59. if ($coordinate) {
  60. $lat = isset($coordinate[0]) ? $coordinate[0] : 0;
  61. $long = isset($coordinate[1]) ? $coordinate[1] : 0;
  62. }
  63. $store_info = self::getStore($store_id);
  64. $store_info['payment'] = json_decode(Option::get('payment', $store_id, 'store', '{}')['value'], true);
  65. $store_info['latitude'] = $lat;
  66. $store_info['longitude'] = $long;
  67. $store_info['distance'] = $distance;
  68. $store_info['mobile'] = $store->contact_tel;
  69. $store_info['address'] = $store->address;
  70. $store_info['province_name'] = District::findOne($store->province_id)->name;
  71. $store_info['city_name'] = District::findOne($store->city_id)->name;
  72. $store_info['district_name'] = District::findOne($store->district_id)->name;
  73. $store_info['cover_url'] = $store->logo;
  74. $store_info['saas_name'] = Option::get('name', 0, 'saas', '')['value'];
  75. $store_info['saas_logo'] = Option::get('logo', 0, 'saas', '')['value'];
  76. if (\Yii::$app->prod_is_dandianpu()) {
  77. $store_info['mch_appid'] = Option::get('platform_mch_appid', 0, 'saas', '')['value'];
  78. }
  79. $switch_store = Option::get('one_store_switch_store', 0, 'saas', 0);
  80. $default_store = Option::get('one_store_default_store', 0, 'saas', 1)['value'];
  81. if ($store_id) {
  82. $result = self::getStoreSwitch($store_id);
  83. $default_store = $result['store_id'];
  84. }
  85. $is_password_login = Option::get(OptionSetting::IS_PASSWORD_LOGIN, $store_id, 'display', 0)['value'];
  86. $is_password_login = Option::get(OptionSetting::IS_PASSWORD_LOGIN, $store_id, 'reg', $is_password_login)['value'];
  87. $is_password_login_phone_verify = Option::get(OptionSetting::IS_PASSWORD_LOGIN_PHONE_VERIFY, $store_id, 'display', 0)['value'];
  88. $is_password_login_phone_verify = Option::get(OptionSetting::IS_PASSWORD_LOGIN_PHONE_VERIFY, $store_id, 'reg', $is_password_login_phone_verify)['value'];
  89. $store_info['is_password_login'] = intval($is_password_login);
  90. $store_info['is_password_login_phone_verify'] = intval($is_password_login_phone_verify);
  91. $one_store_hide_apply = Option::get('one_store_hide_apply', 0, 'saas', '0')['value'];
  92. $store_info['kefu_id'] = $store->kefu_id;
  93. if (is_wechat_platform()) {
  94. $alipay_login_toggle = Option::get('wechat_login_toggle', get_store_id(), 'wechat', 0)['value'];
  95. $store_info['alipay_login_toggle'] = Option::get('wechat_login_toggle', get_store_id(), 'reg', $alipay_login_toggle)['value'];
  96. }
  97. if (is_alipay_platform()) {
  98. $store_info['alipay_login_toggle'] = 1;//Option::get('alipay_login_toggle', get_store_id(), 'alipay', 0)['value'];
  99. }
  100. $default_user_info_arr = OptionSetting::default_user_info_arr();
  101. $default_user_info = [
  102. 'default_user_nickname' => $default_user_info_arr['default_user_nickname'] ?? '',
  103. 'default_user_pic' => $default_user_info_arr['default_user_pic'] ?? '',
  104. ];
  105. if (isset($default_user_info_arr['isOpenDefault'])) {
  106. if (!$default_user_info_arr['isOpenDefault']) {
  107. $default_user_info = [
  108. 'default_user_nickname' => '',
  109. 'default_user_pic' => ''
  110. ];
  111. }
  112. }
  113. $store_info['default_user_info'] = $default_user_info;
  114. $store_info['app_is_open_map'] = Option::get(OptionSetting::APP_IS_OPEN_MAP, get_store_id(), 'app', 2)['value'];
  115. $copyright = Option::get('copyright', get_store_id(), 'store', '')['value'];
  116. if (\Yii::$app->prod_is_dandianpu() && intval(get_store_id()) === 0) {
  117. $copyright = Option::get('copyright', $default_store, 'store', '')['value'];
  118. }
  119. $store_admin = Admin::findOne(['type' => 'store', 'type_id' => get_store_id(), 'is_delete' => 0]);
  120. $store = Store::findOne(get_store_id());
  121. $copyright = json_decode($copyright, true) ?: [
  122. 'type' => 1,
  123. 'mini_url' => [
  124. 'name' => '商城首页',
  125. 'link' => '/pages/home/home',
  126. 'open_type' => "switchtab",
  127. 'params' => []
  128. ],
  129. 'mobile' => $store_admin->mobile ?? '',
  130. 'logo' => $store->logo ?: (Option::get('logo', get_store_id(), 'store')['value'] ?: Option::get('web_log', get_store_id(), 'web')['value']),
  131. 'copyright' => $store->name
  132. ];
  133. foreach ($store_info['payment'] as $pay_type_index => &$pay_type_item) {
  134. if ($pay_type_index === \app\models\Order::PAY_TYPE_KEY_YUNST_WECHAT_PAY) {
  135. $isShowPayType = boolval(Store::findOne($store_id)->cusid);
  136. if (intval($pay_type_item['value']) === 1 && !$isShowPayType) {
  137. $pay_type_item['value'] = 0;
  138. }
  139. }
  140. }
  141. $mchSetting = json_decode(Option::get(OptionSetting::MCH_SETTING, get_store_id(), 'store', '{}')['value'], true);
  142. if(empty($mchSetting)){
  143. $mchSetting = [
  144. 'mch_reg_form' => $mchSetting['mch_reg_form'] ?? [],
  145. 'mch_reg_text' => $mchSetting['mch_reg_text'] ?? '',
  146. 'mch_goods_audit' => $mchSetting['mch_goods_audit'] ?? 0,
  147. 'mch_order_notice' => $mchSetting['mch_order_notice'] ?? 0,
  148. 'mch_cash_type' => $mchSetting['mch_cash_type'] ?? [0],
  149. 'mch_cash_rate' => $mchSetting['mch_cash_rate'] ?? 0,
  150. 'show_mch_mobile' => !isset($mchSetting['show_mch_mobile']) ? 1 : $mchSetting['show_mch_mobile'],
  151. 'show_mch_address' => !isset($mchSetting['show_mch_address']) ? 1 : $mchSetting['show_mch_address'],
  152. ];
  153. }
  154. $mchSetting['show_mch_mobile'] = !isset($mchSetting['show_mch_mobile']) ? 1 : $mchSetting['show_mch_mobile'];
  155. $mchSetting['show_mch_address'] = !isset($mchSetting['show_mch_address']) ? 1 : $mchSetting['show_mch_address'];
  156. $copyright['type'] = intval($copyright['type']);
  157. $config = [
  158. 'share_setting' => $share_form->getShareSetting()['data'],
  159. 'images' => $wxappImg,
  160. 'wx_bar_title' => [],
  161. 'store_name' => $store_name ? $store_name['value'] : '',
  162. 'contact_tel' => $contact_tel ? $contact_tel['value'] : '',
  163. 'store' => $store_info,
  164. 'navbar' => self::getNav(),
  165. 'platform_appid' => Option::getSaasWechat()['sp_appid'],
  166. 'language' => $lang,
  167. 'one_store_switch_store' => (bool)$switch_store['value'],
  168. 'one_store_default_store' => $default_store ?: 1,
  169. 'one_store_hide_apply' => (string)$one_store_hide_apply,
  170. 'copyright' => $copyright,
  171. 'shareHolderAliasName' => Option::get('shareHolderAliasName', $store_id, 'bonus_pool', '股东')['value'],
  172. 'mch_setting' => $mchSetting
  173. ];
  174. // \Yii::error([__METHOD__, $config]);
  175. return $config;
  176. }
  177. //判断是单店铺且平台设置供应链为不可切换店铺时返回店铺id
  178. public static function getStoreSwitch($store_id) {
  179. //is_switch_store 是否需要切换店铺
  180. $is_switch_store = false;
  181. $is_dandianpu = \Yii::$app->prod_is_dandianpu();
  182. //判断是单店铺模式
  183. if ($is_dandianpu) {
  184. //如果当前店铺是有独立小程序店铺,就不跳转
  185. $self_mini = \app\models\Option::get('self_mini', $store_id, 'store', 0)['value'];
  186. if (!intval($self_mini)) {
  187. //判断平台设置是否可以切换店铺
  188. $lock_store = Option::get('one_store_lock_store', 0, 'saas', 0)['value'];
  189. if (intval($lock_store)) {
  190. //获取注册时店铺id
  191. $saas_user = get_saas_user();
  192. //如果是非运营人员就做判断
  193. $storeOperations = StoreOperations::findOne(['saas_id' => $saas_user->id, 'is_delete' => 0]);
  194. if (empty($storeOperations) || intval($storeOperations->status) === 0) {
  195. //注册店铺id与当前店铺不一致就执行
  196. if ($saas_user->store_id > 0 && intval($saas_user->store_id) !== $store_id) {
  197. //如果跳转店铺是没有独立小程序店铺,就跳转
  198. $self_mini = \app\models\Option::get('self_mini', $saas_user->store_id, 'store', 0)['value'];
  199. if (!intval($self_mini)) {
  200. $store_id = $saas_user->store_id;
  201. $is_switch_store = true;
  202. }
  203. }
  204. }
  205. }
  206. }
  207. }
  208. return [
  209. 'is_switch_store' => $is_switch_store,
  210. 'store_id' => $store_id
  211. ];
  212. }
  213. /**
  214. * 平台小程序信息接口
  215. * @return array
  216. */
  217. public static function getPlatformConfig()
  218. {
  219. $store_name = Option::get('name', 0, 'saas')['value'];
  220. // 服务器图片
  221. $form = new StoreImageFrom();
  222. $wxappImg = $form->search();
  223. $config = [
  224. 'images' => $wxappImg,
  225. 'store_name' => $store_name,
  226. 'store' => [
  227. 'name' => $store_name,
  228. 'logo' => Option::get('logo', 0, 'saas')['value']
  229. ],
  230. 'language' => 'zh-CN'
  231. ];
  232. return $config;
  233. }
  234. public static function getNav()
  235. {
  236. $default = [
  237. 'frontColor' => '#000000',
  238. 'backgroundColor' => '#ffffff',
  239. 'bottomBackgroundColor' => '#ffffff',
  240. ];
  241. $navigation_bar_color = Option::get('navigation_bar_color', get_store_id(), 'navbar', Json::encode($default));
  242. $navbar = AppNavbar::getNavbar(get_store_id());
  243. return [
  244. 'navbar' => $navbar,
  245. 'navigation_bar_color' => Json::decode($navigation_bar_color['value'])
  246. ];
  247. }
  248. /**
  249. * 获取商城信息
  250. */
  251. public static function getStore($store_id)
  252. {
  253. $key = [
  254. 'reg' => [
  255. OptionSetting::STORE_MOBILE_VERIFY,
  256. ],
  257. 'pay' => [
  258. OptionSetting::STORE_SEND_TYPE,
  259. ],
  260. 'store' => [
  261. OptionSetting::STORE_NAME,
  262. OptionSetting::STORE_MOBILE_VERIFY,
  263. OptionSetting::STORE_LOGIN_FORCIBLY_BIND_MOBILE,
  264. OptionSetting::STORE_OVER_DAY,
  265. OptionSetting::STORE_DELIVERY_TIME,
  266. OptionSetting::STORE_AFTER_SALE_TIME,
  267. OptionSetting::STORE_SEND_TYPE,
  268. OptionSetting::STORE_INTEGRAL,
  269. OptionSetting::STORE_INTEGRAL_NAME,
  270. OptionSetting::STORE_INTEGRATION,
  271. ],
  272. 'display' => [
  273. OptionSetting::DISPLAY_IS_COMMENT,
  274. OptionSetting::WEB_STORE_SHARE_TITLE,
  275. OptionSetting::WEB_STORE_SHARE_LOG,
  276. OptionSetting::WEB_STORE_SHARE_DESC,
  277. OptionSetting::CLIENT_LOADING_LOGO,
  278. OptionSetting::STORE_CLIENT_PRIVACY_ID,
  279. OptionSetting::STORE_CLIENT_SERVICE_ID,
  280. OptionSetting::INSURANCE_BG_IMG,
  281. OptionSetting::IS_SHOW_CART_LEVEL_PRICE,
  282. ],
  283. 'web' => [
  284. OptionSetting::WEB_LOG,
  285. OptionSetting::WEB_PASSPORT_BG
  286. ],
  287. 'wechat' => [
  288. OptionSetting::WECHAT_IS_SHENHE,
  289. OptionSetting::WECHAT_AUTO_ADDRESS_STATUS,
  290. OptionSetting::WECHAT_IS_OFFICIAL_ACCOUNT,
  291. OptionSetting::WECHAT_ALI_IS_SHENHE
  292. ]
  293. ];
  294. // $data = Option::get($key,$store_id);
  295. $value = [];
  296. foreach ($key as $index => $item) {
  297. foreach ($item as $val) {
  298. if (empty($value[$val])) {
  299. $value[$val] = Option::get($val,$store_id,$index)['value'];
  300. }
  301. if ($val === OptionSetting::STORE_INTEGRAL_NAME && !$value[$val]) {
  302. $value[$val] = "积分";
  303. }
  304. }
  305. }
  306. // $data['quick_navigation'] = (object)array();
  307. $store = Store::findOne($store_id);
  308. if ($store) {
  309. $value['is_alliance'] = $store->is_alliance;
  310. $value['douyin_url'] = $store->douyin_url;
  311. $value['balance'] = $store->balance;
  312. }
  313. if (is_platform()) {
  314. $value['name'] = Option::get('name', 0, 'saas', '')['value'];
  315. $value['web_log'] = Option::get('logo', 0, 'saas', '')['value'];
  316. $value['shenhe'] = Option::get('shenhe', 0, 'saas', 0)['value'];
  317. $value['union_client_loading_logo'] = Option::get('union_client_loading_logo', 0, 'saas', '')['value'];
  318. }
  319. $value['mobile'] = $store->contact_tel;
  320. $value['is_bind_wechat'] = 1;
  321. return $value;
  322. }
  323. }