Common.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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\admin;
  12. use think\facade\Db;
  13. use app\common\repositories\store\order\StoreOrderProductRepository;
  14. use app\common\repositories\store\order\StoreOrderRepository;
  15. use app\common\repositories\system\auth\MenuRepository;
  16. use app\common\repositories\system\CacheRepository;
  17. use app\common\repositories\system\config\ConfigClassifyRepository;
  18. use app\common\repositories\system\config\ConfigRepository;
  19. use app\common\repositories\system\config\ConfigValueRepository;
  20. use app\common\repositories\system\CountRepository;
  21. use app\common\repositories\system\DataScreenRepository;
  22. use app\common\repositories\system\merchant\MerchantCategoryRepository;
  23. use app\common\repositories\system\merchant\MerchantRepository;
  24. use app\common\repositories\user\UserRepository;
  25. use app\common\repositories\user\UserVisitRepository;
  26. use crmeb\basic\BaseController;
  27. use crmeb\services\HttpService;
  28. use crmeb\services\UploadService;
  29. use think\db\exception\DataNotFoundException;
  30. use think\db\exception\DbException;
  31. use think\db\exception\ModelNotFoundException;
  32. use think\Exception;
  33. use think\exception\ValidateException;
  34. use think\facade\Cache;
  35. /**
  36. * Class Common
  37. * @package app\controller\admin
  38. * @author xaboy
  39. * @day 2020/6/25
  40. */
  41. class Common extends BaseController
  42. {
  43. /**
  44. * @return mixed
  45. * @author xaboy
  46. * @day 2020/6/25
  47. */
  48. public function main()
  49. {
  50. $res = Cache::remember(self::class . '@sysmain', function () {
  51. $today = $this->mainGroup('today');
  52. $yesterday = $this->mainGroup('yesterday');
  53. $month = $this->mainGroup('month');
  54. $lastWeek = $this->mainGroup(date('Y-m-d', strtotime('- 7day')));
  55. $lastWeekRate = [];
  56. foreach ($lastWeek as $k => $item) {
  57. $lastWeekRate[$k] = $this->getRate($item, $today[$k], 4);
  58. }
  59. return compact('today', 'yesterday', 'lastWeekRate','month');
  60. }, 1800 + random_int(600, 1200));
  61. return app('json')->success($res);
  62. }
  63. /**
  64. * 上传视频key
  65. * @return \think\response\Json
  66. * @author Qinii
  67. * @day 3/11/22
  68. */
  69. public function temp_key()
  70. {
  71. $upload = UploadService::create();
  72. $re = $upload->getTempKeys();
  73. return app('json')->success($re);
  74. }
  75. /**
  76. * @param $date
  77. * @return array
  78. * @author xaboy
  79. * @day 2020/6/25
  80. */
  81. protected function mainGroup($date)
  82. {
  83. $userRepository = app()->make(UserRepository::class);
  84. $storeOrderRepository = app()->make(StoreOrderRepository::class);
  85. $merchantRepository = app()->make(MerchantRepository::class);
  86. $userVisitRepository = app()->make(UserVisitRepository::class);
  87. $payPrice = (float)$storeOrderRepository->dayOrderPrice($date);
  88. $userNum = (float)$userRepository->newUserNum($date);
  89. $storeNum = (float)$merchantRepository->dateMerchantNum($date);
  90. $visitUserNum = (float)$userVisitRepository->dateVisitUserNum($date);
  91. $visitNum = (float)$userVisitRepository->dateVisitNum($date);
  92. return compact('payPrice', 'userNum', 'storeNum', 'visitUserNum', 'visitNum');
  93. }
  94. /**
  95. * @param StoreOrderRepository $repository
  96. * @return mixed
  97. * @author xaboy
  98. * @day 2020/6/25
  99. */
  100. public function order(StoreOrderRepository $repository)
  101. {
  102. $today = $repository->dayOrderPriceGroup('today')->toArray();
  103. $yesterday = $repository->dayOrderPriceGroup('yesterday')->toArray();
  104. $today = array_combine(array_column($today, 'time'), array_column($today, 'price'));
  105. $yesterday = array_combine(array_column($yesterday, 'time'), array_column($yesterday, 'price'));
  106. $time = getTimes();
  107. $order = [];
  108. foreach ($time as $item) {
  109. $order[] = [
  110. 'time' => $item,
  111. 'today' => $today[$item] ?? 0,
  112. 'yesterday' => $yesterday[$item] ?? 0,
  113. ];
  114. }
  115. $todayPrice = $repository->dayOrderPrice('today');
  116. $yesterdayPrice = $repository->dayOrderPrice('yesterday');
  117. return app('json')->success(compact('order', 'todayPrice', 'yesterdayPrice'));
  118. }
  119. /**
  120. * @param StoreOrderRepository $repository
  121. * @return mixed
  122. * @author xaboy
  123. * @day 2020/6/25
  124. */
  125. public function orderNum(StoreOrderRepository $repository)
  126. {
  127. $orderNum = $repository->dayOrderNum('today');
  128. $yesterdayNum = $repository->dayOrderNum('yesterday');
  129. $today = $repository->dayOrderNumGroup('today')->toArray();
  130. $today = array_combine(array_column($today, 'time'), array_column($today, 'total'));
  131. $monthOrderNum = $repository->dayOrderNum(date('Y/m/d', strtotime('first day of')) . ' 00:00:00' . '-' . date('Y/m/d H:i:s'));
  132. $date = date('Y/m/01 00:00:00', strtotime('last Month')) . '-' . date('Y/m/d 00:00:00', strtotime('-1 day', strtotime('first day of')));
  133. $beforeOrderNum = $repository->dayOrderNum($date);
  134. $monthRate = $this->getRate($beforeOrderNum, $monthOrderNum);
  135. $orderRate = $this->getRate($yesterdayNum, $orderNum);
  136. $time = getTimes();
  137. $data = [];
  138. foreach ($time as $item) {
  139. $data[] = [
  140. 'total' => $today[$item] ?? 0,
  141. 'time' => $item
  142. ];
  143. }
  144. $today = $data;
  145. return app('json')->success(compact('orderNum', 'today', 'monthOrderNum', 'monthRate', 'orderRate'));
  146. }
  147. /**
  148. * @param StoreOrderRepository $repository
  149. * @return mixed
  150. * @author xaboy
  151. * @day 2020/6/25
  152. */
  153. public function orderUser(StoreOrderRepository $repository)
  154. {
  155. $orderNum = $repository->dayOrderUserNum('today');
  156. $yesterdayNum = $repository->dayOrderUserNum('yesterday');
  157. $today = $repository->dayOrderUserGroup('today')->toArray();
  158. $today = array_combine(array_column($today, 'time'), array_column($today, 'total'));
  159. $monthOrderNum = $repository->dayOrderUserNum(date('Y/m/d', strtotime('first day of')) . ' 00:00:00' . '-' . date('Y/m/d H:i:s'));
  160. $date = gmdate('Y/m/01 00:00:00', strtotime('last Month')) . '-' . date('Y/m/d 00:00:00', strtotime('-1 day', strtotime('first day of')));
  161. $beforeOrderNum = $repository->dayOrderUserNum($date);
  162. $monthRate = $this->getRate($beforeOrderNum, $monthOrderNum);
  163. $orderRate = $this->getRate($yesterdayNum, $orderNum);
  164. $time = getTimes();
  165. $data = [];
  166. foreach ($time as $item) {
  167. $data[] = [
  168. 'total' => $today[$item] ?? 0,
  169. 'time' => $item
  170. ];
  171. }
  172. $today = $data;
  173. return app('json')->success(compact('orderNum', 'today', 'monthOrderNum', 'monthRate', 'orderRate'));
  174. }
  175. /**
  176. * @param StoreOrderProductRepository $repository
  177. * @return mixed
  178. * @author xaboy
  179. * @day 2020/6/25
  180. */
  181. public function merchantStock(StoreOrderProductRepository $repository)
  182. {
  183. $date = $this->request->param('date') ?: 'lately7';
  184. $res = Cache::store('file')->remember(self::class . '@merchantStock' . $date, function () use ($date, $repository) {
  185. $total = $repository->dateProductNum($date);
  186. $list = $repository->orderProductGroup($date)->toArray();
  187. foreach ($list as &$item) {
  188. $item['rate'] = bcdiv($item['total'], $total, 2);
  189. }
  190. return compact('list', 'total');
  191. }, 2000 + random_int(600, 1200));
  192. return app('json')->success($res);
  193. }
  194. /**
  195. * @param UserVisitRepository $repository
  196. * @return mixed
  197. * @author xaboy
  198. * @day 2020/6/25
  199. */
  200. public function merchantVisit(UserVisitRepository $repository)
  201. {
  202. $date = $this->request->param('date') ?: 'lately7';
  203. $res = Cache::remember(self::class . '@merchantVisit' . $date, function () use ($date, $repository) {
  204. $total = $repository->dateVisitMerchantTotal($date);
  205. $list = $repository->dateVisitMerchantNum($date)->toArray();
  206. foreach ($list as &$item) {
  207. $item['rate'] = bcdiv($item['total'], $total, 2);
  208. $item['care_count'] = $item['care_ficti'] + $item['care_count'];
  209. }
  210. $res = compact('list', 'total');
  211. return $res;
  212. }, 2000 + random_int(600, 1200));
  213. return app('json')->success($res);
  214. }
  215. /**
  216. * @param StoreOrderRepository $repository
  217. * @param MerchantCategoryRepository $merchantCategoryRepository
  218. * @return mixed
  219. * @author xaboy
  220. * @day 2020/6/25
  221. */
  222. public function merchantRate(StoreOrderRepository $repository, MerchantCategoryRepository $merchantCategoryRepository)
  223. {
  224. $date = $this->request->param('date') ?: 'lately7';
  225. $res = Cache::store('file')->remember(self::class . '@merchantRate' . $date, function () use ($repository, $merchantCategoryRepository, $date) {
  226. $total = $repository->dateOrderPrice($date);
  227. $list = $merchantCategoryRepository->dateMerchantPriceGroup($date)->toArray();
  228. $rate = 1;
  229. $pay_price = $total;
  230. foreach ($list as &$item) {
  231. $item['rate'] = bcdiv($item['pay_price'], $total, 2);
  232. $rate = bcsub($rate, $item['rate'], 2);
  233. $pay_price = bcsub($pay_price, $item['pay_price'], 2);
  234. }
  235. if ($rate > 0 && count($list)) {
  236. $list[] = [
  237. 'pay_price' => $pay_price,
  238. 'category_name' => '其他类',
  239. 'rate' => $rate
  240. ];
  241. }
  242. return compact('list', 'total');
  243. }, 2000 + random_int(600, 1200));
  244. return app('json')->success($res);
  245. }
  246. public function userData(UserRepository $repository, UserVisitRepository $visitRepository)
  247. {
  248. $date = $this->request->param('date') ?: 'lately7';
  249. $res = Cache::store('file')->remember(self::class . '@userData' . $date, function () use ($visitRepository, $repository, $date) {
  250. $newUserList = $repository->userNumGroup($date)->toArray();
  251. $newUserList = array_combine(array_column($newUserList, 'time'), array_column($newUserList, 'new'));
  252. $visitList = $visitRepository->dateVisitNumGroup($date)->toArray();
  253. $visitList = array_combine(array_column($visitList, 'time'), array_column($visitList, 'total'));
  254. $base = $repository->beforeUserNum(getStartModelTime($date));
  255. $time = getDatesBetweenTwoDays(getStartModelTime($date), date('Y-m-d'));
  256. $userList = [];
  257. $before = $base;
  258. foreach ($time as $item) {
  259. $new = $newUserList[$item] ?? 0;
  260. $before += $new;
  261. $userList[] = [
  262. 'total' => $before,
  263. 'new' => $new,
  264. 'visit' => $visitList[$item] ?? 0,
  265. 'day' => $item
  266. ];
  267. }
  268. return $userList;
  269. }, 2000 + random_int(600, 1200));
  270. return app('json')->success($res);
  271. }
  272. /**
  273. * @param $last
  274. * @param $today
  275. * @param int $scale
  276. * @return int|string|null
  277. * @author xaboy
  278. * @day 2020/6/25
  279. */
  280. protected function getRate($last, $today, $scale = 2)
  281. {
  282. if ($last == $today)
  283. return 0;
  284. else if ($last == 0)
  285. return $today;
  286. else if ($today == 0)
  287. return -$last;
  288. else
  289. return (float)bcdiv(bcsub($today, $last, $scale), $last, $scale);
  290. }
  291. /**
  292. * 申请授权
  293. * @return mixed
  294. */
  295. public function auth_apply()
  296. {
  297. $data = $this->request->params([
  298. ['company_name', ''],
  299. ['domain_name', ''],
  300. ['order_id', ''],
  301. ['phone', ''],
  302. ['label', 10],
  303. ['captcha', ''],
  304. ]);
  305. if (!$data['company_name']) {
  306. return app('json')->fail('请填写公司名称');
  307. }
  308. if (!$data['domain_name']) {
  309. return app('json')->fail('请填写授权域名');
  310. }
  311. if (!$data['phone']) {
  312. return app('json')->fail('请填写手机号码');
  313. }
  314. if (!$data['order_id']) {
  315. return app('json')->fail('请填写订单id');
  316. }
  317. if (!$data['captcha']) {
  318. return app('json')->fail('请填写验证码');
  319. }
  320. $res = HttpService::postRequest('http://authorize.crmeb.net/api/auth_apply', $data);
  321. if ($res === false) {
  322. return app('json')->fail('申请失败,服务器没有响应!');
  323. }
  324. $res = json_decode($res, true);
  325. if (isset($res['status'])) {
  326. if ($res['status'] == 400) {
  327. return app('json')->fail($res['msg'] ?? "申请失败");
  328. } else {
  329. return app('json')->success($res['msg'] ?? '申请成功', $res);
  330. }
  331. }
  332. return app('json')->fail("申请授权失败!");
  333. }
  334. public function uploadConfig(ConfigRepository $repository)
  335. {
  336. return app('json')->success(formToData($repository->uploadForm()));
  337. }
  338. public function saveUploadConfig(ConfigRepository $repository)
  339. {
  340. $formData = $this->request->post();
  341. if (!count($formData)) return app('json')->fail('保存失败');
  342. $repository->saveUpload($formData);
  343. return app('json')->success('保存成功');
  344. }
  345. public function loginConfig()
  346. {
  347. $login_logo = systemConfig('sys_login_logo');
  348. $menu_logo = systemConfig('sys_menu_logo');
  349. $menu_slogo = systemConfig('sys_menu_slogo');
  350. $login_title = systemConfig('sys_login_title');
  351. $sys_login_banner = systemConfig('sys_login_banner');
  352. $beian_sn = systemConfig('beian_sn');
  353. $login_banner = [];
  354. foreach ($sys_login_banner ?: [] as $item) {
  355. $login_banner[] = [
  356. 'pic' => $item,
  357. 'name' => $item
  358. ];
  359. }
  360. return app('json')->success(compact('login_banner', 'login_logo', 'login_title', 'menu_slogo', 'menu_logo', 'beian_sn'));
  361. }
  362. public function version()
  363. {
  364. $sys_open_version = systemConfig('sys_open_version');
  365. $data = [
  366. 'version' => get_crmeb_version('未知'),
  367. 'year' => '© 2014-' . date('Y', time()),
  368. 'beian_sn' => systemConfig('beian_sn'),
  369. 'url' => 'http://www.crmeb.com',
  370. 'Copyright' => 'Copyright',
  371. 'sys_open_version' => $sys_open_version === '' ? '1' : $sys_open_version,
  372. 'host' => request()->host(),
  373. 'system' => PHP_OS,
  374. 'php' => @phpversion()
  375. ];
  376. $copyright = app()->make(CacheRepository::class)->getResultByKey('copyright_status');
  377. if (!$copyright) {
  378. $data['status'] = -1;
  379. } else {
  380. $copyright = app()->make(CacheRepository::class)->search(['copyright_status', 'copyright_context', 'copyright_image']);
  381. $data['status'] = 1;
  382. $data['Copyright'] = $copyright['copyright_context'] ?? '';
  383. $data['image'] = $copyright['copyright_image'] ?? '';
  384. $data['url'] = systemConfig('site_url');
  385. }
  386. return app('json')->success($data);
  387. }
  388. public function config()
  389. {
  390. $config = systemConfig(['delivery_type', 'delivery_status', 'sms_use_type', 'hot_ranking_lv', 'hot_ranking_switch']);
  391. return app('json')->success($config);
  392. }
  393. public function getChangeColor()
  394. {
  395. return app('json')->success(systemConfig(['global_theme']));
  396. }
  397. public function setChangeColor()
  398. {
  399. $data = $this->request->params(['global_theme']);
  400. $make = app()->make(ConfigValueRepository::class);
  401. $make->setFormData($data, 0);
  402. return app('json')->success('修改成功');
  403. }
  404. public function svaeCopyright()
  405. {
  406. $data = $this->request->params(['copyright_context', 'copyright_image']);
  407. $copyright = app()->make(CacheRepository::class)->getResultByKey('copyright_status');
  408. if (!$copyright)
  409. return app('json')->fail('请先获取版权授权');
  410. app()->make(CacheRepository::class)->saveAll($data);
  411. return app('json')->success('修改成功');
  412. }
  413. public function payAuth()
  414. {
  415. $host = 'https://shop.crmeb.net/html/index.html';
  416. $version = get_crmeb_version_code();
  417. $url = rtrim($this->request->host(), '/');
  418. $data['url'] = $host . '?url=' . $url . '&product=mer&label=10&venrsion=' . $version;
  419. return app('json')->success($data);
  420. }
  421. /**
  422. * 检测队列是否正常
  423. * @return \think\response\Json
  424. * @author Qinii
  425. * @day 2023/10/24
  426. */
  427. public function queue()
  428. {
  429. $key = env('APP_KEY', 'merchant') . '_queue_status';
  430. $queue = Cache::get($key);
  431. if (!$queue) {
  432. return app('json')->status(201, '您的【队列】运行异常,会导致商品上下架无效、自动取消订单、订单自动好评、拼团到期退款等任务无法正常使用,请尽快启动队列', ['msg' => '>>> 点击查看处理方法 <<<', 'url' => 'https://www.crmeb.com/ask/thread/33264']);
  433. }
  434. return app('json')->status(200, 'ok');
  435. }
  436. public function getAdminCount()
  437. {
  438. return app('json')->success(app()->make(CountRepository::class)->getAdminCount());
  439. }
  440. public function getAdminTodo()
  441. {
  442. return app('json')->success(app()->make(CountRepository::class)->getAdminTodo());
  443. }
  444. public function getMerchantTop()
  445. {
  446. $date = $this->request->param('date', 'lately7');
  447. $type = $this->request->param('type', 'sales');
  448. $sort = $this->request->param('sort', 'desc');
  449. return app('json')->success(app()->make(CountRepository::class)->getMerchantTop($date, $type, $sort));
  450. }
  451. /**
  452. * 数据大屏接口
  453. * @param $key
  454. * @return \think\response\Json
  455. * @author Qinii
  456. * @day 2023/12/4
  457. */
  458. public function data_screen($key)
  459. {
  460. $param['pid'] = $this->request->param('pid', 0);
  461. $data = app()->make(DataScreenRepository::class)->dataScreen($key, $param);
  462. return app('json')->success($data);
  463. }
  464. /**
  465. * 搜索获取菜单列表
  466. * @return void
  467. * @throws DataNotFoundException
  468. * @throws DbException
  469. * @throws ModelNotFoundException
  470. */
  471. public function getMenusList()
  472. {
  473. $param = $this->request->param([
  474. 'keyword','is_mer'
  475. ]);
  476. if(!isset($param['is_mer'])){
  477. throw new ValidateException('参数错误,请稍后重试');
  478. }
  479. $menuRepository = app()->make(MenuRepository::class);// 获取系统菜单服务实例
  480. $menusList = $menuRepository->getSearch([])->where([
  481. ['is_menu','=',1],
  482. ['is_mer','=',$param['is_mer']],
  483. ['pid', '>', 0],
  484. ])->field('menu_name,menu_id,route')->limit(0,10)->select()->toArray();// 查询菜单列表
  485. if(isset($param['keyword']) && $param['keyword']){
  486. $menusList = $menuRepository->getSearch([])->where(['is_menu'=>1,'is_mer'=>$param['is_mer']])->whereLike('menu_name','%' . $param['keyword'] . '%')->field('menu_name,menu_id,route')->select()->toArray();// 查询菜单列表
  487. $configRepository = app()->make(ConfigRepository::class);// 获取系统配置服务实例
  488. $configClassifyRepository = app()->make(ConfigClassifyRepository::class);// 获取系统配置分类服务实例
  489. $configList = $configRepository->getSearch([])->where(['status'=>1])->whereLike('config_name', '%' . $param['keyword'] . '%')->field('config_id,config_classify_id,config_name')->select()->toArray();
  490. $configClassifyList = $configClassifyRepository->getSearch([])->where(['status'=>1])->whereLike('classify_name', '%' . $param['keyword'] . '%')->field('config_classify_id,classify_name')->select()->toArray();
  491. $configAllList = array_merge($configList,$configClassifyList);//分类配置合并分类项
  492. $configClassifyIds = array_unique(array_column($configAllList, 'config_classify_id'));
  493. $configClassifyMenuArray = $configClassifyRepository->getSearch([])->whereIn('config_classify_id',$configClassifyIds)->field('menu_id,classify_name')->select()->toArray();//通过配置分类以及配置项获取菜单ID
  494. //拼接配置分类名称
  495. if(!empty($configClassifyMenuArray)){
  496. foreach ($configClassifyMenuArray as $item){
  497. $menuInfo = $menuRepository->getSearch([])->where(['is_mer'=>$param['is_mer']])->whereIn('menu_id',$item['menu_id'])->field('menu_name,menu_id,route')->find();// 查询菜单详情
  498. if(!empty($menuInfo)){
  499. $menuInfo['menu_name'] .= '-'.$item['classify_name'];
  500. $menusList[] = $menuInfo;
  501. }
  502. }
  503. }
  504. }
  505. //路由拼接模块名
  506. if(!empty($menusList)){
  507. $moduleName = $param['is_mer'] ? config('admin.merchant_prefix') : config('admin.admin_prefix');
  508. foreach ($menusList as &$item){
  509. if(isset($item['route']) && $item['route']){
  510. $item['route'] = '/' . $moduleName. $item['route'];
  511. }
  512. }
  513. }
  514. return app('json')->success($menusList);
  515. }
  516. public function getSystemInfo()
  517. {
  518. $info['server'] = [
  519. ['name' => '服务器系统', 'require' => '类UNIX', 'value' => PHP_OS],
  520. ['name' => 'WEB环境', 'require' => 'Swoole', 'value' => phpversion('swoole')],
  521. ];
  522. $gd_info = function_exists('gd_info') ? gd_info() : array();
  523. $info['environment'] = [
  524. ['name' => 'PHP版本', 'require' => '7.1-7.4', 'value' => phpversion()],
  525. ['name' => 'MySql版本', 'require' => '5.6-8.0', 'value' => Db::query("SELECT VERSION()")[0]['VERSION()']],
  526. ['name' => 'MySqli', 'require' => '开启', 'value' => function_exists('mysqli_connect')],
  527. ['name' => 'Openssl', 'require' => '开启', 'value' => function_exists('openssl_encrypt')],
  528. ['name' => 'Session', 'require' => '开启', 'value' => function_exists('session_start')],
  529. ['name' => 'Safe_Mode', 'require' => '开启', 'value' => !ini_get('safe_mode')],
  530. ['name' => 'GD', 'require' => '开启', 'value' => !empty($gd_info['GD Version'])],
  531. ['name' => 'Curl', 'require' => '开启', 'value' => function_exists('curl_init')],
  532. ['name' => 'Bcmath', 'require' => '开启', 'value' => function_exists('bcadd')],
  533. ['name' => 'Upload', 'require' => '开启', 'value' => (bool)ini_get('file_uploads')],
  534. ];
  535. $info['permissions'] = [
  536. ['name' => 'backup', 'require' => '读写', 'value' => is_readable(root_path('backup')) && is_writable(root_path('backup'))],
  537. ['name' => 'public', 'require' => '读写', 'value' => is_readable(root_path('public')) && is_writable(root_path('public'))],
  538. ['name' => 'runtime', 'require' => '读写', 'value' => is_readable(root_path('runtime')) && is_writable(root_path('runtime'))],
  539. ['name' => '.env', 'require' => '读写', 'value' => is_readable(root_path() . '.env') && is_writable(root_path() . '.env')],
  540. ['name' => '.version', 'require' => '读写', 'value' => is_readable(root_path() . '.version') && is_writable(root_path() . '.version')],
  541. ['name' => '.constant', 'require' => '读写', 'value' => is_readable(root_path() . '.constant') && is_writable(root_path() . '.constant')],
  542. ];
  543. if (function_exists('exec')) {
  544. $workermanOutput = $timerOutput = $queueOutput = [];
  545. //exec("ps aux | grep 'php think timer' | grep -v grep", $timerOutput);
  546. exec("ps aux | grep 'php think queue' | grep -v grep", $queueOutput);
  547. $info['process'] = [//['name' => '定时任务', 'require' => '开启', 'value' => count($timerOutput) > 0],
  548. ['name' => '消息队列', 'require' => '开启', 'value' => count($queueOutput) > 0],];
  549. }
  550. return app('json')->success($info);
  551. }
  552. }