PublicController.php 27 KB

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