PublicController.php 31 KB

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