PublicController.php 32 KB

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