PublicController.php 28 KB

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