PublicController.php 28 KB

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