PublicController.php 27 KB

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