PublicController.php 30 KB

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