PublicController.php 27 KB

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