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