PublicController.php 29 KB

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