PublicController.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  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. @file_put_contents('quanju.txt', $codeUrl."-传参codeUrl\r\n", 8);
  308. /** @var SystemStorageServices $systemStorageServices */
  309. $systemStorageServices = app()->make(SystemStorageServices::class);
  310. $domainArr = $systemStorageServices->getColumn([], 'domain');
  311. $domainArr = array_merge($domainArr, [$request->host()]);
  312. $domainArr = array_unique(array_diff($domainArr, ['']));
  313. if (count($domainArr)) {
  314. $domainArr = array_map(function ($item) {
  315. return str_replace(['https://', 'http://'], '', $item);
  316. }, $domainArr);
  317. }
  318. $domainArr[] = 'mp.weixin.qq.com';
  319. $imageUrlHost = $imageUrl ? (parse_url($imageUrl)['host'] ?? $imageUrl) : $imageUrl;
  320. $codeUrlHost = $codeUrl ? (parse_url($codeUrl)['host'] ?? $codeUrl) : $codeUrl;
  321. if ($domainArr && (($imageUrl && !in_array($imageUrlHost, $domainArr)) || ($codeUrl && !in_array($codeUrlHost, $domainArr)))) {
  322. return app('json')->success(['code' => false, 'image' => false]);
  323. }
  324. if ($imageUrl !== '' && !preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $imageUrl) && strpos(strtolower($imageUrl), "phar://") !== false) {
  325. return app('json')->success(['code' => false, 'image' => false]);
  326. }
  327. @file_put_contents('quanju.txt', $imageUrl."-imageUrl\r\n", 8);
  328. 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) {
  329. return app('json')->success(['code' => false, 'image' => false]);
  330. }
  331. @file_put_contents('quanju.txt', $codeUrl."-codeUrl\r\n", 8);
  332. try {
  333. $code = CacheService::remember($codeUrl, function () use ($codeUrl) {
  334. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
  335. if (!$codeTmp) {
  336. $putCodeUrl = put_image($codeUrl);
  337. //TODO
  338. $code = $putCodeUrl ? image_to_base64(app()->request->domain(true) . '/' . $putCodeUrl) : false;
  339. if ($putCodeUrl) {
  340. unlink($_SERVER["DOCUMENT_ROOT"] . DS . $putCodeUrl);
  341. }
  342. }
  343. return $code;
  344. });
  345. $image = CacheService::remember($imageUrl, function () use ($imageUrl) {
  346. @file_put_contents('quanju.txt', $imageUrl."-前imageUrl\r\n", 8);
  347. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  348. @file_put_contents('quanju.txt', $imageTmp."-后imageTmp\r\n", 8);
  349. if (!$imageTmp) {
  350. $putImageUrl = put_image($imageUrl);
  351. //TODO
  352. $image = $putImageUrl ? image_to_base64(app()->request->domain(true) . '/' . $putImageUrl) : false;
  353. if ($putImageUrl) {
  354. unlink($_SERVER["DOCUMENT_ROOT"] . DS . $putImageUrl);
  355. }
  356. }
  357. return $image;
  358. });
  359. return app('json')->success(compact('code', 'image'));
  360. } catch (\Exception $e) {
  361. return app('json')->fail(100005);
  362. }
  363. }
  364. /**
  365. * 门店列表
  366. * @return mixed
  367. */
  368. public function store_list(Request $request, SystemStoreServices $services)
  369. {
  370. list($latitude, $longitude) = $request->getMore([
  371. ['latitude', ''],
  372. ['longitude', ''],
  373. ], true);
  374. $data['list'] = $services->getStoreList(['type' => 0], ['id', 'name', 'phone', 'address', 'detailed_address', 'image', 'latitude', 'longitude'], $latitude, $longitude);
  375. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  376. return app('json')->success($data);
  377. }
  378. /**
  379. * 查找城市数据
  380. * @param Request $request
  381. * @return mixed
  382. */
  383. public function city_list(Request $request)
  384. {
  385. /** @var SystemCityServices $systemCity */
  386. $systemCity = app()->make(SystemCityServices::class);
  387. return app('json')->success($systemCity->cityList());
  388. }
  389. /**
  390. * 获取拼团数据
  391. * @return mixed
  392. */
  393. public function pink(StorePinkServices $pink, UserServices $user)
  394. {
  395. $data['pink_count'] = $pink->getCount(['is_refund' => 0]);
  396. $uids = array_flip($pink->getColumn(['is_refund' => 0], 'uid'));
  397. if (count($uids)) {
  398. $uids = array_rand($uids, count($uids) < 3 ? count($uids) : 3);
  399. }
  400. $data['avatars'] = $uids ? $user->getColumn(is_array($uids) ? [['uid', 'in', $uids]] : ['uid' => $uids], 'avatar') : [];
  401. foreach ($data['avatars'] as &$avatar) {
  402. if (strpos($avatar, '/statics/system_images/') !== false) {
  403. $avatar = set_file_url($avatar);
  404. }
  405. }
  406. return app('json')->success($data);
  407. }
  408. /**
  409. * 复制口令接口
  410. * @return mixed
  411. */
  412. public function copy_words()
  413. {
  414. $data['words'] = sys_config('copy_words');
  415. return app('json')->success($data);
  416. }
  417. /**生成口令关键字
  418. * @param Request $request
  419. * @return mixed
  420. * @throws \think\db\exception\DataNotFoundException
  421. * @throws \think\db\exception\DbException
  422. * @throws \think\db\exception\ModelNotFoundException
  423. */
  424. public function copy_share_words(Request $request)
  425. {
  426. list($productId) = $request->getMore([
  427. ['product_id', ''],
  428. ], true);
  429. /** @var StoreProductServices $productService */
  430. $productService = app()->make(StoreProductServices::class);
  431. $keyWords['key_words'] = $productService->getProductWords($productId);
  432. return app('json')->success($keyWords);
  433. }
  434. /**
  435. * 获取页面数据
  436. * @return mixed
  437. * @throws \think\db\exception\DataNotFoundException
  438. * @throws \think\db\exception\DbException
  439. * @throws \think\db\exception\ModelNotFoundException
  440. */
  441. public function getDiy(DiyServices $services, $id = 0)
  442. {
  443. return app('json')->success($services->getDiyInfo((int)$id));
  444. }
  445. /**
  446. * 获取底部导航
  447. * @param DiyServices $services
  448. * @param string $template_name
  449. * @return mixed
  450. */
  451. public function getNavigation(DiyServices $services, string $template_name = '')
  452. {
  453. return app('json')->success($services->getNavigation($template_name));
  454. }
  455. /**
  456. * 首页商品数据
  457. * @param Request $request
  458. */
  459. public function home_products_list(Request $request, DiyServices $services)
  460. {
  461. $data = $request->getMore([
  462. ['priceOrder', ''],
  463. ['newsOrder', ''],
  464. ['salesOrder', ''],
  465. [['type', 'd'], 0],
  466. ['ids', ''],
  467. [['selectId', 'd'], ''],
  468. ['selectType', 0],
  469. ['isType', 0],
  470. ]);
  471. $where = [];
  472. $where['is_show'] = 1;
  473. $where['is_del'] = 0;
  474. $where['productId'] = '';
  475. if ($data['selectType'] == 1) {
  476. if (!$data['ids']) {
  477. return app('json')->success(100011);
  478. }
  479. $where['ids'] = $data['ids'] ? explode(',', $data['ids']) : [];
  480. if ($data['type'] != 2 && $data['type'] != 3 && $data['type'] != 8) {
  481. $where['type'] = 0;
  482. } else {
  483. $where['type'] = $data['type'];
  484. }
  485. } else {
  486. $where['priceOrder'] = $data['priceOrder'];
  487. $where['newsOrder'] = $data['newsOrder'];
  488. $where['salesOrder'] = $data['salesOrder'];
  489. $where['type'] = $data['type'];
  490. if ($data['selectId']) {
  491. /** @var StoreCategoryServices $storeCategoryServices */
  492. $storeCategoryServices = app()->make(StoreCategoryServices::class);
  493. if ($storeCategoryServices->value(['id' => $data['selectId']], 'pid')) {
  494. $where['sid'] = $data['selectId'];
  495. } else {
  496. $where['cid'] = $data['selectId'];
  497. }
  498. }
  499. }
  500. return app('json')->success($services->homeProductList($where, $request->uid()));
  501. }
  502. public function getNewAppVersion($platform)
  503. {
  504. /** @var AppVersionServices $appService */
  505. $appService = app()->make(AppVersionServices::class);
  506. return app('json')->success($appService->getNewInfo($platform));
  507. }
  508. public function getCustomerType()
  509. {
  510. $data = [];
  511. $data['customer_type'] = sys_config('customer_type', 0);
  512. $data['customer_phone'] = sys_config('customer_phone', 0);
  513. $data['customer_url'] = sys_config('customer_url', 0);
  514. $data['customer_corpId'] = sys_config('customer_corpId', 0);
  515. return app('json')->success($data);
  516. }
  517. /**
  518. * 统计代码
  519. * @return array|string
  520. */
  521. public function getScript()
  522. {
  523. return sys_config('statistic_script', '');
  524. }
  525. public function customPcJs()
  526. {
  527. return sys_config('custom_pc_js', '');
  528. }
  529. /**
  530. * 获取workerman请求域名
  531. * @return mixed
  532. */
  533. public function getWorkerManUrl()
  534. {
  535. return app('json')->success(getWorkerManUrl());
  536. }
  537. /**
  538. * 首页开屏广告
  539. * @return mixed
  540. */
  541. public function getOpenAdv()
  542. {
  543. /** @var CacheServices $cache */
  544. $cache = app()->make(CacheServices::class);
  545. $data = $cache->getDbCache('open_adv', '');
  546. return app('json')->success($data);
  547. }
  548. /**
  549. * 获取用户协议内容
  550. * @return mixed
  551. */
  552. public function getUserAgreement()
  553. {
  554. /** @var CacheServices $cache */
  555. $cache = app()->make(CacheServices::class);
  556. $content = $cache->getDbCache('user_agreement', '');
  557. return app('json')->success(compact('content'));
  558. }
  559. /**
  560. * 获取协议
  561. * @param AgreementServices $agreementServices
  562. * @param $type
  563. * @return mixed
  564. * @throws \think\db\exception\DataNotFoundException
  565. * @throws \think\db\exception\DbException
  566. * @throws \think\db\exception\ModelNotFoundException
  567. */
  568. public function getAgreement(AgreementServices $agreementServices, $type)
  569. {
  570. $data = $agreementServices->getAgreementBytype($type);
  571. return app('json')->success($data);
  572. }
  573. /**
  574. * 查询版权信息
  575. * @return mixed
  576. */
  577. public function copyright()
  578. {
  579. $copyrightContext = sys_config('nncnL_crmeb_copyright', '');
  580. $copyrightImage = sys_config('nncnL_crmeb_copyright_image', '');
  581. $siteName = sys_config('site_name', '');
  582. $siteLogo = sys_config('wap_login_logo', '');
  583. return app('json')->success(compact('copyrightContext', 'copyrightImage', 'siteName', 'siteLogo'));
  584. }
  585. /**
  586. * 获取多语言类型列表
  587. * @return mixed
  588. * @throws \think\db\exception\DataNotFoundException
  589. * @throws \think\db\exception\DbException
  590. * @throws \think\db\exception\ModelNotFoundException
  591. */
  592. public function getLangTypeList()
  593. {
  594. /** @var LangTypeServices $langTypeServices */
  595. $langTypeServices = app()->make(LangTypeServices::class);
  596. $list = $langTypeServices->langTypeList(['status' => 1, 'is_del' => 0])['list'];
  597. $data = [];
  598. foreach ($list as $item) {
  599. $data[] = ['name' => $item['language_name'], 'value' => $item['file_name']];
  600. }
  601. return app('json')->success($data);
  602. }
  603. /**
  604. * 获取当前语言json
  605. * @return mixed
  606. * @throws \Throwable
  607. */
  608. public function getLangJson()
  609. {
  610. /** @var LangTypeServices $langTypeServices */
  611. $langTypeServices = app()->make(LangTypeServices::class);
  612. /** @var LangCountryServices $langCountryServices */
  613. $langCountryServices = app()->make(LangCountryServices::class);
  614. $request = app()->request;
  615. //获取接口传入的语言类型
  616. if (!$range = $request->header('cb-lang')) {
  617. //没有传入则使用系统默认语言显示
  618. if (!$range = $langTypeServices->value(['is_default' => 1], 'file_name')) {
  619. //系统没有设置默认语言的话,根据浏览器语言显示,如果浏览器语言在库中找不到,则使用简体中文
  620. if ($request->header('accept-language') !== null) {
  621. $range = explode(',', $request->header('accept-language'))[0];
  622. } else {
  623. $range = 'zh-CN';
  624. }
  625. }
  626. }
  627. // 获取type_id
  628. $typeId = $langCountryServices->value(['code' => $range], 'type_id') ?: 1;
  629. // 获取缓存key
  630. $langData = $langTypeServices->getColumn(['status' => 1, 'is_del' => 0], 'file_name', 'id');
  631. $langStr = 'api_lang_' . str_replace('-', '_', $langData[$typeId]);
  632. //读取当前语言的语言包
  633. $lang = CacheService::remember($langStr, function () use ($typeId, $range) {
  634. /** @var LangCodeServices $langCodeServices */
  635. $langCodeServices = app()->make(LangCodeServices::class);
  636. return $langCodeServices->getColumn(['type_id' => $typeId, 'is_admin' => 0], 'lang_explain', 'code');
  637. }, 3600);
  638. return app('json')->success([$range => $lang]);
  639. }
  640. /**
  641. * 获取当前后台设置的默认语言类型
  642. * @return mixed
  643. */
  644. public function getDefaultLangType()
  645. {
  646. /** @var LangTypeServices $langTypeServices */
  647. $langTypeServices = app()->make(LangTypeServices::class);
  648. $lang_type = $langTypeServices->value(['is_default' => 1], 'file_name');
  649. return app('json')->success(compact('lang_type'));
  650. }
  651. /**
  652. * 获取版本号
  653. * @return mixed
  654. */
  655. public function getVersion()
  656. {
  657. $version = parse_ini_file(app()->getRootPath() . '.version');
  658. return app('json')->success(['version' => $version['version'], 'version_code' => $version['version_code']]);
  659. }
  660. /**
  661. * 获取多语言缓存
  662. * @return \think\Response
  663. * @author 吴汐
  664. * @email 442384644@qq.com
  665. * @date 2023/03/06
  666. */
  667. public function getLangVersion()
  668. {
  669. return app('json')->success(app()->make(LangCodeServices::class)->getLangVersion());
  670. }
  671. /**
  672. * 商城基础配置汇总接口
  673. * @return \think\Response
  674. * @author 吴汐
  675. * @email 442384644@qq.com
  676. * @date 2023/04/03
  677. */
  678. public function getMallBasicConfig()
  679. {
  680. $data['site_name'] = sys_config('site_name');//网站名称
  681. $data['site_url'] = sys_config('site_url');//网站地址
  682. $data['wap_login_logo'] = sys_config('wap_login_logo');//移动端登录logo
  683. $data['record_No'] = sys_config('record_No');//备案号
  684. $data['icp_url'] = sys_config('icp_url');//备案号链接
  685. $data['network_security'] = sys_config('network_security');//网安备案
  686. $data['network_security_url'] = sys_config('network_security_url');//网安备案链接
  687. $data['store_self_mention'] = sys_config('store_self_mention');//是否开启到店自提
  688. $data['invoice_func_status'] = sys_config('invoice_func_status');//发票功能启用
  689. $data['special_invoice_status'] = sys_config('special_invoice_status');//专用发票启用
  690. $data['member_func_status'] = sys_config('member_func_status');//用户等级启用
  691. $data['balance_func_status'] = sys_config('balance_func_status');//余额功能启用
  692. $data['recharge_switch'] = sys_config('recharge_switch');//小程序充值开关
  693. $data['member_card_status'] = sys_config('member_card_status');//是否开启付费会员
  694. $data['member_price_status'] = sys_config('member_price_status');//商品会员折扣价展示启用
  695. $data['ali_pay_status'] = sys_config('ali_pay_status') != '0';//支付宝是否启用
  696. $data['pay_weixin_open'] = sys_config('pay_weixin_open') != '0';//微信是否启用
  697. $data['yue_pay_status'] = sys_config('yue_pay_status') == 1 && sys_config('balance_func_status') != 0;//余额是否启用
  698. $data['offline_pay_status'] = sys_config('offline_pay_status') == 1;//线下是否启用
  699. $data['friend_pay_status'] = sys_config('friend_pay_status') == 1;//好友是否启用
  700. $data['wechat_auth_switch'] = (int)in_array(1, sys_config('routine_auth_type'));//微信登录开关
  701. $data['phone_auth_switch'] = (int)in_array(2, sys_config('routine_auth_type'));//手机号登录开关
  702. $data['wechat_status'] = sys_config('wechat_appid') != '' && sys_config('wechat_appsecret') != '';//公众号是否配置
  703. $data['site_func'] = sys_config('model_checkbox', ['seckill', 'bargain', 'combination']);
  704. return app('json')->success($data);
  705. }
  706. /**
  707. * 小程序跳转链接接口
  708. * @param $id
  709. * @author wuhaotian
  710. * @email 442384644@qq.com
  711. * @date 2024/2/26
  712. */
  713. public function getSchemeUrl($id)
  714. {
  715. $url = app()->make(RoutineSchemeServices::class)->value($id, 'url');
  716. if ($url) {
  717. echo '<script>window.location.href="' . $url . '";</script>';
  718. } else {
  719. echo '<h1>未找到跳转路径</h1>';
  720. }
  721. }
  722. /**
  723. * 微信服务商支付
  724. * @param Request $request
  725. * @return \think\Response
  726. * @throws \think\db\exception\DataNotFoundException
  727. * @throws \think\db\exception\DbException
  728. * @throws \think\db\exception\ModelNotFoundException
  729. * @author wuhaotian
  730. * @email 442384644@qq.com
  731. * @date 2024/4/7
  732. */
  733. public function servicePayResult(Request $request)
  734. {
  735. [$sub_mch_id, $out_trade_no, $check_code] = $request->getMore([
  736. ['sub_mch_id', ''],
  737. ['out_trade_no', ''],
  738. ['check_code', ''],
  739. ], true);
  740. $data['site_name'] = sys_config('site_name');//网站名称
  741. $data['site_url'] = sys_config('site_url');//网站地址
  742. $data['site_logo'] = sys_config('wap_login_logo');//移动端登录logo
  743. $order = app()->make(StoreOrderServices::class)->getOne(['order_id' => $out_trade_no]);
  744. $data['goods_name'] = app()->make(StoreOrderCartInfoServices::class)->getCarIdByProductTitle((int)$order['id']);
  745. $data['pay_price'] = $order['pay_price'];
  746. $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'];
  747. return app('json')->header(['X-Frame-Options' => 'payapp.weixin.qq.com'])->success($data);
  748. }
  749. public function getTransferInfo(Request $request, $order_id, $type)
  750. {
  751. $extractServices = app()->make(UserExtractServices::class);
  752. $lotteryRecordServices = app()->make(LuckLotteryRecordServices::class);
  753. $uid = (int)$request->uid();
  754. if ($type == 1) {
  755. $info = $extractServices->getExtractByOrderId($uid, $order_id);
  756. $info['true_extract_price'] = bcsub($info['extract_price'], $info['extract_fee'], 2);
  757. } else {
  758. $info = $lotteryRecordServices->getRecordByOrderId($uid, $order_id);
  759. $info['true_extract_price'] = $info['num'];
  760. }
  761. if ($info['state'] == 'WAIT_USER_CONFIRM') {
  762. $pay = new Pay('v3_wechat_pay');
  763. $res = $pay->queryTransferBills($order_id);
  764. if (isset($res['fail_reason']) && $res['fail_reason'] != '') {
  765. if ($type == 1) {
  766. $extractServices->changeFail($info['id'], $info, '提现失败,原因:超时未领取');
  767. $extractServices->update($info['id'], ['state' => 'FAIL']);
  768. } else {
  769. $lotteryRecordServices->update($info['id'], ['state' => 'FAIL']);
  770. }
  771. $info['state'] = 'FAIL';
  772. }
  773. }
  774. switch ($info['channel_type']) {
  775. case 'wechat':
  776. $info['wechat_appid'] = sys_config('wechat_appid');
  777. break;
  778. case 'routine':
  779. $info['wechat_appid'] = sys_config('routine_appid');
  780. break;
  781. case 'app':
  782. $info['wechat_appid'] = sys_config('app_appid');
  783. break;
  784. }
  785. $info['mchid'] = sys_config('pay_weixin_mchid');
  786. return app('json')->success($info);
  787. }
  788. }