PublicController.php 31 KB

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