PublicController.php 32 KB

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