PublicController.php 34 KB

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