PublicController.php 32 KB

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