PublicController.php 32 KB

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