PublicController.php 28 KB

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