PublicController.php 31 KB

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