PublicController.php 32 KB

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