PublicController.php 32 KB

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