PublicController.php 33 KB

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