PublicController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1;
  12. use app\services\activity\combination\StorePinkServices;
  13. use app\services\diy\DiyServices;
  14. use app\services\kefu\service\StoreServiceServices;
  15. use app\services\order\DeliveryServiceServices;
  16. use app\services\other\AgreementServices;
  17. use app\services\other\CacheServices;
  18. use app\services\product\product\StoreCategoryServices;
  19. use app\services\product\product\StoreProductServices;
  20. use app\services\shipping\ExpressServices;
  21. use app\services\shipping\SystemCityServices;
  22. use app\services\system\AppVersionServices;
  23. use app\services\system\attachment\SystemAttachmentServices;
  24. use app\services\system\config\SystemConfigServices;
  25. use app\services\system\lang\LangCodeServices;
  26. use app\services\system\lang\LangCountryServices;
  27. use app\services\system\lang\LangTypeServices;
  28. use app\services\system\store\SystemStoreServices;
  29. use app\services\system\store\SystemStoreStaffServices;
  30. use app\services\user\UserBillServices;
  31. use app\services\user\UserInvoiceServices;
  32. use app\services\user\UserServices;
  33. use app\services\wechat\WechatUserServices;
  34. use app\Request;
  35. use crmeb\services\CacheService;
  36. use app\services\other\UploadService;
  37. use crmeb\services\workerman\ChannelService;
  38. use think\facade\Cache;
  39. /**
  40. * 公共类
  41. * Class PublicController
  42. * @package app\api\controller
  43. */
  44. class PublicController
  45. {
  46. /**
  47. * 主页获取
  48. * @param Request $request
  49. * @return mixed
  50. */
  51. public function index(Request $request)
  52. {
  53. $banner = sys_data('routine_home_banner') ?: [];//TODO 首页banner图
  54. $menus = sys_data('routine_home_menus') ?: [];//TODO 首页按钮
  55. $roll = sys_data('routine_home_roll_news') ?: [];//TODO 首页滚动新闻
  56. $activity = sys_data('routine_home_activity', 3) ?: [];//TODO 首页活动区域图片
  57. $explosive_money = sys_data('index_categy_images') ?: [];//TODO 首页超值爆款
  58. $site_name = sys_config('site_name');
  59. $routine_index_page = sys_data('routine_index_page');
  60. $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';//TODO 快速选择简介
  61. $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';//TODO 精品推荐简介
  62. $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';//TODO 首发新品简介
  63. $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';//TODO 促销单品简介
  64. $logoUrl = sys_config('routine_index_logo');//TODO 促销单品简介
  65. if (strstr($logoUrl, 'http') === false && $logoUrl) {
  66. $logoUrl = sys_config('site_url') . $logoUrl;
  67. }
  68. $logoUrl = str_replace('\\', '/', $logoUrl);
  69. $fastNumber = (int)sys_config('fast_number', 0);//TODO 快速选择分类个数
  70. /** @var StoreCategoryServices $categoryService */
  71. $categoryService = app()->make(StoreCategoryServices::class);
  72. $info['fastList'] = $fastNumber ? $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic') : [];//TODO 快速选择分类个数
  73. /** @var StoreProductServices $storeProductServices */
  74. $storeProductServices = app()->make(StoreProductServices::class);
  75. //获取推荐商品
  76. [$baseList, $firstList, $benefit, $likeInfo, $vipList] = $storeProductServices->getRecommendProductArr((int)$request->uid(), ['is_best', 'is_new', 'is_benefit', 'is_hot']);
  77. $info['bastList'] = $baseList;//TODO 精品推荐个数
  78. $info['firstList'] = $firstList;//TODO 首发新品个数
  79. $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];//TODO 首页精品推荐图片
  80. $lovely = sys_data('routine_home_new_banner') ?: [];//TODO 首发新品顶部图
  81. if ($request->uid()) {
  82. /** @var WechatUserServices $wechatUserService */
  83. $wechatUserService = app()->make(WechatUserServices::class);
  84. $subscribe = (bool)$wechatUserService->value(['uid' => $request->uid()], 'subscribe');
  85. } else {
  86. $subscribe = true;
  87. }
  88. $newGoodsBananr = sys_config('new_goods_bananr');
  89. $tengxun_map_key = sys_config('tengxun_map_key');
  90. return app('json')->success(compact('banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key', 'explosive_money'));
  91. }
  92. /**
  93. * 获取分享配置
  94. * @return mixed
  95. */
  96. public function share()
  97. {
  98. $data['img'] = sys_config('wechat_share_img');
  99. if (strstr($data['img'], 'http') === false) {
  100. $data['img'] = sys_config('site_url') . $data['img'];
  101. }
  102. $data['img'] = str_replace('\\', '/', $data['img']);
  103. $data['title'] = sys_config('wechat_share_title');
  104. $data['synopsis'] = sys_config('wechat_share_synopsis');
  105. return app('json')->success($data);
  106. }
  107. /**
  108. * 获取网站配置
  109. * @return mixed
  110. */
  111. public function getSiteConfig()
  112. {
  113. $data['record_No'] = sys_config('record_No');
  114. return app('json')->success($data);
  115. }
  116. /**
  117. * 获取个人中心菜单
  118. * @param Request $request
  119. * @return mixed
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. * @throws \think\exception\DbException
  123. */
  124. public function menu_user(Request $request)
  125. {
  126. $menusInfo = sys_data('routine_my_menus') ?? [];
  127. $uid = 0;
  128. $userInfo = [];
  129. if ($request->hasMacro('user')) $userInfo = $request->user();
  130. if ($request->hasMacro('uid')) $uid = $request->uid();
  131. $vipOpen = sys_config('member_func_status');
  132. $brokerageFuncStatus = sys_config('brokerage_func_status');
  133. $balanceFuncStatus = sys_config('balance_func_status');
  134. $vipCard = sys_config('member_card_status', 0);
  135. $svipOpen = (bool)sys_config('member_card_status');
  136. $userService = $invoiceStatus = $deliveryUser = $isUserPromoter = $userVerifyStatus = $userOrder = true;
  137. if ($uid && $userInfo) {
  138. /** @var StoreServiceServices $storeService */
  139. $storeService = app()->make(StoreServiceServices::class);
  140. $userService = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1]);
  141. $userOrder = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1, 'customer' => 1]);
  142. /** @var SystemStoreStaffServices $systemStoreStaff */
  143. $systemStoreStaff = app()->make(SystemStoreStaffServices::class);
  144. /** @var UserServices $user */
  145. $user = app()->make(UserServices::class);
  146. /** @var UserInvoiceServices $userInvoice */
  147. $userInvoice = app()->make(UserInvoiceServices::class);
  148. $invoiceStatus = $userInvoice->invoiceFuncStatus(false);
  149. /** @var DeliveryServiceServices $deliveryService */
  150. $deliveryService = app()->make(DeliveryServiceServices::class);
  151. $deliveryUser = $deliveryService->checkoutIsService($uid);
  152. $isUserPromoter = $user->checkUserPromoter($uid, $userInfo);
  153. $userVerifyStatus = $systemStoreStaff->verifyStatus($uid);
  154. }
  155. $auth = [];
  156. $auth['/pages/users/user_vip/index'] = !$vipOpen;
  157. $auth['/pages/users/user_spread_user/index'] = !$brokerageFuncStatus || !$isUserPromoter || $uid == 0;
  158. $auth['/pages/users/user_money/index'] = !$balanceFuncStatus;
  159. $auth['/pages/admin/order/index'] = !$userOrder || $uid == 0;
  160. $auth['/pages/admin/order_cancellation/index'] = (!$userVerifyStatus && !$deliveryUser) || $uid == 0;
  161. $auth['/pages/users/user_invoice_list/index'] = !$invoiceStatus;
  162. $auth['/pages/annex/vip_paid/index'] = !$vipCard || !$svipOpen;
  163. $auth['/kefu/mobile_list'] = !$userService || $uid == 0;
  164. foreach ($menusInfo as $key => &$value) {
  165. if (isset($auth[$value['url']]) && $auth[$value['url']]) {
  166. unset($menusInfo[$key]);
  167. continue;
  168. }
  169. if ($value['url'] == '/kefu/mobile_list') {
  170. $value['url'] = sys_config('site_url') . $value['url'];
  171. if ($request->isRoutine()) {
  172. $value['url'] = str_replace('http://', 'https://', $value['url']);
  173. }
  174. }
  175. }
  176. /** @var SystemConfigServices $systemConfigServices */
  177. $systemConfigServices = app()->make(SystemConfigServices::class);
  178. $bannerInfo = $systemConfigServices->getSpreadBanner() ?? [];
  179. $my_banner = sys_data('routine_my_banner');
  180. $routine_contact_type = sys_config('routine_contact_type', 0);
  181. /** @var DiyServices $diyServices */
  182. $diyServices = app()->make(DiyServices::class);
  183. $diy_data = $diyServices->get(['template_name' => 'member', 'type' => 1], ['value', 'order_status', 'my_banner_status']);
  184. $diy_data = $diy_data ? $diy_data->toArray() : [];
  185. return app('json')->success(['routine_my_menus' => array_merge($menusInfo), 'routine_my_banner' => $my_banner, 'routine_spread_banner' => $bannerInfo, 'routine_contact_type' => $routine_contact_type, 'diy_data' => $diy_data]);
  186. }
  187. /**
  188. * 热门搜索关键字获取
  189. * @return mixed
  190. * @throws \think\db\exception\DataNotFoundException
  191. * @throws \think\db\exception\ModelNotFoundException
  192. * @throws \think\exception\DbException
  193. */
  194. public function search()
  195. {
  196. $routineHotSearch = sys_data('routine_hot_search') ?? [];
  197. $searchKeyword = [];
  198. if (count($routineHotSearch)) {
  199. foreach ($routineHotSearch as $key => &$item) {
  200. array_push($searchKeyword, $item['title']);
  201. }
  202. }
  203. return app('json')->success($searchKeyword);
  204. }
  205. /**
  206. * 图片上传
  207. * @param Request $request
  208. * @return mixed
  209. * @throws \Psr\SimpleCache\InvalidArgumentException
  210. */
  211. public function upload_image(Request $request, SystemAttachmentServices $services)
  212. {
  213. $data = $request->postMore([
  214. ['filename', 'file'],
  215. ]);
  216. if (!$data['filename']) return app('json')->fail(100100);
  217. if (Cache::has('start_uploads_' . $request->uid()) && Cache::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail(100101);
  218. $upload = UploadService::init();
  219. $info = $upload->to('store/comment')->validate()->move($data['filename']);
  220. if ($info === false) {
  221. return app('json')->fail($upload->getError());
  222. }
  223. $res = $upload->getUploadInfo();
  224. $services->attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, (int)sys_config('upload_type', 1), $res['time'], 3);
  225. if (Cache::has('start_uploads_' . $request->uid()))
  226. $start_uploads = (int)Cache::get('start_uploads_' . $request->uid());
  227. else
  228. $start_uploads = 0;
  229. $start_uploads++;
  230. Cache::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
  231. $res['dir'] = path_to_url($res['dir']);
  232. if (strpos($res['dir'], 'http') === false) $res['dir'] = $request->domain() . $res['dir'];
  233. return app('json')->success(100009, ['name' => $res['name'], 'url' => $res['dir']]);
  234. }
  235. /**
  236. * 物流公司
  237. * @return mixed
  238. */
  239. public function logistics(ExpressServices $services)
  240. {
  241. $expressList = $services->expressList();
  242. return app('json')->success($expressList ?? []);
  243. }
  244. /**
  245. * 短信购买异步通知
  246. *
  247. * @param Request $request
  248. * @return mixed
  249. */
  250. public function sms_pay_notify(Request $request)
  251. {
  252. [$order_id, $price, $status, $num, $pay_time, $attach] = $request->postMore([
  253. ['order_id', ''],
  254. ['price', 0.00],
  255. ['status', 400],
  256. ['num', 0],
  257. ['pay_time', time()],
  258. ['attach', 0],
  259. ], true);
  260. if ($status == 200) {
  261. try {
  262. ChannelService::instance()->send('PAY_SMS_SUCCESS', ['price' => $price, 'number' => $num], [$attach]);
  263. } catch (\Throwable $e) {
  264. }
  265. return app('json')->success(100010);
  266. }
  267. return app('json')->fail(100005);
  268. }
  269. /**
  270. * 记录用户分享
  271. * @param Request $request
  272. * @param UserBillServices $services
  273. * @return mixed
  274. */
  275. public function user_share(Request $request, UserBillServices $services)
  276. {
  277. $uid = (int)$request->uid();
  278. $services->setUserShare($uid);
  279. return app('json')->success(100012);
  280. }
  281. /**
  282. * 获取图片base64
  283. * @param Request $request
  284. * @return mixed
  285. */
  286. public function get_image_base64(Request $request)
  287. {
  288. [$imageUrl, $codeUrl] = $request->postMore([
  289. ['image', ''],
  290. ['code', ''],
  291. ], true);
  292. if ($imageUrl !== '' && !preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $imageUrl)) {
  293. return app('json')->success(['code' => false, 'image' => false]);
  294. }
  295. if ($codeUrl !== '' && !(preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $codeUrl) || strpos($codeUrl, 'https://mp.weixin.qq.com/cgi-bin/showqrcode') !== false)) {
  296. return app('json')->success(['code' => false, 'image' => false]);
  297. }
  298. try {
  299. $code = CacheService::remember($codeUrl, function () use ($codeUrl) {
  300. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
  301. if (!$codeTmp) {
  302. $putCodeUrl = put_image($codeUrl);
  303. $code = $putCodeUrl ? image_to_base64(app()->request->domain(true) . '/' . $putCodeUrl) : false;
  304. $code ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putCodeUrl);
  305. }
  306. return $code;
  307. });
  308. $image = CacheService::remember($imageUrl, function () use ($imageUrl) {
  309. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  310. if (!$imageTmp) {
  311. $putImageUrl = put_image($imageUrl);
  312. $image = $putImageUrl ? image_to_base64(app()->request->domain(true) . '/' . $putImageUrl) : false;
  313. $image ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putImageUrl);
  314. }
  315. return $image;
  316. });
  317. return app('json')->success(compact('code', 'image'));
  318. } catch (\Exception $e) {
  319. return app('json')->fail(100005);
  320. }
  321. }
  322. /**
  323. * 门店列表
  324. * @return mixed
  325. */
  326. public function store_list(Request $request, SystemStoreServices $services)
  327. {
  328. list($latitude, $longitude) = $request->getMore([
  329. ['latitude', ''],
  330. ['longitude', ''],
  331. ], true);
  332. $data['list'] = $services->getStoreList(['type' => 0], ['id', 'name', 'phone', 'address', 'detailed_address', 'image', 'latitude', 'longitude'], $latitude, $longitude);
  333. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  334. return app('json')->success($data);
  335. }
  336. /**
  337. * 查找城市数据
  338. * @param Request $request
  339. * @return mixed
  340. */
  341. public function city_list(Request $request)
  342. {
  343. /** @var SystemCityServices $systemCity */
  344. $systemCity = app()->make(SystemCityServices::class);
  345. return app('json')->success($systemCity->cityList());
  346. }
  347. /**
  348. * 获取拼团数据
  349. * @return mixed
  350. */
  351. public function pink(StorePinkServices $pink, UserServices $user)
  352. {
  353. $data['pink_count'] = $pink->getCount(['is_refund' => 0]);
  354. $uids = array_flip($pink->getColumn(['is_refund' => 0], 'uid'));
  355. if (count($uids)) {
  356. $uids = array_rand($uids, count($uids) < 3 ? count($uids) : 3);
  357. }
  358. $data['avatars'] = $uids ? $user->getColumn(is_array($uids) ? [['uid', 'in', $uids]] : ['uid' => $uids], 'avatar') : [];
  359. return app('json')->success($data);
  360. }
  361. /**
  362. * 复制口令接口
  363. * @return mixed
  364. */
  365. public function copy_words()
  366. {
  367. $data['words'] = sys_config('copy_words');
  368. return app('json')->success($data);
  369. }
  370. /**生成口令关键字
  371. * @param Request $request
  372. * @return mixed
  373. * @throws \think\db\exception\DataNotFoundException
  374. * @throws \think\db\exception\DbException
  375. * @throws \think\db\exception\ModelNotFoundException
  376. */
  377. public function copy_share_words(Request $request)
  378. {
  379. list($productId) = $request->getMore([
  380. ['product_id', ''],
  381. ], true);
  382. /** @var StoreProductServices $productService */
  383. $productService = app()->make(StoreProductServices::class);
  384. $keyWords['key_words'] = $productService->getProductWords($productId);
  385. return app('json')->success($keyWords);
  386. }
  387. /**
  388. * 获取页面数据
  389. * @return mixed
  390. * @throws \think\db\exception\DataNotFoundException
  391. * @throws \think\db\exception\DbException
  392. * @throws \think\db\exception\ModelNotFoundException
  393. */
  394. public function getDiy(DiyServices $services, $id = 0)
  395. {
  396. return app('json')->success($services->getDiyInfo((int)$id));
  397. }
  398. /**
  399. * 获取底部导航
  400. * @param DiyServices $services
  401. * @param string $template_name
  402. * @return mixed
  403. */
  404. public function getNavigation(DiyServices $services, string $template_name = '')
  405. {
  406. return app('json')->success($services->getNavigation($template_name));
  407. }
  408. /**
  409. * 首页商品数据
  410. * @param Request $request
  411. */
  412. public function home_products_list(Request $request, DiyServices $services)
  413. {
  414. $data = $request->getMore([
  415. ['priceOrder', ''],
  416. ['newsOrder', ''],
  417. ['salesOrder', ''],
  418. [['type', 'd'], 0],
  419. ['ids', ''],
  420. [['selectId', 'd'], ''],
  421. ['selectType', 0],
  422. ['isType', 0],
  423. ]);
  424. $where = [];
  425. $where['is_show'] = 1;
  426. $where['is_del'] = 0;
  427. $where['productId'] = '';
  428. if ($data['selectType'] == 1) {
  429. if (!$data['ids']) {
  430. return app('json')->success(100011);
  431. }
  432. $where['ids'] = $data['ids'] ? explode(',', $data['ids']) : [];
  433. if ($data['type'] != 2 && $data['type'] != 3 && $data['type'] != 8) {
  434. $where['type'] = 0;
  435. } else {
  436. $where['type'] = $data['type'];
  437. }
  438. } else {
  439. $where['priceOrder'] = $data['priceOrder'];
  440. $where['newsOrder'] = $data['newsOrder'];
  441. $where['salesOrder'] = $data['salesOrder'];
  442. $where['type'] = $data['type'];
  443. if ($data['selectId']) {
  444. /** @var StoreCategoryServices $storeCategoryServices */
  445. $storeCategoryServices = app()->make(StoreCategoryServices::class);
  446. if ($storeCategoryServices->value(['id' => $data['selectId']], 'pid')) {
  447. $where['sid'] = $data['selectId'];
  448. } else {
  449. $where['cid'] = $data['selectId'];
  450. }
  451. }
  452. }
  453. return app('json')->success($services->homeProductList($where, $request->uid()));
  454. }
  455. public function getNewAppVersion($platform)
  456. {
  457. /** @var AppVersionServices $appService */
  458. $appService = app()->make(AppVersionServices::class);
  459. return app('json')->success($appService->getNewInfo($platform));
  460. }
  461. public function getCustomerType()
  462. {
  463. $data = [];
  464. $data['customer_type'] = sys_config('customer_type', 0);
  465. $data['customer_phone'] = sys_config('customer_phone', 0);
  466. $data['customer_url'] = sys_config('customer_url', 0);
  467. $data['customer_corpId'] = sys_config('customer_corpId', 0);
  468. return app('json')->success($data);
  469. }
  470. /**
  471. * 统计代码
  472. * @return array|string
  473. */
  474. public function getScript()
  475. {
  476. return sys_config('statistic_script', '');
  477. }
  478. /**
  479. * 获取workerman请求域名
  480. * @return mixed
  481. */
  482. public function getWorkerManUrl()
  483. {
  484. return app('json')->success(getWorkerManUrl());
  485. }
  486. /**
  487. * 首页开屏广告
  488. * @return mixed
  489. */
  490. public function getOpenAdv()
  491. {
  492. /** @var CacheServices $cache */
  493. $cache = app()->make(CacheServices::class);
  494. $data = $cache->getDbCache('open_adv', '');
  495. return app('json')->success($data);
  496. }
  497. /**
  498. * 获取用户协议内容
  499. * @return mixed
  500. */
  501. public function getUserAgreement()
  502. {
  503. /** @var CacheServices $cache */
  504. $cache = app()->make(CacheServices::class);
  505. $content = $cache->getDbCache('user_agreement', '');
  506. return app('json')->success(compact('content'));
  507. }
  508. /**
  509. * 获取协议
  510. * @param AgreementServices $agreementServices
  511. * @param $type
  512. * @return mixed
  513. * @throws \think\db\exception\DataNotFoundException
  514. * @throws \think\db\exception\DbException
  515. * @throws \think\db\exception\ModelNotFoundException
  516. */
  517. public function getAgreement(AgreementServices $agreementServices, $type)
  518. {
  519. $data = $agreementServices->getAgreementBytype($type);
  520. return app('json')->success($data);
  521. }
  522. /**
  523. * 查询版权信息
  524. * @return mixed
  525. */
  526. public function copyright()
  527. {
  528. $copyrightContext = sys_config('nncnL_crmeb_copyright', '');
  529. $copyrightImage = sys_config('nncnL_crmeb_copyright_image', '');
  530. $siteName = sys_config('site_name', '');
  531. $siteLogo = sys_config('wap_login_logo', '');
  532. return app('json')->success(compact('copyrightContext', 'copyrightImage', 'siteName', 'siteLogo'));
  533. }
  534. /**
  535. * 获取多语言类型列表
  536. * @return mixed
  537. * @throws \think\db\exception\DataNotFoundException
  538. * @throws \think\db\exception\DbException
  539. * @throws \think\db\exception\ModelNotFoundException
  540. */
  541. public function getLangTypeList()
  542. {
  543. /** @var LangTypeServices $langTypeServices */
  544. $langTypeServices = app()->make(LangTypeServices::class);
  545. $list = $langTypeServices->langTypeList(['status' => 1, 'is_del' => 0])['list'];
  546. $data = [];
  547. foreach ($list as $item) {
  548. $data[] = ['name' => $item['language_name'], 'value' => $item['file_name']];
  549. }
  550. return app('json')->success($data);
  551. }
  552. /**
  553. * 获取当前语言json
  554. * @return mixed
  555. * @throws \Throwable
  556. */
  557. public function getLangJson()
  558. {
  559. /** @var LangTypeServices $langTypeServices */
  560. $langTypeServices = app()->make(LangTypeServices::class);
  561. /** @var LangCountryServices $langCountryServices */
  562. $langCountryServices = app()->make(LangCountryServices::class);
  563. $request = app()->request;
  564. //获取接口传入的语言类型
  565. if (!$range = $request->header('cb-lang')) {
  566. //没有传入则使用系统默认语言显示
  567. if (!$range = $langTypeServices->value(['is_default' => 1], 'file_name')) {
  568. //系统没有设置默认语言的话,根据浏览器语言显示,如果浏览器语言在库中找不到,则使用简体中文
  569. if ($request->header('accept-language') !== null) {
  570. $range = explode(',', $request->header('accept-language'))[0];
  571. } else {
  572. $range = 'zh-CN';
  573. }
  574. }
  575. }
  576. // 获取type_id
  577. $typeId = $langCountryServices->value(['code' => $range], 'type_id') ?: 1;
  578. // 获取缓存key
  579. $langData = $langTypeServices->getColumn(['status' => 1, 'is_del' => 0], 'file_name', 'id');
  580. $langStr = 'api_lang_' . str_replace('-', '_', $langData[$typeId]);
  581. //读取当前语言的语言包
  582. $lang = CacheService::remember($langStr, function () use ($typeId, $range) {
  583. /** @var LangCodeServices $langCodeServices */
  584. $langCodeServices = app()->make(LangCodeServices::class);
  585. return $langCodeServices->getColumn(['type_id' => $typeId, 'is_admin' => 0], 'lang_explain', 'code');
  586. }, 3600);
  587. return app('json')->success([$range => $lang]);
  588. }
  589. /**
  590. * 获取当前后台设置的默认语言类型
  591. * @return mixed
  592. */
  593. public function getDefaultLangType()
  594. {
  595. /** @var LangTypeServices $langTypeServices */
  596. $langTypeServices = app()->make(LangTypeServices::class);
  597. $lang_type = $langTypeServices->value(['is_default' => 1], 'file_name');
  598. return app('json')->success(compact('lang_type'));
  599. }
  600. /**
  601. * 获取版本号
  602. * @return mixed
  603. */
  604. public function getVersion()
  605. {
  606. return app('json')->success(['version' => get_crmeb_version()]);
  607. }
  608. }