PublicController.php 32 KB

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