PublicController.php 29 KB

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