PublicController.php 28 KB

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