PublicController.php 28 KB

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