PublicController.php 31 KB

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