PublicController.php 28 KB

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