PublicController.php 32 KB

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