PublicController.php 34 KB

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