PublicController.php 30 KB

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