PublicController.php 32 KB

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