PublicController.php 29 KB

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