PublicController.php 31 KB

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