PublicController.php 31 KB

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