PublicController.php 31 KB

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