PublicController.php 26 KB

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