PublicController.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v1;
  12. use app\services\activity\combination\StorePinkServices;
  13. use app\services\diy\DiyServices;
  14. use app\services\message\service\StoreServiceServices;
  15. use app\services\store\DeliveryServiceServices;
  16. use app\services\other\CacheServices;
  17. use app\services\product\category\StoreProductCategoryServices;
  18. use app\services\product\product\StoreProductServices;
  19. use app\services\other\ExpressServices;
  20. use app\services\other\SystemCityServices;
  21. use app\services\system\attachment\SystemAttachmentServices;
  22. use app\services\system\config\SystemConfigServices;
  23. use app\services\store\SystemStoreServices;
  24. use app\services\store\SystemStoreStaffServices;
  25. use app\services\user\level\UserLevelServices;
  26. use app\services\user\UserAwardIntegralServices;
  27. use app\services\user\UserBillServices;
  28. use app\services\user\UserInvoiceServices;
  29. use app\services\user\UserServices;
  30. use app\services\wechat\WechatUserServices;
  31. use app\webscoket\SocketPush;
  32. use Joypack\Tencent\Map\Bundle\Location;
  33. use Joypack\Tencent\Map\Bundle\LocationOption;
  34. use app\Request;
  35. use crmeb\services\CacheService;
  36. use crmeb\services\UploadService;
  37. use crmeb\basic\BaseController;
  38. /**
  39. * 公共类
  40. * Class PublicController
  41. * @package app\controller\api
  42. */
  43. class PublicController extends BaseController
  44. {
  45. public function test()
  46. {
  47. $levelServices = app()->make(UserLevelServices::class);
  48. $levelServices->detection(1);
  49. }
  50. /**
  51. * 主页获取
  52. * @param Request $request
  53. * @return mixed
  54. */
  55. public function index(Request $request)
  56. {
  57. $uid = $request->hasMacro('uid') ? (int)$request->uid() : 0;
  58. $banner = sys_data('routine_home_banner') ?: [];// 首页banner图
  59. $menus = sys_data('routine_home_menus') ?: [];// 首页按钮
  60. $roll = sys_data('routine_home_roll_news') ?: [];// 首页滚动新闻
  61. $activity = sys_data('routine_home_activity', 3) ?: [];// 首页活动区域图片
  62. $explosive_money = sys_data('index_categy_images') ?: [];// 首页超值爆款
  63. $site_name = sys_config('site_name');
  64. $routine_index_page = sys_data('routine_index_page');
  65. $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';// 快速选择简介
  66. $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';// 精品推荐简介
  67. $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';// 首发新品简介
  68. $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';// 促销单品简介
  69. $logoUrl = sys_config('routine_index_logo');// 促销单品简介
  70. if (strstr($logoUrl, 'http') === false && $logoUrl) {
  71. $logoUrl = sys_config('site_url') . $logoUrl;
  72. }
  73. $logoUrl = str_replace('\\', '/', $logoUrl);
  74. $fastNumber = (int)sys_config('fast_number', 0);// 快速选择分类个数
  75. $bastNumber = (int)sys_config('bast_number', 0);// 精品推荐个数
  76. $firstNumber = (int)sys_config('first_number', 0);// 首发新品个数
  77. $promotionNumber = (int)sys_config('promotion_number', 0);// 首发新品个数
  78. /** @var StoreProductCategoryServices $categoryService */
  79. $categoryService = app()->make(StoreProductCategoryServices::class);
  80. $info['fastList'] = $fastNumber ? $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic') : [];// 快速选择分类个数
  81. /** @var StoreProductServices $storeProductServices */
  82. $storeProductServices = app()->make(StoreProductServices::class);
  83. $info['bastList'] = $bastNumber ? $storeProductServices->getRecommendProduct($uid, ['is_best' => 1], $bastNumber) : [];// 精品推荐个数
  84. $info['firstList'] = $firstNumber ? $storeProductServices->getRecommendProduct($uid, ['is_new' => 1], $firstNumber) : [];// 首发新品个数
  85. $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];// 首页精品推荐图片
  86. $benefit = $promotionNumber ? $storeProductServices->getRecommendProduct($uid, ['is_benefit' => 1], $promotionNumber) : [];// 首页促销单品
  87. $lovely = sys_data('routine_home_new_banner') ?: [];// 首发新品顶部图
  88. $likeInfo = $storeProductServices->getRecommendProduct($uid, ['is_hot' => 1], 3);// 热门榜单 猜你喜欢
  89. if ($uid) {
  90. /** @var WechatUserServices $wechatUserService */
  91. $wechatUserService = app()->make(WechatUserServices::class);
  92. $subscribe = (bool)$wechatUserService->value(['uid' => $uid], 'subscribe');
  93. } else {
  94. $subscribe = true;
  95. }
  96. $newGoodsBananr = sys_config('new_goods_bananr');
  97. $tengxun_map_key = sys_config('tengxun_map_key');
  98. $award_integral_service = app()->make(UserAwardIntegralServices::class);
  99. $award_lack = $award_integral_service->getLake();
  100. $integral_price = $award_integral_service->getPrice();
  101. return app('json')->successful(compact('award_lack', 'integral_price', 'banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key', 'explosive_money'));
  102. }
  103. /**
  104. * 获取分享配置
  105. * @return mixed
  106. */
  107. public function share()
  108. {
  109. $data['img'] = sys_config('wechat_share_img');
  110. if (strstr($data['img'], 'http') === false) {
  111. $data['img'] = sys_config('site_url') . $data['img'];
  112. }
  113. $data['img'] = str_replace('\\', '/', $data['img']);
  114. $data['title'] = sys_config('wechat_share_title');
  115. $data['synopsis'] = sys_config('wechat_share_synopsis');
  116. return app('json')->successful($data);
  117. }
  118. /**
  119. * 获取网站配置
  120. * @return mixed
  121. */
  122. public function getSiteConfig()
  123. {
  124. $data['record_No'] = sys_config('record_No');
  125. return app('json')->success($data);
  126. }
  127. /**
  128. * 获取个人中心菜单
  129. * @param Request $request
  130. * @return mixed
  131. * @throws \think\db\exception\DataNotFoundException
  132. * @throws \think\db\exception\ModelNotFoundException
  133. * @throws \think\exception\DbException
  134. */
  135. public function menu_user(Request $request)
  136. {
  137. $menusInfo = sys_data('routine_my_menus') ?? [];
  138. $uid = 0;
  139. $userInfo = [];
  140. if ($request->hasMacro('user')) $userInfo = $request->user();
  141. if ($request->hasMacro('uid')) $uid = $request->uid();
  142. $vipOpen = sys_config('member_func_status');
  143. $brokerageFuncStatus = sys_config('brokerage_func_status');
  144. $balanceFuncStatus = sys_config('balance_func_status');
  145. $vipCard = sys_config('member_card_status', 0);
  146. $svipOpen = (bool)sys_config('member_card_status');
  147. $userService = $invoiceStatus = $deliveryUser = $isUserPromoter = $userVerifyStatus = $userOrder = $isStaff = $isDelivery = true;
  148. if ($uid && $userInfo) {
  149. /** @var StoreServiceServices $storeService */
  150. $storeService = app()->make(StoreServiceServices::class);
  151. $userService = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1, 'account_status' => 1]);
  152. $userOrder = $storeService->checkoutIsService(['uid' => $uid, 'account_status' => 1, 'customer' => 1]);
  153. /** @var SystemStoreStaffServices $systemStoreStaff */
  154. $systemStoreStaff = app()->make(SystemStoreStaffServices::class);
  155. /** @var UserServices $user */
  156. $user = app()->make(UserServices::class);
  157. /** @var UserInvoiceServices $userInvoice */
  158. $userInvoice = app()->make(UserInvoiceServices::class);
  159. $invoiceStatus = $userInvoice->invoiceFuncStatus(false);
  160. /** @var DeliveryServiceServices $deliveryService */
  161. $deliveryService = app()->make(DeliveryServiceServices::class);
  162. $deliveryUser = $deliveryService->checkoutIsService($uid);
  163. $isUserPromoter = $user->checkUserPromoter($uid, $userInfo);
  164. $userVerifyStatus = $systemStoreStaff->verifyStatus($uid);
  165. try {
  166. $isStaff = $systemStoreStaff->getStaffInfoByUid($uid);
  167. } catch (\Throwable $e) {
  168. $isStaff = false;
  169. }
  170. try {
  171. $isDelivery = $deliveryService->getDeliveryInfoByUid($uid);
  172. } catch (\Throwable $e) {
  173. $isDelivery = false;
  174. }
  175. }
  176. $auth = [];
  177. $auth['/pages/users/user_vip/index'] = !$vipOpen;
  178. $auth['/pages/users/user_spread_user/index'] = !$brokerageFuncStatus || !$isUserPromoter || $uid == 0;
  179. $auth['/pages/users/user_money/index'] = !$balanceFuncStatus;
  180. $auth['/pages/admin/order/index'] = !$userOrder || $uid == 0;
  181. $auth['/pages/admin/order_cancellation/index'] = (!$userVerifyStatus && !$deliveryUser) || $uid == 0;
  182. $auth['/pages/users/user_invoice_list/index'] = !$invoiceStatus;
  183. $auth['/pages/annex/vip_paid/index'] = !$vipCard || !$svipOpen;
  184. $auth['/kefu/mobile_list'] = !$userService || $uid == 0;
  185. $auth['/pages/admin/store/index'] = $uid == 0 || !$isStaff;
  186. $auth['/pages/admin/distribution/index'] = $uid == 0 || !$isDelivery;
  187. $auth['/pages/store_spread/index'] = $uid == 0 || !$isStaff;
  188. foreach ($menusInfo as $key => &$value) {
  189. $value['pic'] = set_file_url($value['pic'] ?? '');
  190. $value['url'] = $value['url'] ?? '';
  191. if (isset($auth[$value['url']]) && $auth[$value['url']]) {
  192. unset($menusInfo[$key]);
  193. continue;
  194. }
  195. if ($value['url'] == '/kefu/mobile_list') {
  196. $value['url'] = sys_config('site_url') . $value['url'];
  197. if ($request->isRoutine()) {
  198. $value['url'] = str_replace('http://', 'https://', $value['url']);
  199. }
  200. }
  201. }
  202. /** @var SystemConfigServices $systemConfigServices */
  203. $systemConfigServices = app()->make(SystemConfigServices::class);
  204. $bannerInfo = $systemConfigServices->getSpreadBanner() ?? [];
  205. $my_banner = sys_data('routine_my_banner');
  206. $routine_contact_type = sys_config('routine_contact_type', 0);
  207. /** @var DiyServices $diyServices */
  208. $diyServices = app()->make(DiyServices::class);
  209. $diy_data = $diyServices->cacheRemember('diy_data_member_3', function () use ($diyServices) {
  210. $diy_data = $diyServices->get(['template_name' => 'member', 'type' => 3], ['value', 'status', 'order_status', 'my_banner_status', 'menu_status', 'service_status']);
  211. $diy_data = $diy_data ? $diy_data->toArray() : [];
  212. return $diy_data;
  213. });
  214. if ($diy_data) {
  215. $diy_value = json_decode($diy_data['value'], true);
  216. $new_value = [];
  217. if (is_int($diy_value)) {
  218. $new_value['status'] = $diy_value;
  219. $new_value['vip_type'] = 1;
  220. $new_value['newcomer_status'] = 1;
  221. $new_value['newcomer_style'] = 1;
  222. } else {
  223. $new_value = $diy_value;
  224. }
  225. $diy_data = array_merge($diy_data, $new_value);
  226. $diy_data['order_status'] = (int)$diy_data['order_status'];
  227. }
  228. unset($diy_data['value']);
  229. return app('json')->successful(['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]);
  230. }
  231. /**
  232. * 热门搜索关键字获取
  233. * @return mixed
  234. * @throws \think\db\exception\DataNotFoundException
  235. * @throws \think\db\exception\ModelNotFoundException
  236. * @throws \think\exception\DbException
  237. */
  238. public function search()
  239. {
  240. $routineHotSearch = sys_data('routine_hot_search') ?? [];
  241. $searchKeyword = [];
  242. if (count($routineHotSearch)) {
  243. foreach ($routineHotSearch as $key => &$item) {
  244. array_push($searchKeyword, $item['title'] ?? '');
  245. }
  246. }
  247. return app('json')->successful($searchKeyword);
  248. }
  249. /**
  250. * 图片上传
  251. * @param Request $request
  252. * @return mixed
  253. * @throws \Psr\SimpleCache\InvalidArgumentException
  254. */
  255. public function upload_image(Request $request, SystemAttachmentServices $services)
  256. {
  257. $data = $request->postMore([
  258. ['filename', 'file'],
  259. ]);
  260. if (!$data['filename']) return app('json')->fail('参数有误');
  261. if (CacheService::has('start_uploads_' . $request->uid()) && CacheService::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail('非法操作');
  262. $upload = UploadService::init();
  263. $info = $upload->to('store/comment')->validate()->move($data['filename']);
  264. if ($info === false) {
  265. return app('json')->fail($upload->getError());
  266. }
  267. $res = $upload->getUploadInfo();
  268. $services->attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, (int)sys_config('upload_type', 1), $res['time'], 3);
  269. if (CacheService::has('start_uploads_' . $request->uid()))
  270. $start_uploads = (int)CacheService::get('start_uploads_' . $request->uid());
  271. else
  272. $start_uploads = 0;
  273. $start_uploads++;
  274. CacheService::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
  275. $res['dir'] = path_to_url($res['dir']);
  276. if (strpos($res['dir'], 'http') === false) $res['dir'] = sys_config('site_url') . $res['dir'];
  277. return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
  278. }
  279. /**
  280. * 物流公司
  281. * @return mixed
  282. */
  283. public function logistics(Request $request, ExpressServices $services)
  284. {
  285. [$status] = $request->getMore([
  286. ['status', ''],
  287. ], true);
  288. if ($status == 1) $data['status'] = $status;
  289. $data['is_show'] = 1;
  290. $expressList = $services->expressList($data);
  291. return app('json')->successful($expressList ?? []);
  292. }
  293. /**
  294. * 反向解析地址
  295. * @param Request $request
  296. * @return mixed
  297. */
  298. public function geoLbscoder(Request $request)
  299. {
  300. [$data] = $request->getMore([
  301. ['location', '']
  302. ], true);
  303. $locationOption = new LocationOption(sys_config('tengxun_map_key'));
  304. $data = explode(',', $data);
  305. $locationOption->setLocation($data[0] ?? '', $data[1] ?? '');
  306. $location = new Location($locationOption);
  307. $res = $location->request();
  308. if ($res->error) {
  309. return app('json')->fail($res->error);
  310. }
  311. if ($res->status) {
  312. return app('json')->fail($res->message);
  313. }
  314. if (!$res->result) {
  315. return app('json')->fail('获取失败');
  316. }
  317. return app('json')->success($res->result);
  318. }
  319. /**
  320. * 短信购买异步通知
  321. *
  322. * @param Request $request
  323. * @return mixed
  324. */
  325. public function sms_pay_notify(Request $request)
  326. {
  327. [$order_id, $price, $status, $num, $pay_time, $attach] = $request->postMore([
  328. ['order_id', ''],
  329. ['price', 0.00],
  330. ['status', 400],
  331. ['num', 0],
  332. ['pay_time', time()],
  333. ['attach', 0],
  334. ], true);
  335. if ($status == 200) {
  336. try {
  337. SocketPush::admin()->type('PAY_SMS_SUCCESS')->data(['price' => $price, 'number' => $num])->push();
  338. } catch (\Throwable $e) {
  339. }
  340. return app('json')->successful();
  341. }
  342. return app('json')->fail();
  343. }
  344. /**
  345. * 记录用户分享
  346. * @param Request $request
  347. * @param UserBillServices $services
  348. * @return mixed
  349. */
  350. public function user_share(Request $request, UserBillServices $services)
  351. {
  352. $uid = (int)$request->uid();
  353. return app('json')->successful($services->setUserShare($uid));
  354. }
  355. /**
  356. * 获取图片base64
  357. * @param Request $request
  358. * @return mixed
  359. */
  360. public function get_image_base64(Request $request)
  361. {
  362. [$imageUrl, $codeUrl] = $request->postMore([
  363. ['image', ''],
  364. ['code', ''],
  365. ], true);
  366. if ($imageUrl !== '' && !preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $imageUrl)) {
  367. return app('json')->success(['code' => false, 'image' => false]);
  368. }
  369. if ($codeUrl !== '' && !(preg_match('/.*(\.png|\.jpg|\.jpeg|\.gif)$/', $codeUrl) || strpos($codeUrl, 'https://mp.weixin.qq.com/cgi-bin/showqrcode') !== false)) {
  370. return app('json')->success(['code' => false, 'image' => false]);
  371. }
  372. try {
  373. $code = CacheService::get($codeUrl, function () use ($codeUrl) {
  374. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
  375. if (!$codeTmp) {
  376. $codeUrl = explode('?', $codeUrl)[0] ?? $codeUrl;
  377. $putCodeUrl = put_image($codeUrl);
  378. $code = $putCodeUrl ? image_to_base64(public_path() . $putCodeUrl) : false;
  379. $code ?? unlink(public_path() . $putCodeUrl);
  380. }
  381. return $code;
  382. });
  383. $image = CacheService::get($imageUrl, function () use ($imageUrl) {
  384. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  385. if (!$imageTmp) {
  386. $imageUrl = explode('?', $imageUrl)[0] ?? $imageUrl;
  387. $putImageUrl = put_image($imageUrl);
  388. $image = $putImageUrl ? image_to_base64(public_path() . $putImageUrl) : false;
  389. $image ?? unlink(public_path() . $putImageUrl);
  390. }
  391. return $image;
  392. });
  393. return app('json')->successful(compact('code', 'image'));
  394. } catch (\Exception $e) {
  395. return app('json')->fail($e->getMessage());
  396. }
  397. }
  398. /**
  399. * 门店列表
  400. * @param Request $request
  401. * @param SystemStoreServices $services
  402. * @return mixed
  403. * @throws \think\db\exception\DataNotFoundException
  404. * @throws \think\db\exception\DbException
  405. * @throws \think\db\exception\ModelNotFoundException
  406. */
  407. public function store_list(Request $request, SystemStoreServices $services)
  408. {
  409. [$latitude, $longitude, $product_id, $type, $is_store, $store_id] = $request->getMore([
  410. ['latitude', ''],
  411. ['longitude', ''],
  412. ['product_id', 0],
  413. ['type', 0],//商品类型 0:普通 1:秒杀
  414. ['is_store', 1], //前端传值为 1|商城配送 2|门店自提 3|门店配送
  415. ['store_id', 0], //前端传值为 1|商城配送 2|门店自提 3|门店配送
  416. ], true);
  417. //判断是否门店自提
  418. $is_store == 2 ? $is_store = 1 : $is_store = '';
  419. $where = ['type' => 0, 'is_store' => $is_store];
  420. $field = ['id', 'name', 'phone', 'image', 'latitude', 'longitude', 'address', 'detailed_address', 'is_show', 'is_store', 'day_time', 'day_start', 'day_end', 'valid_range'];
  421. $data['list'] = $services->getStoreList($where, $field, $latitude, $longitude, (int)$product_id, [], (int)$type, $store_id);
  422. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  423. return app('json')->successful($data);
  424. }
  425. /**
  426. * 查找城市数据
  427. * @param Request $request
  428. * @return mixed
  429. */
  430. public function city_list(Request $request)
  431. {
  432. /** @var SystemCityServices $systemCity */
  433. $systemCity = app()->make(SystemCityServices::class);
  434. return app('json')->successful($systemCity->cityList());
  435. }
  436. /**
  437. * 获取拼团数据
  438. * @return mixed
  439. */
  440. public function pink(Request $request, StorePinkServices $pink, UserServices $user)
  441. {
  442. [$type] = $request->getMore([
  443. ['type', 1],
  444. ], true);
  445. $where = ['is_refund' => 0];
  446. if ($type == 1) {
  447. $where['status'] = 2;
  448. }
  449. $data['pink_count'] = $pink->getCount($where);
  450. $uids = array_flip($pink->getColumn($where, 'uid'));
  451. if (count($uids)) {
  452. mt_srand();
  453. $uids = array_rand($uids, count($uids) < 3 ? count($uids) : 3);
  454. }
  455. $data['avatars'] = $uids ? $user->getColumn(is_array($uids) ? [['uid', 'in', $uids]] : ['uid' => $uids], 'avatar') : [];
  456. return app('json')->successful($data);
  457. }
  458. /**
  459. * 复制口令接口
  460. * @return mixed
  461. */
  462. public function copy_words()
  463. {
  464. $data['words'] = sys_config('copy_words');
  465. return app('json')->successful($data);
  466. }
  467. /**
  468. * 生成口令关键字
  469. * @param Request $request
  470. * @return mixed
  471. * @throws \think\db\exception\DataNotFoundException
  472. * @throws \think\db\exception\DbException
  473. * @throws \think\db\exception\ModelNotFoundException
  474. */
  475. public function copy_share_words(Request $request)
  476. {
  477. [$productId] = $request->getMore([
  478. ['product_id', ''],
  479. ], true);
  480. /** @var StoreProductServices $productService */
  481. $productService = app()->make(StoreProductServices::class);
  482. $keyWords['key_words'] = $productService->getProductWords($productId);
  483. return app('json')->successful($keyWords);
  484. }
  485. /**
  486. * 获取页面数据
  487. * @return mixed
  488. * @throws \think\db\exception\DataNotFoundException
  489. * @throws \think\db\exception\DbException
  490. * @throws \think\db\exception\ModelNotFoundException
  491. */
  492. public function getDiy(DiyServices $services, $id = 0)
  493. {
  494. return app('json')->successful($services->getDiyInfo((int)$id));
  495. }
  496. /**
  497. * @param DiyServices $services
  498. * @param int $id
  499. * @return mixed
  500. * @author 等风来
  501. * @email 136327134@qq.com
  502. * @date 2022/11/9
  503. */
  504. public function getDiyVersion(DiyServices $services, $id = 0)
  505. {
  506. return app('json')->successful(['version' => $services->getDiyVersion((int)$id)]);
  507. }
  508. /**
  509. * 获取底部导航
  510. * @param DiyServices $services
  511. * @param string $template_name
  512. * @return mixed
  513. */
  514. public function getNavigation(DiyServices $services, string $template_name = '')
  515. {
  516. return app('json')->success($services->getNavigation($template_name));
  517. }
  518. /**
  519. * 获取用户协议内容
  520. * @return mixed
  521. */
  522. public function getUserAgreement(Request $request, $type = 1)
  523. {
  524. /** @var CacheServices $cache */
  525. $cache = app()->make(CacheServices::class);
  526. /** @var UserServices $userService */
  527. $userService = app()->make(UserServices::class);
  528. $content = $cache->getDbCache($type, '');
  529. $uid = $request->uid() ?? 0;
  530. $userInfo = $userService->get($uid);
  531. $name = $userInfo['nickname'] ?? '';
  532. $avatar = $userInfo['avatar'] ?? '';
  533. return app('json')->success(compact('content', 'uid', 'name', 'avatar'));
  534. }
  535. /**
  536. * 统计代码
  537. * @return array|string
  538. */
  539. public function getScript()
  540. {
  541. return sys_config('system_statistics', '');
  542. }
  543. /**
  544. * 首页开屏广告
  545. * @return mixed
  546. */
  547. public function getOpenAdv()
  548. {
  549. /** @var CacheServices $cache */
  550. $cache = app()->make(CacheServices::class);
  551. $data = $cache->getDbCache('open_adv', '');
  552. $data['time'] = (float)($data['time'] ?? 3);
  553. $data['interval_time'] = (float)($data['interval_time'] ?? 24);
  554. return app('json')->success($data);
  555. }
  556. /**
  557. * 用户注销
  558. * @param Request $request
  559. * @return mixed
  560. */
  561. public function cancelUser(Request $request)
  562. {
  563. $uid = $request->uid();
  564. if (!$uid) return app('json')->fail('用户不存在');
  565. event('user.cancelUser', [$uid]);
  566. return app('json')->success('注销成功');
  567. }
  568. /**
  569. * 获取版权
  570. * @return mixed
  571. */
  572. public function getCopyright()
  573. {
  574. try {
  575. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  576. } catch (\Throwable $e) {
  577. $copyright = [
  578. 'copyrightContext' => '',
  579. 'copyrightImage' => '',
  580. ];
  581. }
  582. $copyright['record_No'] = sys_config('record_No');
  583. $copyright['version'] = get_crmeb_version();
  584. $copyright['routine_contact_type'] = sys_config('routine_contact_type');
  585. $copyright['store_user_agreement'] = (int)sys_config('store_user_agreement');
  586. $copyright['routine_auth_type'] = sys_config('routine_auth_type', []);
  587. $copyright['wechat_auth_switch'] = (int)in_array(1, $copyright['routine_auth_type']);//微信登录开关
  588. $copyright['phone_auth_switch'] = (int)in_array(2, $copyright['routine_auth_type']);//手机号登录开关
  589. $copyright['site_name'] = sys_config('site_name', '');
  590. $copyright['site_logo'] = sys_config('wap_login_logo', '');
  591. $copyright['wechat_status'] = sys_config('wechat_appid') && sys_config('wechat_appsecret');
  592. return $this->success($copyright);
  593. }
  594. /**
  595. * 登录页面获取logo以及版本全新
  596. * @return mixed
  597. */
  598. public function getLogo()
  599. {
  600. try {
  601. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  602. } catch (\Throwable $e) {
  603. $copyright = [
  604. 'copyrightContext' => '',
  605. 'copyrightImage' => '',
  606. ];
  607. }
  608. $copyright['record_No'] = sys_config('record_No');
  609. $copyright['version'] = get_crmeb_version();
  610. $logo = sys_config('wap_login_logo');
  611. if (strstr($logo, 'http') === false && $logo) $logo = sys_config('site_url') . $logo;
  612. $copyright['site_name'] = sys_config('site_name');
  613. $copyright['logo_url'] = str_replace('\\', '/', $logo);
  614. $copyright['store_user_agreement'] = (int)sys_config('store_user_agreement');
  615. $copyright['routine_auth_type'] = sys_config('routine_auth_type', []);
  616. $copyright['wechat_auth_switch'] = (int)in_array(1, $copyright['routine_auth_type']);//微信登录开关
  617. $copyright['phone_auth_switch'] = (int)in_array(2, $copyright['routine_auth_type']);//手机号登录开关
  618. $copyright['wechat_status'] = sys_config('wechat_appid') && sys_config('wechat_appsecret');
  619. return app('json')->successful($copyright);
  620. }
  621. }