PublicController.php 32 KB

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