You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PublicController.php 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. <?php
  2. namespace app\controller\api\v1;
  3. use app\services\activity\combination\StorePinkServices;
  4. use app\services\diy\DiyServices;
  5. use app\services\message\service\StoreServiceServices;
  6. use app\services\store\DeliveryServiceServices;
  7. use app\services\other\CacheServices;
  8. use app\services\product\category\StoreCategoryServices;
  9. use app\services\product\product\StoreProductServices;
  10. use app\services\other\ExpressServices;
  11. use app\services\other\SystemCityServices;
  12. use app\services\system\attachment\SystemAttachmentServices;
  13. use app\services\system\config\SystemConfigServices;
  14. use app\services\store\SystemStoreServices;
  15. use app\services\store\SystemStoreStaffServices;
  16. use app\services\user\UserBillServices;
  17. use app\services\user\UserInvoiceServices;
  18. use app\services\user\UserServices;
  19. use app\services\wechat\WechatUserServices;
  20. use app\webscoket\SocketPush;
  21. use Joypack\Tencent\Map\Bundle\Location;
  22. use Joypack\Tencent\Map\Bundle\LocationOption;
  23. use app\Request;
  24. use crmeb\services\CacheService;
  25. use crmeb\services\UploadService;
  26. use crmeb\basic\BaseController;
  27. /**
  28. * 公共类
  29. * Class PublicController
  30. * @package app\api\controller
  31. */
  32. class PublicController extends BaseController
  33. {
  34. /**
  35. * 主页获取
  36. * @param Request $request
  37. * @return mixed
  38. */
  39. public function index(Request $request)
  40. {
  41. $banner = sys_data('routine_home_banner') ?: [];// 首页banner图
  42. $menus = sys_data('routine_home_menus') ?: [];// 首页按钮
  43. $roll = sys_data('routine_home_roll_news') ?: [];// 首页滚动新闻
  44. $activity = sys_data('routine_home_activity', 3) ?: [];// 首页活动区域图片
  45. $explosive_money = sys_data('index_categy_images') ?: [];// 首页超值爆款
  46. $site_name = sys_config('site_name');
  47. $routine_index_page = sys_data('routine_index_page');
  48. $info['fastInfo'] = $routine_index_page[0]['fast_info'] ?? '';// 快速选择简介
  49. $info['bastInfo'] = $routine_index_page[0]['bast_info'] ?? '';// 精品推荐简介
  50. $info['firstInfo'] = $routine_index_page[0]['first_info'] ?? '';// 首发新品简介
  51. $info['salesInfo'] = $routine_index_page[0]['sales_info'] ?? '';// 促销单品简介
  52. $logoUrl = sys_config('routine_index_logo');// 促销单品简介
  53. if (strstr($logoUrl, 'http') === false && $logoUrl) {
  54. $logoUrl = sys_config('site_url') . $logoUrl;
  55. }
  56. $logoUrl = str_replace('\\', '/', $logoUrl);
  57. $fastNumber = (int)sys_config('fast_number', 0);// 快速选择分类个数
  58. $bastNumber = (int)sys_config('bast_number', 0);// 精品推荐个数
  59. $firstNumber = (int)sys_config('first_number', 0);// 首发新品个数
  60. $promotionNumber = (int)sys_config('promotion_number', 0);// 首发新品个数
  61. /** @var StoreCategoryServices $categoryService */
  62. $categoryService = app()->make(StoreCategoryServices::class);
  63. $info['fastList'] = $fastNumber ? $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic') : [];// 快速选择分类个数
  64. /** @var StoreProductServices $storeProductServices */
  65. $storeProductServices = app()->make(StoreProductServices::class);
  66. $info['bastList'] = $bastNumber ? $storeProductServices->getRecommendProduct($request->uid(), 'is_best', $bastNumber) : [];// 精品推荐个数
  67. $info['firstList'] = $firstNumber ? $storeProductServices->getRecommendProduct($request->uid(), 'is_new', $firstNumber) : [];// 首发新品个数
  68. $info['bastBanner'] = sys_data('routine_home_bast_banner') ?? [];// 首页精品推荐图片
  69. $benefit = $promotionNumber ? $storeProductServices->getRecommendProduct($request->uid(), 'is_benefit', $promotionNumber) : [];// 首页促销单品
  70. $lovely = sys_data('routine_home_new_banner') ?: [];// 首发新品顶部图
  71. $likeInfo = $storeProductServices->getRecommendProduct($request->uid(), 'is_hot', 3);// 热门榜单 猜你喜欢
  72. if ($request->uid()) {
  73. /** @var WechatUserServices $wechatUserService */
  74. $wechatUserService = app()->make(WechatUserServices::class);
  75. $subscribe = $wechatUserService->value(['uid' => $request->uid()], 'subscribe') ? true : false;
  76. } else {
  77. $subscribe = true;
  78. }
  79. $newGoodsBananr = sys_config('new_goods_bananr');
  80. $tengxun_map_key = sys_config('tengxun_map_key');
  81. return app('json')->successful(compact('banner', 'menus', 'roll', 'info', 'activity', 'lovely', 'benefit', 'likeInfo', 'logoUrl', 'site_name', 'subscribe', 'newGoodsBananr', 'tengxun_map_key', 'explosive_money'));
  82. }
  83. /**
  84. * 获取分享配置
  85. * @return mixed
  86. */
  87. public function share()
  88. {
  89. $data['title'] = "v1.0";
  90. $data['synopsis'] = "赛维亚";
  91. return app('json')->successful($data);
  92. }
  93. /**
  94. * 获取网站配置
  95. * @return mixed
  96. */
  97. public function getSiteConfig()
  98. {
  99. $data['record_No'] = sys_config('record_No');
  100. return app('json')->success($data);
  101. }
  102. /**
  103. * 获取个人中心菜单
  104. * @param Request $request
  105. * @return mixed
  106. * @throws \think\db\exception\DataNotFoundException
  107. * @throws \think\db\exception\ModelNotFoundException
  108. * @throws \think\exception\DbException
  109. */
  110. public function menu_user(Request $request)
  111. {
  112. $menusInfo = sys_data('routine_my_menus') ?? [];
  113. $uid = 0;
  114. $userInfo = [];
  115. if ($request->hasMacro('user')) $userInfo = $request->user();
  116. if ($request->hasMacro('uid')) $uid = $request->uid();
  117. $vipOpen = sys_config('member_func_status');
  118. $brokerageFuncStatus = sys_config('brokerage_func_status');
  119. $balanceFuncStatus = sys_config('balance_func_status');
  120. $vipCard = sys_config('member_card_status', 0);
  121. $svipOpen = sys_config('member_card_status') ? true : false;
  122. $userService = $invoiceStatus = $deliveryUser = $isUserPromoter = $userVerifyStatus = $userOrder = $isStaff = $isDelivery = true;
  123. if ($uid && $userInfo) {
  124. /** @var StoreServiceServices $storeService */
  125. $storeService = app()->make(StoreServiceServices::class);
  126. $userService = $storeService->checkoutIsService(['uid' => $uid, 'status' => 1, 'account_status' => 1]);
  127. $userOrder = $storeService->checkoutIsService(['uid' => $uid, 'account_status' => 1, 'customer' => 1]);
  128. /** @var SystemStoreStaffServices $systemStoreStaff */
  129. $systemStoreStaff = app()->make(SystemStoreStaffServices::class);
  130. /** @var UserServices $user */
  131. $user = app()->make(UserServices::class);
  132. /** @var UserInvoiceServices $userInvoice */
  133. $userInvoice = app()->make(UserInvoiceServices::class);
  134. $invoiceStatus = $userInvoice->invoiceFuncStatus(false);
  135. /** @var DeliveryServiceServices $deliveryService */
  136. $deliveryService = app()->make(DeliveryServiceServices::class);
  137. $deliveryUser = $deliveryService->checkoutIsService($uid);
  138. $isUserPromoter = $user->checkUserPromoter($uid, $userInfo);
  139. $userVerifyStatus = $systemStoreStaff->verifyStatus($uid);
  140. try {
  141. $isStaff = $systemStoreStaff->getStaffInfoByUid($uid);
  142. } catch (\Throwable $e) {
  143. $isStaff = false;
  144. }
  145. try {
  146. $isDelivery = $deliveryService->getDeliveryInfoByUid($uid);
  147. } catch (\Throwable $e) {
  148. $isDelivery = false;
  149. }
  150. }
  151. $auth = [];
  152. $auth['/pages/users/user_vip/index'] = !$vipOpen;
  153. $auth['/pages/users/user_spread_user/index'] = !$brokerageFuncStatus || !$isUserPromoter || $uid == 0;
  154. $auth['/pages/users/user_money/index'] = !$balanceFuncStatus;
  155. $auth['/pages/admin/order/index'] = !$userOrder || $uid == 0;
  156. $auth['/pages/admin/order_cancellation/index'] = (!$userVerifyStatus && !$deliveryUser) || $uid == 0;
  157. $auth['/pages/users/user_invoice_list/index'] = !$invoiceStatus;
  158. $auth['/pages/annex/vip_paid/index'] = !$vipCard || !$svipOpen;
  159. $auth['/kefu/mobile_list'] = !$userService || $uid == 0;
  160. $auth['/pages/admin/store/index'] = $uid == 0 || !$isStaff;
  161. $auth['/pages/admin/distribution/index'] = $uid == 0 || !$isDelivery;
  162. $auth['/pages/store_spread/index'] = $uid == 0 || !$isStaff;
  163. foreach ($menusInfo as $key => &$value) {
  164. $value['pic'] = set_file_url($value['pic'] ?? '');
  165. $value['url'] = $value['url'] ?? '';
  166. if (isset($auth[$value['url']]) && $auth[$value['url']]) {
  167. unset($menusInfo[$key]);
  168. continue;
  169. }
  170. if ($value['url'] == '/kefu/mobile_list') {
  171. $value['url'] = sys_config('site_url') . $value['url'];
  172. if ($request->isRoutine()) {
  173. $value['url'] = str_replace('http://', 'https://', $value['url']);
  174. }
  175. }
  176. }
  177. $user_model = new \app\model\user\User();
  178. $agent_level = $user_model->where('uid', $uid)->value('agent_level');
  179. foreach ($menusInfo as $key => &$value) {
  180. if ($value['url'] == '/pages/users/user_spread_user/index') {
  181. if ($agent_level < 0) {
  182. unset($menusInfo[$key]);
  183. }
  184. }
  185. if ($value['name'] == '分红商品') {
  186. if ($agent_level < 3) {
  187. unset($menusInfo[$key]);
  188. }
  189. }
  190. }
  191. /** @var SystemConfigServices $systemConfigServices */
  192. $systemConfigServices = app()->make(SystemConfigServices::class);
  193. $bannerInfo = $systemConfigServices->getSpreadBanner() ?? [];
  194. $my_banner = sys_data('routine_my_banner');
  195. $routine_contact_type = sys_config('routine_contact_type', 0);
  196. /** @var DiyServices $diyServices */
  197. $diyServices = app()->make(DiyServices::class);
  198. $diy_data = $diyServices->get(['template_name' => 'member', 'type' => 3], ['value', 'status', 'order_status', 'my_banner_status', 'menu_status', 'service_status']);
  199. $diy_data = $diy_data ? $diy_data->toArray() : [];
  200. 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]);
  201. }
  202. /**
  203. * 热门搜索关键字获取
  204. * @return mixed
  205. * @throws \think\db\exception\DataNotFoundException
  206. * @throws \think\db\exception\ModelNotFoundException
  207. * @throws \think\exception\DbException
  208. */
  209. public function search()
  210. {
  211. $routineHotSearch = sys_data('routine_hot_search') ?? [];
  212. $searchKeyword = [];
  213. if (count($routineHotSearch)) {
  214. foreach ($routineHotSearch as $key => &$item) {
  215. array_push($searchKeyword, $item['title']);
  216. }
  217. }
  218. return app('json')->successful($searchKeyword);
  219. }
  220. /**
  221. * 图片上传
  222. * @param Request $request
  223. * @return mixed
  224. * @throws \Psr\SimpleCache\InvalidArgumentException
  225. */
  226. public function upload_image(Request $request, SystemAttachmentServices $services)
  227. {
  228. $data = $request->postMore([
  229. ['filename', 'file'],
  230. ]);
  231. if (!$data['filename']) return app('json')->fail('参数有误');
  232. if (CacheService::has('start_uploads_' . $request->uid()) && CacheService::get('start_uploads_' . $request->uid()) >= 100) return app('json')->fail('非法操作');
  233. $upload = UploadService::init();
  234. $info = $upload->to('store/comment')->validate()->move($data['filename']);
  235. if ($info === false) {
  236. return app('json')->fail($upload->getError());
  237. }
  238. $res = $upload->getUploadInfo();
  239. $services->attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 1, (int)sys_config('upload_type', 1), $res['time'], 3);
  240. if (CacheService::has('start_uploads_' . $request->uid()))
  241. $start_uploads = (int)CacheService::get('start_uploads_' . $request->uid());
  242. else
  243. $start_uploads = 0;
  244. $start_uploads++;
  245. CacheService::set('start_uploads_' . $request->uid(), $start_uploads, 86400);
  246. $res['dir'] = path_to_url($res['dir']);
  247. if (strpos($res['dir'], 'http') === false) $res['dir'] = $request->domain() . $res['dir'];
  248. return app('json')->successful('图片上传成功!', ['name' => $res['name'], 'url' => $res['dir']]);
  249. }
  250. /**
  251. * 物流公司
  252. * @return mixed
  253. */
  254. public function logistics(Request $request, ExpressServices $services)
  255. {
  256. [$status] = $request->getMore([
  257. ['status', ''],
  258. ], true);
  259. if ($status == 1) $data['status'] = $status;
  260. $data['is_show'] = 1;
  261. $expressList = $services->expressList($data);
  262. return app('json')->successful($expressList ?? []);
  263. }
  264. /**
  265. * 反向解析地址
  266. * @param Request $request
  267. * @return mixed
  268. */
  269. public function geoLbscoder(Request $request)
  270. {
  271. [$data] = $request->getMore([
  272. ['location', '']
  273. ], true);
  274. $locationOption = new LocationOption(sys_config('tengxun_map_key'));
  275. $data = explode(',', $data);
  276. $locationOption->setLocation($data[0] ?? '', $data[1] ?? '');
  277. $location = new Location($locationOption);
  278. $res = $location->request();
  279. if ($res->error) {
  280. return app('json')->fail($res->error);
  281. }
  282. if ($res->status) {
  283. return app('json')->fail($res->message);
  284. }
  285. if (!$res->result) {
  286. return app('json')->fail('获取失败');
  287. }
  288. return app('json')->success($res->result);
  289. }
  290. /**
  291. * 短信购买异步通知
  292. *
  293. * @param Request $request
  294. * @return mixed
  295. */
  296. public function sms_pay_notify(Request $request)
  297. {
  298. [$order_id, $price, $status, $num, $pay_time, $attach] = $request->postMore([
  299. ['order_id', ''],
  300. ['price', 0.00],
  301. ['status', 400],
  302. ['num', 0],
  303. ['pay_time', time()],
  304. ['attach', 0],
  305. ], true);
  306. if ($status == 200) {
  307. try {
  308. SocketPush::admin()->type('PAY_SMS_SUCCESS')->data(['price' => $price, 'number' => $num])->push();
  309. } catch (\Throwable $e) {
  310. }
  311. return app('json')->successful();
  312. }
  313. return app('json')->fail();
  314. }
  315. /**
  316. * 记录用户分享
  317. * @param Request $request
  318. * @param UserBillServices $services
  319. * @return mixed
  320. */
  321. public function user_share(Request $request, UserBillServices $services)
  322. {
  323. $uid = (int)$request->uid();
  324. return app('json')->successful($services->setUserShare($uid));
  325. }
  326. /**
  327. * 获取图片base64
  328. * @param Request $request
  329. * @return mixed
  330. */
  331. public function get_image_base64(Request $request)
  332. {
  333. [$imageUrl, $codeUrl] = $request->postMore([
  334. ['image', ''],
  335. ['code', ''],
  336. ], true);
  337. try {
  338. $code = CacheService::get($codeUrl, function () use ($codeUrl) {
  339. $codeTmp = $code = $codeUrl ? image_to_base64($codeUrl) : false;
  340. if (!$codeTmp) {
  341. $codeUrl = explode('?', $codeUrl)[0] ?? $codeUrl;
  342. $putCodeUrl = put_image($codeUrl);
  343. $code = $putCodeUrl ? image_to_base64(app()->request->domain(true) . '/' . $putCodeUrl) : false;
  344. $code ?? unlink(public_path() . $putCodeUrl);
  345. }
  346. return $code;
  347. });
  348. $image = CacheService::get($imageUrl, function () use ($imageUrl) {
  349. $imageTmp = $image = $imageUrl ? image_to_base64($imageUrl) : false;
  350. if (!$imageTmp) {
  351. $imageUrl = explode('?', $imageUrl)[0] ?? $imageUrl;
  352. $putImageUrl = put_image($imageUrl);
  353. $image = $putImageUrl ? image_to_base64(app()->request->domain(true) . '/' . $putImageUrl) : false;
  354. $image ?? unlink(public_path() . $putImageUrl);
  355. }
  356. return $image;
  357. });
  358. return app('json')->successful(compact('code', 'image'));
  359. } catch (\Exception $e) {
  360. return app('json')->fail($e->getMessage());
  361. }
  362. }
  363. /**
  364. * 门店列表
  365. * @param Request $request
  366. * @param SystemStoreServices $services
  367. * @return mixed
  368. * @throws \think\db\exception\DataNotFoundException
  369. * @throws \think\db\exception\DbException
  370. * @throws \think\db\exception\ModelNotFoundException
  371. */
  372. public function store_list(Request $request, SystemStoreServices $services)
  373. {
  374. [$latitude, $longitude, $product_id] = $request->getMore([
  375. ['latitude', ''],
  376. ['longitude', ''],
  377. ['product_id', 0]
  378. ], true);
  379. $where = ['type' => 0, 'is_store' => 1, 'name' => $request['name']];
  380. $data['list'] = $services->getStoreList($where, ['id', 'name', 'phone', 'address', 'detailed_address', 'image', 'is_show', 'day_start', 'day_end', 'latitude', 'longitude'], $latitude, $longitude, (int)$product_id);
  381. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  382. return app('json')->successful($data);
  383. }
  384. /**
  385. * 查找城市数据
  386. * @param Request $request
  387. * @return mixed
  388. */
  389. public function city_list(Request $request)
  390. {
  391. /** @var SystemCityServices $systemCity */
  392. $systemCity = app()->make(SystemCityServices::class);
  393. return app('json')->successful($systemCity->cityList());
  394. }
  395. /**
  396. * 获取拼团数据
  397. * @return mixed
  398. */
  399. public function pink(Request $request, StorePinkServices $pink, UserServices $user)
  400. {
  401. [$type] = $request->getMore([
  402. ['type', 1],
  403. ], true);
  404. $where = ['is_refund' => 0];
  405. if ($type == 1) {
  406. $where['status'] = 2;
  407. }
  408. $data['pink_count'] = $pink->getCount($where);
  409. $uids = array_flip($pink->getColumn($where, 'uid'));
  410. if (count($uids)) {
  411. mt_srand();
  412. $uids = array_rand($uids, count($uids) < 3 ? count($uids) : 3);
  413. }
  414. $data['avatars'] = $uids ? $user->getColumn(is_array($uids) ? [['uid', 'in', $uids]] : ['uid' => $uids], 'avatar') : [];
  415. return app('json')->successful($data);
  416. }
  417. /**
  418. * 复制口令接口
  419. * @return mixed
  420. */
  421. public function copy_words()
  422. {
  423. $data['words'] = sys_config('copy_words');
  424. return app('json')->successful($data);
  425. }
  426. /**
  427. * 生成口令关键字
  428. * @param Request $request
  429. * @return mixed
  430. * @throws \think\db\exception\DataNotFoundException
  431. * @throws \think\db\exception\DbException
  432. * @throws \think\db\exception\ModelNotFoundException
  433. */
  434. public function copy_share_words(Request $request)
  435. {
  436. list($productId) = $request->getMore([
  437. ['product_id', ''],
  438. ], true);
  439. /** @var StoreProductServices $productService */
  440. $productService = app()->make(StoreProductServices::class);
  441. $keyWords['key_words'] = $productService->getProductWords($productId);
  442. return app('json')->successful($keyWords);
  443. }
  444. /**
  445. * 获取页面数据
  446. * @return mixed
  447. * @throws \think\db\exception\DataNotFoundException
  448. * @throws \think\db\exception\DbException
  449. * @throws \think\db\exception\ModelNotFoundException
  450. */
  451. public function getDiy(DiyServices $services, $id = 0)
  452. {
  453. return app('json')->successful($services->getDiyInfo((int)$id));
  454. }
  455. /**
  456. * 获取底部导航
  457. * @param DiyServices $services
  458. * @param string $template_name
  459. * @return mixed
  460. */
  461. public function getNavigation(DiyServices $services, string $template_name = '')
  462. {
  463. return app('json')->success($services->getNavigation($template_name));
  464. }
  465. /**
  466. * 获取用户协议内容
  467. * @return mixed
  468. */
  469. public function getUserAgreement(Request $request, $type = 1)
  470. {
  471. /** @var CacheServices $cache */
  472. $cache = app()->make(CacheServices::class);
  473. /** @var UserServices $userService */
  474. $userService = app()->make(UserServices::class);
  475. $content = $cache->getDbCache($type, '');
  476. $uid = $request->uid() ?? 0;
  477. $userInfo = $userService->get($uid);
  478. $name = $userInfo['nickname'] ?? '';
  479. $avatar = $userInfo['avatar'] ?? '';
  480. return app('json')->success(compact('content', 'uid', 'name', 'avatar'));
  481. }
  482. /**
  483. * 统计代码
  484. * @return array|string
  485. */
  486. public function getScript()
  487. {
  488. return sys_config('system_statistics', '');
  489. }
  490. /**
  491. * 首页开屏广告
  492. * @return mixed
  493. */
  494. public function getOpenAdv()
  495. {
  496. /** @var CacheServices $cache */
  497. $cache = app()->make(CacheServices::class);
  498. $data = $cache->getDbCache('open_adv', '');
  499. return app('json')->success($data);
  500. }
  501. /**
  502. * 用户注销
  503. * @param Request $request
  504. * @return mixed
  505. */
  506. public function cancelUser(Request $request)
  507. {
  508. $uid = $request->uid();
  509. if (!$uid) return app('json')->fail('用户不存在');
  510. event('user.cancelUser', [$uid]);
  511. return app('json')->success('注销成功');
  512. }
  513. /**
  514. * 获取版权
  515. * @return mixed
  516. */
  517. public function getCopyright()
  518. {
  519. try {
  520. $copyright = $this->__z6uxyJQ4xYa5ee1mx5();
  521. } catch (\Throwable $e) {
  522. $copyright = false;
  523. }
  524. return json_encode($this->success(['copyright' => $copyright]));
  525. }
  526. }