PublicController.php 33 KB

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