PublicController.php 30 KB

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