PublicController.php 33 KB

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