PublicController.php 27 KB

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