PublicController.php 27 KB

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