PublicController.php 27 KB

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