PublicController.php 32 KB

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