PublicController.php 28 KB

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