PublicController.php 33 KB

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