BasicInformation.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: dingran
  5. * Date: 2019/2/19
  6. * Time: 上午11:53
  7. */
  8. namespace app\common\middleware;
  9. use app\backend\modules\goods\models\GoodsSetting;
  10. use app\backend\modules\member\models\MemberRelation;
  11. use app\common\events\CommonExtraEvent;
  12. use app\common\facades\Setting;
  13. use app\common\helpers\Cache;
  14. use app\common\helpers\Client;
  15. use app\common\services\popularize\PortType;
  16. use app\common\traits\JsonTrait;
  17. use app\frontend\controllers\HomePageController;
  18. use app\frontend\models\Member;
  19. use app\frontend\modules\finance\controllers\PopularizePageShowController;
  20. use app\frontend\modules\home\services\ShopPublicDataService;
  21. use app\frontend\modules\member\controllers\MemberController;
  22. use app\common\modules\shop\PluginsConfig;
  23. use app\frontend\modules\member\controllers\ServiceController;
  24. use Yunshop\Decorate\models\DecorateFooterModel;
  25. use Yunshop\Decorate\models\DecorateModel;
  26. use Yunshop\Love\Common\Services\SetService;
  27. use Yunshop\NewMemberPrize\frontend\controllers\NewMemberPrizeController;
  28. use app\common\facades\RichText;
  29. class BasicInformation
  30. {
  31. use JsonTrait;
  32. /**
  33. * Handle an incoming request.
  34. *
  35. * @param \Illuminate\Http\Request $request
  36. * @param \Closure $next
  37. * @param string|null $guard
  38. * @return mixed
  39. */
  40. public function handle($request, \Closure $next)
  41. {
  42. $response = $next($request);
  43. if (!$response) {
  44. return $response;
  45. }
  46. $content = $response->getContent();
  47. $response->setContent($this->handleContent($request, $content));
  48. return $response;
  49. }
  50. private function handleContent($request, $content)
  51. {
  52. app('db')->cacheSelect = false;
  53. $content = json_decode($content, true);
  54. if (request()->basic_info == 1) {
  55. $content = array_merge($content, ['basic_info' => $this->getBasicInfo($request, $content)]);
  56. }
  57. if (request()->validate_page == 1) {
  58. $content = array_merge($content, $this->getValidatePage($request));
  59. }
  60. return json_encode($content);
  61. }
  62. private function getBasicInfo($request, $content = [])
  63. {
  64. $consolidated_payment = \Setting::get('shop.trade')['consolidated_payment'];
  65. return [
  66. 'popularize_page' => (new PopularizePageShowController())->index($request, true)['json'],
  67. 'balance' => Setting::get('shop.shop')['credit'] ?: '余额',
  68. 'point' => Setting::get('shop.shop.credit1') ?: '积分',
  69. 'integral' => Setting::get('integral.plugin_name') ?: '消费积分',
  70. 'ecological_point' => Setting::get('plugin.ecological_point.plugin_name') ?: '供销积分',
  71. 'love' => Setting::get('love.name') ?: '爱心值',
  72. 'lang' => $this->getLangSetting(),
  73. 'globalParameter' => $this->globalParameter(),
  74. 'plugin_setting' => PluginsConfig::current()->get(),
  75. 'consolidated_payment' => is_null($consolidated_payment) ? 1 : $consolidated_payment,
  76. 'home' => $this->getPublicData(),
  77. 'thumb_parameter' => $this->getThumbParameter(),
  78. 'upload_max_file_size' => $this->getFileSize(),
  79. 'theme_color' => Setting::get('shop.shop')['theme_color'] ?: '#fe9a51',
  80. 'customer_center' => app('plugins')->isEnabled('customer-center') && Setting::get("plugin.customer-center.is_open"),
  81. ];
  82. }
  83. private function getValidatePage($request)
  84. {
  85. return ['validate_page' => (new MemberController())->isValidatePage($request, true)['json']];
  86. }
  87. private function getFileSize()
  88. {
  89. $file_size = 0;
  90. $file_size_str = ini_get('upload_max_filesize');
  91. if (strexists($file_size_str, 'M')) {
  92. $file_size = strstr($file_size_str, 'M', true) * 1024 * 1024;
  93. }
  94. if (strexists($file_size_str, 'G')) {
  95. $file_size = strstr($file_size_str, 'G', true) * 1024 * 1024 * 1024;
  96. }
  97. if (strexists($file_size_str, 'T')) {
  98. $file_size = strstr($file_size_str, 'T', true) * 1024 * 1024 * 1024 * 1024;
  99. }
  100. return $file_size;
  101. }
  102. private function getPublicData()
  103. {
  104. $uid = \YunShop::app()->getMemberId();
  105. if (!Cache::has("public_setting")) {
  106. //商城设置
  107. $shop_setting = Setting::get('shop.shop');
  108. $member_set = Setting::get('shop.member');
  109. $sms_set = Setting::get('shop.sms');
  110. $goodsSet = GoodsSetting::uniacid()->select('scribing_show')->first();
  111. $mailInfo = [
  112. 'logo' => replace_yunshop(yz_tomedia($shop_setting['logo'])),
  113. 'signimg' => replace_yunshop(yz_tomedia($shop_setting['signimg'])),
  114. 'agent' => MemberRelation::getSetInfo()->value('status') ? true : false,
  115. 'diycode' => html_entity_decode($shop_setting['diycode']),
  116. 'is_bind_mobile' => $member_set['is_bind_mobile'], //是否绑定手机号
  117. 'bind_mobile_page' => $member_set['bind_mobile_page'] ?: [], //指定绑定手机号的页面
  118. 'service_mobile' => Setting::get('shop.contact')['phone'], //商城设置客服电话
  119. 'scribing_show' => $goodsSet['scribing_show'] ? 1 : 0, //原价划线显示
  120. ];
  121. //客服设置
  122. $mailInfo = array_merge($shop_setting, $mailInfo, (new ServiceController())->index());
  123. $setting['mailInfo'] = $mailInfo;
  124. $setting['mobile_login_code'] = $member_set['mobile_login_code'];
  125. $setting['register'] = Setting::get('shop.register');
  126. //增加验证码功能
  127. $setting['captcha_status'] = $sms_set['status'];
  128. $setting['country_code'] = $sms_set['country_code'];
  129. $setting['plugin']['goods_show'] = [];
  130. if (app('plugins')->isEnabled('goods-show')) {
  131. $setting['plugin']['goods_show'] = [
  132. 'goods_group' => Setting::get('plugin.goods_show.goods_group'),
  133. 'around_goods' => Setting::get('plugin.goods_show.around_goods'),
  134. ];
  135. }
  136. if (app('plugins')->isEnabled('love')) {
  137. $setting['love_name'] = SetService::getLoveSet()['name'];//获取爱心值基础设置
  138. }
  139. Cache::put("public_setting", $setting, 3600);
  140. } else {
  141. $setting = Cache::get("public_setting");
  142. }
  143. //强制绑定手机号
  144. $is_bind_mobile = 0;
  145. if ($uid) {
  146. $is_bind_mobile = Member::current()->mobile ? 0 : $setting['mailInfo']['is_bind_mobile'];
  147. $result['memberinfo']['uid'] = Member::current()->uid;
  148. //用户爱心值
  149. if (app('plugins')->isEnabled('love')) {
  150. $love_usable = \Yunshop\Love\Common\Models\MemberLove::select('usable')->where(
  151. 'member_id',
  152. $uid
  153. )->value('usable');
  154. }
  155. $result['memberinfo']['usable'] = empty($love_usable) ? 0 : $love_usable;
  156. }
  157. $setting['mailInfo']['is_bind_mobile'] = (int)$is_bind_mobile;
  158. $result['mailInfo'] = $setting['mailInfo'];
  159. //验证码
  160. if (extension_loaded('fileinfo') && $setting['captcha_status'] == 1) {
  161. $result['captcha'] = app('captcha')->create('default', true);
  162. $result['captcha']['status'] = 1;
  163. }
  164. $result['system']['mobile_login_code'] = $setting['mobile_login_code'] ? 1 : 0;
  165. $result['system']['country_code'] = $setting['country_code'] ? 1 : 0;
  166. //小程序验证推广按钮是否开启
  167. $result['system']['btn_romotion'] = PortType::popularizeShow(request()->type);
  168. //会员注册设置
  169. $result['register_setting'] = $setting['register'];
  170. //商品展示组件
  171. $result['plugin']['goods_show'] = $setting['plugin']['goods_show'];
  172. $result['plugin']['new_member_prize'] = [];
  173. if (app('plugins')->isEnabled('new-member-prize')) {
  174. $result['plugin']['new_member_prize'] = (new NewMemberPrizeController())->index(request()->type);
  175. }
  176. $result['designer']['love_name'] = $setting['love_name'];
  177. $public_data_service = ShopPublicDataService::getInstance();
  178. $item = [
  179. 'ViewSet' => $public_data_service->getViewSet(),
  180. 'is_decorate' => $public_data_service->is_decorate,
  181. ];
  182. $result['item'] = array_merge($item, $public_data_service->getFootMenus());
  183. //会员注册设置
  184. $register_set = Setting::get('shop.register');
  185. $shop = Setting::get('shop.shop');
  186. if ($shop['is_agreement']) {
  187. $register_set['new_agreement'] = RichText::get('shop.agreement');
  188. $register_set['agreement_name'] = $shop['agreement_name'];
  189. }
  190. $result['register_setting'] = $register_set;
  191. return $result;
  192. }
  193. /**
  194. * 获取语言设置
  195. * @return array|mixed
  196. */
  197. private function getLangSetting()
  198. {
  199. $lang = Setting::get('shop.lang.lang');
  200. $data = [
  201. 'test' => [],
  202. 'commission' => [
  203. 'title' => '',
  204. 'commission' => '',
  205. 'agent' => '',
  206. 'level_name' => '',
  207. 'commission_order' => '',
  208. 'commission_amount' => '',
  209. ],
  210. 'single_return' => [
  211. 'title' => '',
  212. 'single_return' => '',
  213. 'return_name' => '',
  214. 'return_queue' => '',
  215. 'return_log' => '',
  216. 'return_detail' => '',
  217. 'return_amount' => '',
  218. ],
  219. 'team_return' => [
  220. 'title' => '',
  221. 'team_return' => '',
  222. 'return_name' => '',
  223. 'team_level' => '',
  224. 'return_log' => '',
  225. 'return_detail' => '',
  226. 'return_amount' => '',
  227. 'return_rate' => '',
  228. 'team_name' => '',
  229. 'return_time' => '',
  230. ],
  231. 'full_return' => [
  232. 'title' => '',
  233. 'full_return' => '',
  234. 'return_name' => '',
  235. 'full_return_log' => '',
  236. 'return_detail' => '',
  237. 'return_amount' => '',
  238. ],
  239. 'team_dividend' => [
  240. 'title' => '',
  241. 'team_dividend' => '',
  242. 'team_agent_centre' => '',
  243. 'dividend' => '',
  244. 'flat_prize' => '',
  245. 'award_gratitude' => '',
  246. 'dividend_amount' => '',
  247. 'my_agent' => '',
  248. ],
  249. 'area_dividend' => [
  250. 'area_dividend_center' => '',
  251. 'area_dividend' => '',
  252. 'dividend_amount' => '',
  253. ],
  254. 'income' => [
  255. 'name_of_withdrawal' => '提现',
  256. 'income_name' => '收入',
  257. 'poundage_name' => '手续费',
  258. 'special_service_tax' => '劳务税',
  259. 'manual_withdrawal' => '手动提现',
  260. ],
  261. 'agent' => [
  262. 'agent' => '',
  263. 'agent_num' => '',
  264. 'agent_count' => '',
  265. 'agent_order' => '',
  266. 'agent_order_count' => '',
  267. 'agent_goods_num' => '',
  268. ],
  269. 'merchant' => [
  270. 'title' => '招商',
  271. 'merchant_people' => '招商员',
  272. 'merchant_center' => '招商中心',
  273. 'merchant_reward' => '分红',
  274. ]
  275. ];
  276. $langData = Setting::get('shop.lang.' . $lang, $data);
  277. if (is_null($langData)) {
  278. $langData = $data;
  279. }
  280. if ($langData['income']['name_of_withdrawal'] == '') {
  281. $langData['income']['name_of_withdrawal'] = '提现';
  282. }
  283. if ($langData['income']['income_name'] == '') {
  284. $langData['income']['income_name'] = '收入';
  285. }
  286. if ($langData['income']['poundage_name'] == '') {
  287. $langData['income']['poundage_name'] = '手续费';
  288. }
  289. if ($langData['income']['special_service_tax'] == '') {
  290. $langData['income']['special_service_tax'] = '劳务税';
  291. }
  292. if ($langData['income']['manual_withdrawal'] == '') {
  293. $langData['income']['manual_withdrawal'] = '手动打款';
  294. }
  295. if (!$langData['appointment']['project']) {
  296. $langData['appointment']['project'] = '项目';
  297. }
  298. if (!$langData['appointment']['service']) {
  299. $langData['appointment']['service'] = '服务';
  300. }
  301. if (!$langData['appointment']['worker']) {
  302. $langData['appointment']['worker'] = '技师';
  303. }
  304. if (!$langData['reserve_simple']['service']) {
  305. $langData['reserve_simple']['service'] = '服务';
  306. }
  307. if (!$langData['reserve_simple']['reserve_obj']) {
  308. $langData['reserve_simple']['reserve_obj'] = '预约人员';
  309. }
  310. if (!$langData['merchant']['title']) {
  311. $langData['merchant']['title'] = '招商';
  312. }
  313. if (!$langData['merchant']['merchant_people']) {
  314. $langData['merchant']['merchant_people'] = '招商员';
  315. }
  316. if (!$langData['merchant']['merchant_center']) {
  317. $langData['merchant']['merchant_center'] = '招商中心';
  318. }
  319. if (!$langData['merchant']['merchant_reward']) {
  320. $langData['merchant']['merchant_reward'] = '分红';
  321. }
  322. if (!$langData['store_projects']['project']) {
  323. $langData['store_projects']['project'] = '项目';
  324. }
  325. if (app('plugins')->isEnabled('micro')) {
  326. $title = Setting::get('plugin.micro');
  327. $langData['micro']['title'] = $title['micro_title'] ?: '微店';
  328. }
  329. $langData['plugin_language'] = \app\common\services\LangService::getCurrentLang();
  330. return $langData;
  331. }
  332. //该接口为全局需要的参数,别给我删了
  333. private function globalParameter()
  334. {
  335. //配送站
  336. if (app('plugins')->isEnabled('delivery-station')) {
  337. $data['is_open_delivery_station'] = Setting::get('plugin.delivery_station.is_open') ? 1 : 0;
  338. } else {
  339. $data['is_open_delivery_station'] = 0;
  340. }
  341. if (app('plugins')->isEnabled('photo-order')) {
  342. $set = Setting::get('plugin.photo-order');
  343. if ($set['is_open'] == 1) {
  344. $data['is_open_photo_order'] = 1;
  345. $data['photo_order_min_pohot'] = $set['min_pohot'];
  346. $data['photo_order_max_pohot'] = $set['max_pohot'];
  347. } else {
  348. $data['is_open_photo_order'] = 0;
  349. }
  350. } else {
  351. $data['is_open_photo_order'] = 0;
  352. }
  353. //会员订单配送方式为司机配送(7), 参数会在会员中心订单列表、供应商前端订单、门店前端订单用到
  354. $data['delivery_driver_open'] = \app\common\services\plugin\DeliveryDriverSet::whetherEnabled();
  355. // 自提点
  356. if (app('plugins')->isEnabled('package-deliver')) {
  357. $set = Setting::get('plugin.package_deliver');
  358. $data['is_open_package_deliver'] = $set['is_package'];
  359. }
  360. // 广告市场
  361. if (app('plugins')->isEnabled('advert-market') && app('plugins')->isEnabled('store-cashier')) {
  362. $set = Setting::get('plugin.advert-market');
  363. $data['is_open_advert_market'] = $set['is_open'];
  364. }
  365. $data['assemble_name'] = '安装服务';
  366. $data['assemble_worker_name'] = '安装师傅';
  367. if (app('plugins')->isEnabled('assemble')) {
  368. $data['assemble_name'] = Setting::get('plugin.assemble.assemble_name') ?: '安装服务';
  369. $data['assemble_worker_name'] = Setting::get('plugin.assemble.assemble_worker_name') ?: '安装师傅';
  370. }
  371. if (app('plugins')->isEnabled('consume-red-packet')) {
  372. $data['consume_red_packet_status'] = 1;
  373. } else {
  374. $data['consume_red_packet_status'] = 0;
  375. }
  376. if (app('plugins')->isEnabled('shop-esign')) {
  377. $data['is_open_shop_esign'] = 1;
  378. } else {
  379. $data['is_open_shop_esign'] = 0;
  380. }
  381. $data['is_open_shop_esign_v2'] = 0;
  382. if (app('plugins')->isEnabled('shop-esign-v2')) {
  383. $data['is_open_shop_esign_v2'] = 1;
  384. }
  385. //汇聚支付
  386. if (app('plugins')->isEnabled('converge_pay') && Setting::get('plugin.convergePay_set.wechat') == true) {
  387. $data['initial_id'] = Setting::get('plugin.convergePay_set.wechat.initial_id');//初始id
  388. }
  389. $ios_virtual_pay = 0;
  390. if (Client::osType() == 1 && Setting::get('shop.pay.ios_virtual_pay') == 1) {
  391. $ios_virtual_pay = 1;
  392. }
  393. $data['ios_virtual_pay'] = $ios_virtual_pay;
  394. //注册,下单定位
  395. $data['order_locate'] = false;
  396. $data['register_locate'] = false;
  397. $data['bind_mobile_locate'] = false;
  398. //会员价
  399. $data['vip_show'] = Setting::get('shop.member')['vip_price'] == 1 ? true : false;
  400. if (app('plugins')->isEnabled('registration_area')) {
  401. $area_set = array_pluck(Setting::getAllByGroup('registration-area')->toArray(), 'value', 'key');
  402. if ($area_set['is_open'] == 1) {
  403. $data['order_locate'] = true;
  404. $data['register_locate'] = true;
  405. $data['bind_mobile_locate'] = true;
  406. }
  407. }
  408. //招商专员插件是否开启 true 开启 false 关闭
  409. if (app('plugins')->isEnabled('invest-people')) {
  410. $data['invest_people_name'] = \Yunshop\InvestPeople\services\InvestMemberView::pluginName();
  411. $data['invest_people_open'] = !Setting::get('plugin.invest_people')['open'];
  412. } else {
  413. $data['invest_people_open'] = false;
  414. }
  415. $data['cart_num'] = \app\frontend\models\MemberCart::getCartNum(\YunShop::app()->getMemberId());
  416. //益生系统
  417. if (app('plugins')->isEnabled('ys-system')) {
  418. $data['crm_account_bind'] = \Yunshop\YsSystem\common\AccountBindState::open(\YunShop::app()->getMemberId());
  419. } else {
  420. $data['crm_account_bind'] = 0;
  421. }
  422. //会员团队
  423. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('team_judge')) && \YunShop::app()->getMemberId(
  424. )) {
  425. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('team_judge'), 'class');
  426. $function = array_get(\app\common\modules\shop\ShopConfig::current()->get('team_judge'), 'function');
  427. $member_team = $class::$function(\YunShop::app()->getMemberId());
  428. if ($member_team['res']) {
  429. $data['member_team'] = $member_team['notice'];
  430. }
  431. }
  432. //默认地址
  433. if (!is_null(\app\common\modules\shop\ShopConfig::current()->get('default_address_judge'))) {
  434. $class = array_get(\app\common\modules\shop\ShopConfig::current()->get('default_address_judge'), 'class');
  435. $function = array_get(
  436. \app\common\modules\shop\ShopConfig::current()->get('default_address_judge'),
  437. 'function'
  438. );
  439. $default_address_judge = $class::$function();
  440. if ($default_address_judge['hide_address']) {
  441. $data['hide_address'] = true;
  442. }
  443. if ($default_address_judge['hide_dispatch']) {
  444. $data['hide_dispatch'] = true;
  445. }
  446. }
  447. $data['hide_total_sales'] = Setting::get('goods.hide_goods_sales') ? 1 : 0;
  448. return $data;
  449. }
  450. private function getThumbParameter()
  451. {
  452. return '';
  453. if (config('app.framework') == 'platform') {
  454. $systemSetting = app('SystemSetting');
  455. if ($remote = $systemSetting->get('remote')) {
  456. $setting[$remote['key']] = unserialize($remote['value']);
  457. }
  458. $upload_type = $setting['remote']['type'];
  459. } else {
  460. global $_W;
  461. //公众号独立配置信息 优先使用公众号独立配置
  462. $uni_setting = app('WqUniSetting')->get()->toArray();
  463. if (!empty($uni_setting['remote']) && iunserializer($uni_setting['remote'])['type'] != 0) {
  464. $setting['remote'] = iunserializer($uni_setting['remote']);
  465. $upload_type = $setting['remote']['type'];
  466. } else {
  467. $setting = $_W['setting'];
  468. $upload_type = $setting['remote']['type'];
  469. }
  470. }
  471. switch ($upload_type) {
  472. case 2:
  473. $parameter = '?x-oss-process=image/resize,mfit,h_350,w_350';
  474. break;
  475. case 4:
  476. $parameter = '?imageView2/2/w/350/h/350';
  477. break;
  478. default:
  479. $parameter = '';
  480. }
  481. return $parameter;
  482. }
  483. }