PublicController.php 31 KB

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