PublicController.php 31 KB

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