PublicController.php 26 KB

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