PublicController.php 34 KB

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