PublicController.php 31 KB

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