PublicController.php 29 KB

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