PublicController.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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) {
  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($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($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. $code ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putCodeUrl);
  307. }
  308. return $code;
  309. });
  310. $image = CacheService::remember($imageUrl, function () use ($imageUrl) {
  311. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  312. if (!$imageTmp) {
  313. $putImageUrl = put_image($imageUrl);
  314. $image = $putImageUrl ? image_to_base64(app()->request->domain(true) . '/' . $putImageUrl) : false;
  315. $image ?? unlink($_SERVER["DOCUMENT_ROOT"] . '/' . $putImageUrl);
  316. }
  317. return $image;
  318. });
  319. return app('json')->success(compact('code', 'image'));
  320. } catch (\Exception $e) {
  321. return app('json')->fail(100005);
  322. }
  323. }
  324. /**
  325. * 门店列表
  326. * @return mixed
  327. */
  328. public function store_list(Request $request, SystemStoreServices $services)
  329. {
  330. list($latitude, $longitude) = $request->getMore([
  331. ['latitude', ''],
  332. ['longitude', ''],
  333. ], true);
  334. $data['list'] = $services->getStoreList(['type' => 0], ['id', 'name', 'phone', 'address', 'detailed_address', 'image', 'latitude', 'longitude'], $latitude, $longitude);
  335. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  336. return app('json')->success($data);
  337. }
  338. /**
  339. * 查找城市数据
  340. * @param Request $request
  341. * @return mixed
  342. */
  343. public function city_list(Request $request)
  344. {
  345. /** @var SystemCityServices $systemCity */
  346. $systemCity = app()->make(SystemCityServices::class);
  347. return app('json')->success($systemCity->cityList());
  348. }
  349. /**
  350. * 获取拼团数据
  351. * @return mixed
  352. */
  353. public function pink(StorePinkServices $pink, UserServices $user)
  354. {
  355. $data['pink_count'] = $pink->getCount(['is_refund' => 0]);
  356. $uids = array_flip($pink->getColumn(['is_refund' => 0], 'uid'));
  357. if (count($uids)) {
  358. $uids = array_rand($uids, count($uids) < 3 ? count($uids) : 3);
  359. }
  360. $data['avatars'] = $uids ? $user->getColumn(is_array($uids) ? [['uid', 'in', $uids]] : ['uid' => $uids], 'avatar') : [];
  361. return app('json')->success($data);
  362. }
  363. /**
  364. * 复制口令接口
  365. * @return mixed
  366. */
  367. public function copy_words()
  368. {
  369. $data['words'] = sys_config('copy_words');
  370. return app('json')->success($data);
  371. }
  372. /**生成口令关键字
  373. * @param Request $request
  374. * @return mixed
  375. * @throws \think\db\exception\DataNotFoundException
  376. * @throws \think\db\exception\DbException
  377. * @throws \think\db\exception\ModelNotFoundException
  378. */
  379. public function copy_share_words(Request $request)
  380. {
  381. list($productId) = $request->getMore([
  382. ['product_id', ''],
  383. ], true);
  384. /** @var StoreProductServices $productService */
  385. $productService = app()->make(StoreProductServices::class);
  386. $keyWords['key_words'] = $productService->getProductWords($productId);
  387. return app('json')->success($keyWords);
  388. }
  389. /**
  390. * 获取页面数据
  391. * @return mixed
  392. * @throws \think\db\exception\DataNotFoundException
  393. * @throws \think\db\exception\DbException
  394. * @throws \think\db\exception\ModelNotFoundException
  395. */
  396. public function getDiy(DiyServices $services, $id = 0)
  397. {
  398. return app('json')->success($services->getDiyInfo((int)$id));
  399. }
  400. /**
  401. * 获取底部导航
  402. * @param DiyServices $services
  403. * @param string $template_name
  404. * @return mixed
  405. */
  406. public function getNavigation(DiyServices $services, string $template_name = '')
  407. {
  408. return app('json')->success($services->getNavigation($template_name));
  409. }
  410. /**
  411. * 首页商品数据
  412. * @param Request $request
  413. */
  414. public function home_products_list(Request $request, DiyServices $services)
  415. {
  416. $data = $request->getMore([
  417. ['priceOrder', ''],
  418. ['newsOrder', ''],
  419. ['salesOrder', ''],
  420. [['type', 'd'], 0],
  421. ['ids', ''],
  422. [['selectId', 'd'], ''],
  423. ['selectType', 0],
  424. ['isType', 0],
  425. ]);
  426. $where = [];
  427. $where['is_show'] = 1;
  428. $where['is_del'] = 0;
  429. $where['productId'] = '';
  430. if ($data['selectType'] == 1) {
  431. if (!$data['ids']) {
  432. return app('json')->success(100011);
  433. }
  434. $where['ids'] = $data['ids'] ? explode(',', $data['ids']) : [];
  435. if ($data['type'] != 2 && $data['type'] != 3 && $data['type'] != 8) {
  436. $where['type'] = 0;
  437. } else {
  438. $where['type'] = $data['type'];
  439. }
  440. } else {
  441. $where['priceOrder'] = $data['priceOrder'];
  442. $where['newsOrder'] = $data['newsOrder'];
  443. $where['salesOrder'] = $data['salesOrder'];
  444. $where['type'] = $data['type'];
  445. if ($data['selectId']) {
  446. /** @var StoreCategoryServices $storeCategoryServices */
  447. $storeCategoryServices = app()->make(StoreCategoryServices::class);
  448. if ($storeCategoryServices->value(['id' => $data['selectId']], 'pid')) {
  449. $where['sid'] = $data['selectId'];
  450. } else {
  451. $where['cid'] = $data['selectId'];
  452. }
  453. }
  454. }
  455. return app('json')->success($services->homeProductList($where, $request->uid()));
  456. }
  457. public function getNewAppVersion($platform)
  458. {
  459. /** @var AppVersionServices $appService */
  460. $appService = app()->make(AppVersionServices::class);
  461. return app('json')->success($appService->getNewInfo($platform));
  462. }
  463. public function getCustomerType()
  464. {
  465. $data = [];
  466. $data['customer_type'] = sys_config('customer_type', 0);
  467. $data['customer_phone'] = sys_config('customer_phone', 0);
  468. $data['customer_url'] = sys_config('customer_url', 0);
  469. $data['customer_corpId'] = sys_config('customer_corpId', 0);
  470. return app('json')->success($data);
  471. }
  472. /**
  473. * 统计代码
  474. * @return array|string
  475. */
  476. public function getScript()
  477. {
  478. return sys_config('statistic_script', '');
  479. }
  480. /**
  481. * 获取workerman请求域名
  482. * @return mixed
  483. */
  484. public function getWorkerManUrl()
  485. {
  486. return app('json')->success(getWorkerManUrl());
  487. }
  488. /**
  489. * 首页开屏广告
  490. * @return mixed
  491. */
  492. public function getOpenAdv()
  493. {
  494. /** @var CacheServices $cache */
  495. $cache = app()->make(CacheServices::class);
  496. $data = $cache->getDbCache('open_adv', '');
  497. return app('json')->success($data);
  498. }
  499. /**
  500. * 获取用户协议内容
  501. * @return mixed
  502. */
  503. public function getUserAgreement()
  504. {
  505. /** @var CacheServices $cache */
  506. $cache = app()->make(CacheServices::class);
  507. $content = $cache->getDbCache('user_agreement', '');
  508. return app('json')->success(compact('content'));
  509. }
  510. /**
  511. * 获取协议
  512. * @param AgreementServices $agreementServices
  513. * @param $type
  514. * @return mixed
  515. * @throws \think\db\exception\DataNotFoundException
  516. * @throws \think\db\exception\DbException
  517. * @throws \think\db\exception\ModelNotFoundException
  518. */
  519. public function getAgreement(AgreementServices $agreementServices, $type)
  520. {
  521. $data = $agreementServices->getAgreementBytype($type);
  522. return app('json')->success($data);
  523. }
  524. /**
  525. * 查询版权信息
  526. * @return mixed
  527. */
  528. public function copyright()
  529. {
  530. $copyrightContext = sys_config('nncnL_crmeb_copyright', '');
  531. $copyrightImage = sys_config('nncnL_crmeb_copyright_image', '');
  532. $siteName = sys_config('site_name', '');
  533. $siteLogo = sys_config('wap_login_logo', '');
  534. return app('json')->success(compact('copyrightContext', 'copyrightImage', 'siteName', 'siteLogo'));
  535. }
  536. /**
  537. * 获取多语言类型列表
  538. * @return mixed
  539. * @throws \think\db\exception\DataNotFoundException
  540. * @throws \think\db\exception\DbException
  541. * @throws \think\db\exception\ModelNotFoundException
  542. */
  543. public function getLangTypeList()
  544. {
  545. /** @var LangTypeServices $langTypeServices */
  546. $langTypeServices = app()->make(LangTypeServices::class);
  547. $list = $langTypeServices->langTypeList(['status' => 1, 'is_del' => 0])['list'];
  548. $data = [];
  549. foreach ($list as $item) {
  550. $data[] = ['name' => $item['language_name'], 'value' => $item['file_name']];
  551. }
  552. return app('json')->success($data);
  553. }
  554. /**
  555. * 获取当前语言json
  556. * @return mixed
  557. * @throws \Throwable
  558. */
  559. public function getLangJson()
  560. {
  561. /** @var LangTypeServices $langTypeServices */
  562. $langTypeServices = app()->make(LangTypeServices::class);
  563. /** @var LangCountryServices $langCountryServices */
  564. $langCountryServices = app()->make(LangCountryServices::class);
  565. $request = app()->request;
  566. //获取接口传入的语言类型
  567. if (!$range = $request->header('cb-lang')) {
  568. //没有传入则使用系统默认语言显示
  569. if (!$range = $langTypeServices->value(['is_default' => 1], 'file_name')) {
  570. //系统没有设置默认语言的话,根据浏览器语言显示,如果浏览器语言在库中找不到,则使用简体中文
  571. if ($request->header('accept-language') !== null) {
  572. $range = explode(',', $request->header('accept-language'))[0];
  573. } else {
  574. $range = 'zh-CN';
  575. }
  576. }
  577. }
  578. // 获取type_id
  579. $typeId = $langCountryServices->value(['code' => $range], 'type_id') ?: 1;
  580. // 获取缓存key
  581. $langData = $langTypeServices->getColumn(['status' => 1, 'is_del' => 0], 'file_name', 'id');
  582. $langStr = 'api_lang_' . str_replace('-', '_', $langData[$typeId]);
  583. //读取当前语言的语言包
  584. $lang = CacheService::remember($langStr, function () use ($typeId, $range) {
  585. /** @var LangCodeServices $langCodeServices */
  586. $langCodeServices = app()->make(LangCodeServices::class);
  587. return $langCodeServices->getColumn(['type_id' => $typeId, 'is_admin' => 0], 'lang_explain', 'code');
  588. }, 3600);
  589. return app('json')->success([$range => $lang]);
  590. }
  591. /**
  592. * 获取当前后台设置的默认语言类型
  593. * @return mixed
  594. */
  595. public function getDefaultLangType()
  596. {
  597. /** @var LangTypeServices $langTypeServices */
  598. $langTypeServices = app()->make(LangTypeServices::class);
  599. $lang_type = $langTypeServices->value(['is_default' => 1], 'file_name');
  600. return app('json')->success(compact('lang_type'));
  601. }
  602. /**
  603. * 获取版本号
  604. * @return mixed
  605. */
  606. public function getVersion()
  607. {
  608. $version = parse_ini_file(app()->getRootPath() . '.version');
  609. return app('json')->success(['version' => $version['version'], 'version_code' => $version['version_code']]);
  610. }
  611. /**
  612. * 获取多语言缓存
  613. * @return \think\Response
  614. * @author 吴汐
  615. * @email 442384644@qq.com
  616. * @date 2023/03/06
  617. */
  618. public function getLangVersion()
  619. {
  620. return app('json')->success(app()->make(LangCodeServices::class)->getLangVersion());
  621. }
  622. /**
  623. * 商城基础配置汇总接口
  624. * @return \think\Response
  625. * @author 吴汐
  626. * @email 442384644@qq.com
  627. * @date 2023/04/03
  628. */
  629. public function getMallBasicConfig()
  630. {
  631. $data['site_name'] = sys_config('site_name');//网站名称
  632. $data['site_url'] = sys_config('site_url');//网站地址
  633. $data['wap_login_logo'] = sys_config('wap_login_logo');//移动端登录logo
  634. $data['record_No'] = sys_config('record_No');//备案号
  635. $data['network_security'] = sys_config('network_security');//网安备案
  636. $data['store_self_mention'] = sys_config('store_self_mention');//是否开启到店自提
  637. $data['invoice_func_status'] = sys_config('invoice_func_status');//发票功能启用
  638. $data['special_invoice_status'] = sys_config('special_invoice_status');//专用发票启用
  639. $data['member_func_status'] = sys_config('member_func_status');//用户等级启用
  640. $data['balance_func_status'] = sys_config('balance_func_status');//余额功能启用
  641. $data['recharge_switch'] = sys_config('recharge_switch');//小程序充值开关
  642. $data['member_card_status'] = sys_config('member_card_status');//是否开启付费会员
  643. $data['member_price_status'] = sys_config('member_price_status');//商品会员折扣价展示启用
  644. $data['ali_pay_status'] = sys_config('ali_pay_status') != '0';//支付宝是否启用
  645. $data['pay_weixin_open'] = sys_config('pay_weixin_open') != '0';//微信是否启用
  646. $data['yue_pay_status'] = sys_config('yue_pay_status') == 1 && sys_config('balance_func_status') != 0;//余额是否启用
  647. $data['offline_pay_status'] = sys_config('offline_pay_status') == 1;//线下是否启用
  648. $data['friend_pay_status'] = sys_config('friend_pay_status') == 1;//好友是否启用
  649. $data['wechat_auth_switch'] = (int)in_array(1, sys_config('routine_auth_type'));//微信登录开关
  650. $data['phone_auth_switch'] = (int)in_array(2, sys_config('routine_auth_type'));//手机号登录开关
  651. $data['wechat_status'] = sys_config('wechat_appid') != '' && sys_config('wechat_appsecret') != '';//公众号是否配置
  652. return app('json')->success($data);
  653. }
  654. }