PublicController.php 28 KB

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