SystemConfigServices.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\system\config;
  12. use app\dao\system\config\SystemConfigDao;
  13. use app\services\agent\AgentManageServices;
  14. use app\services\BaseServices;
  15. use crmeb\exceptions\AdminException;
  16. use crmeb\services\FileService;
  17. use crmeb\services\FormBuilder;
  18. use think\facade\Log;
  19. /**
  20. * 系统配置
  21. * Class SystemConfigServices
  22. * @package app\services\system\config
  23. * @method count(array $where = []) 获取指定条件下的count
  24. * @method save(array $data) 保存数据
  25. * @method get(int $id, ?array $field = []) 获取一条数据
  26. * @method update($id, array $data, ?string $key = null) 修改数据
  27. * @method delete(int $id, ?string $key = null) 删除数据
  28. * @method getUploadTypeList(string $configName) 获取上传配置中的上传类型
  29. */
  30. class SystemConfigServices extends BaseServices
  31. {
  32. /**
  33. * form表单句柄
  34. * @var FormBuilder
  35. */
  36. protected $builder;
  37. /**
  38. * 表单数据切割符号
  39. * @var string
  40. */
  41. protected $cuttingStr = '=>';
  42. /**
  43. * 表单提交url
  44. * @var string[]
  45. */
  46. protected $postUrl = [
  47. 'setting' => [
  48. 'url' => '/setting/config/save_basics',
  49. 'auth' => [],
  50. ],
  51. 'serve' => [
  52. 'url' => '/serve/sms_config/save_basics',
  53. 'auth' => ['short_letter_switch'],
  54. ],
  55. 'freight' => [
  56. 'url' => '/freight/config/save_basics',
  57. 'auth' => ['express'],
  58. ],
  59. 'agent' => [
  60. 'url' => '/agent/config/save_basics',
  61. 'auth' => ['fenxiao'],
  62. ],
  63. 'marketing' => [
  64. 'url' => '/marketing/integral_config/save_basics',
  65. 'auth' => ['point'],
  66. ]
  67. ];
  68. /**
  69. * 子集控制规则
  70. * @var array[]
  71. */
  72. protected $relatedRule = [
  73. 'brokerage_func_status' => [
  74. 'son_type' => [
  75. 'store_brokerage_statu' => [
  76. 'son_type' => ['store_brokerage_price' => ''],
  77. 'show_value' => 3
  78. ],
  79. 'brokerage_bindind' => '',
  80. 'store_brokerage_binding_status' => [
  81. 'son_type' => ['store_brokerage_binding_time' => ''],
  82. 'show_value' => 2
  83. ],
  84. 'spread_banner' => '',
  85. ],
  86. 'show_value' => 1
  87. ],
  88. 'brokerage_user_status' => [
  89. 'son_type' => [
  90. 'uni_brokerage_price' => '',
  91. 'day_brokerage_price_upper' => '',
  92. ],
  93. 'show_value' => 1
  94. ],
  95. 'wss_open' => [
  96. 'son_type' => [
  97. 'wss_local_cert' => '',
  98. 'wss_local_pk' => '',
  99. ],
  100. 'show_value' => 1
  101. ],
  102. 'invoice_func_status' => [
  103. 'son_type' => [
  104. 'special_invoice_status' => '',
  105. ],
  106. 'show_value' => 1
  107. ],
  108. 'member_func_status' => [
  109. 'son_type' => [
  110. 'order_give_exp' => '',
  111. 'sign_give_exp' => '',
  112. 'invite_user_exp' => ''
  113. ],
  114. 'show_value' => 1
  115. ],
  116. 'balance_func_status' => [
  117. 'son_type' => [
  118. 'recharge_attention' => '',
  119. 'recharge_switch' => '',
  120. 'store_user_min_recharge' => '',
  121. ],
  122. 'show_value' => 1
  123. ],
  124. 'ali_pay_status' => [
  125. 'son_type' => [
  126. 'ali_pay_appid' => '',
  127. 'alipay_merchant_private_key' => '',
  128. 'alipay_public_key' => '',
  129. ],
  130. 'show_value' => 1
  131. ],
  132. 'pay_weixin_open' => [
  133. 'son_type' => [
  134. 'pay_weixin_mchid' => '',
  135. 'pay_wechat_type' => [
  136. 'son_type' => [
  137. 'pay_weixin_key' => '',
  138. ],
  139. 'show_value' => 0
  140. ],
  141. 'pay_wechat_type@' => [
  142. 'son_type' => [
  143. 'pay_weixin_serial_no' => '',
  144. 'pay_weixin_key_v3' => ''
  145. ],
  146. 'show_value' => 1
  147. ],
  148. 'pay_weixin_client_cert' => '',
  149. 'pay_weixin_client_key' => '',
  150. 'paydir' => '',
  151. ],
  152. 'show_value' => 1
  153. ],
  154. 'image_watermark_status' => [
  155. 'son_type' => [
  156. 'watermark_type' => [
  157. 'son_type' => [
  158. 'watermark_image' => '',
  159. 'watermark_opacity' => '',
  160. 'watermark_rotate' => '',
  161. ],
  162. 'show_value' => 1
  163. ],
  164. 'watermark_position' => '',
  165. 'watermark_x' => '',
  166. 'watermark_y' => '',
  167. 'watermark_type@' => [
  168. 'son_type' => [
  169. 'watermark_text' => '',
  170. 'watermark_text_size' => '',
  171. 'watermark_text_color' => '',
  172. 'watermark_text_angle' => ''
  173. ],
  174. 'show_value' => 2
  175. ],
  176. ],
  177. 'show_value' => 1
  178. ],
  179. 'customer_type' => [
  180. 'son_type' => [
  181. 'customer_phone' => '',
  182. ],
  183. 'show_value' => 1
  184. ],
  185. 'customer_type@' => [
  186. 'son_type' => [
  187. 'customer_url' => '',
  188. 'customer_corpId' => '',
  189. ],
  190. 'show_value' => 2
  191. ],
  192. 'pay_new_weixin_open' => [
  193. 'son_type' => [
  194. 'pay_new_weixin_mchid' => ''
  195. ],
  196. 'show_value' => 1
  197. ]
  198. ];
  199. /**
  200. * SystemConfigServices constructor.
  201. * @param SystemConfigDao $dao
  202. */
  203. public function __construct(SystemConfigDao $dao, FormBuilder $builder)
  204. {
  205. $this->dao = $dao;
  206. $this->builder = $builder;
  207. }
  208. public function getSonConfig()
  209. {
  210. $sonConfig = [];
  211. $rolateRule = $this->relatedRule;
  212. if ($rolateRule) {
  213. foreach ($rolateRule as $key => $value) {
  214. $sonConfig = array_merge($sonConfig, array_keys($value['son_type']));
  215. foreach ($value['son_type'] as $k => $v) {
  216. if (isset($v['son_type'])) {
  217. $sonConfig = array_merge($sonConfig, array_keys($v['son_type']));
  218. }
  219. }
  220. }
  221. }
  222. return $sonConfig;
  223. }
  224. /**
  225. * 获取单个系统配置
  226. * @param string $configName
  227. * @param null $default
  228. * @return mixed|null
  229. */
  230. public function getConfigValue(string $configName, $default = null)
  231. {
  232. $value = $this->dao->getConfigValue($configName);
  233. return is_null($value) ? $default : json_decode($value, true);
  234. }
  235. /**
  236. * 获取全部配置
  237. * @param array $configName
  238. * @return array
  239. */
  240. public function getConfigAll(array $configName = [])
  241. {
  242. return array_map(function ($item) {
  243. return json_decode($item, true);
  244. }, $this->dao->getConfigAll($configName));
  245. }
  246. /**
  247. * 获取配置并分页
  248. * @param array $where
  249. * @return array
  250. * @throws \think\db\exception\DataNotFoundException
  251. * @throws \think\db\exception\DbException
  252. * @throws \think\db\exception\ModelNotFoundException
  253. */
  254. public function getConfigList(array $where)
  255. {
  256. [$page, $limit] = $this->getPageValue();
  257. $list = $this->dao->getConfigList($where, $page, $limit);
  258. $count = $this->dao->count($where);
  259. $tidy_srr = [];
  260. foreach ($list as &$item) {
  261. $item['value'] = $item['value'] ? json_decode($item['value'], true) ?: '' : '';
  262. if ($item['type'] == 'radio' || $item['type'] == 'checkbox') {
  263. $item['value'] = $this->getRadioOrCheckboxValueInfo($item['menu_name'], $item['value']);
  264. }
  265. if ($item['type'] == 'upload' && !empty($item['value'])) {
  266. if ($item['upload_type'] == 1 || $item['upload_type'] == 3) {
  267. $item['value'] = [set_file_url($item['value'])];
  268. } elseif ($item['upload_type'] == 2) {
  269. $item['value'] = set_file_url($item['value']);
  270. }
  271. foreach ($item['value'] as $key => $value) {
  272. $tidy_srr[$key]['filepath'] = $value;
  273. $tidy_srr[$key]['filename'] = basename($value);
  274. }
  275. $item['value'] = $tidy_srr;
  276. }
  277. }
  278. return compact('count', 'list');
  279. }
  280. /**
  281. * 获取单选按钮或者多选按钮的显示值
  282. * @param $menu_name
  283. * @param $value
  284. * @return string
  285. * @throws \think\db\exception\DataNotFoundException
  286. * @throws \think\db\exception\ModelNotFoundException
  287. * @throws \think\exception\DbException
  288. */
  289. public function getRadioOrCheckboxValueInfo(string $menu_name, $value): string
  290. {
  291. $option = [];
  292. $config_one = $this->dao->getOne(['menu_name' => $menu_name]);
  293. if (!$config_one) {
  294. return '';
  295. }
  296. $parameter = explode("\n", $config_one['parameter']);
  297. foreach ($parameter as $k => $v) {
  298. if (isset($v) && strlen($v) > 0) {
  299. $data = explode('=>', $v);
  300. $option[$data[0]] = $data[1];
  301. }
  302. }
  303. $str = '';
  304. if (is_array($value)) {
  305. foreach ($value as $v) {
  306. $str .= $option[$v] . ',';
  307. }
  308. } else {
  309. $str .= !empty($value) ? $option[$value] ?? '' : $option[0] ?? '';
  310. }
  311. return $str;
  312. }
  313. /**
  314. * 获取系统配置信息
  315. * @param int $tabId
  316. * @return array
  317. * @throws \think\db\exception\DataNotFoundException
  318. * @throws \think\db\exception\DbException
  319. * @throws \think\db\exception\ModelNotFoundException
  320. */
  321. public function getReadList(int $tabId)
  322. {
  323. $info = $this->dao->getConfigTabAllList($tabId);
  324. foreach ($info as $k => $v) {
  325. if (!is_null(json_decode($v['value'])))
  326. $info[$k]['value'] = json_decode($v['value'], true);
  327. if ($v['type'] == 'upload' && !empty($v['value'])) {
  328. if ($v['upload_type'] == 1 || $v['upload_type'] == 3) $info[$k]['value'] = explode(',', $v['value']);
  329. }
  330. }
  331. return $info;
  332. }
  333. /**
  334. * 创建单行表单
  335. * @param string $type
  336. * @param array $data
  337. * @return array
  338. */
  339. public function createTextForm(string $type, array $data)
  340. {
  341. $formbuider = [];
  342. switch ($type) {
  343. case 'input':
  344. $data['value'] = isset($data['value']) ? json_decode($data['value'], true) : '';
  345. $formbuider[] = $this->builder->input($data['menu_name'], $data['info'], $data['value'])->info($data['desc'])->placeholder($data['desc'])->col(13);
  346. break;
  347. case 'number':
  348. $data['value'] = isset($data['value']) ? json_decode($data['value'], true) : 0;
  349. $formbuider[] = $this->builder->number($data['menu_name'], $data['info'], (float)$data['value'])->info($data['desc']);
  350. break;
  351. case 'dateTime':
  352. $formbuider[] = $this->builder->dateTime($data['menu_name'], $data['info'], $data['value'])->info($data['desc']);
  353. break;
  354. case 'color':
  355. $data['value'] = isset($data['value']) ? json_decode($data['value'], true) : '';
  356. $formbuider[] = $this->builder->color($data['menu_name'], $data['info'], $data['value'])->info($data['desc']);
  357. break;
  358. default:
  359. $data['value'] = isset($data['value']) ? json_decode($data['value'], true) : '';
  360. $formbuider[] = $this->builder->input($data['menu_name'], $data['info'], $data['value'])->info($data['desc'])->placeholder($data['desc'])->col(13);
  361. break;
  362. }
  363. return $formbuider;
  364. }
  365. /**
  366. * 创建多行文本框
  367. * @param array $data
  368. * @return mixed
  369. */
  370. public function createTextareaForm(array $data)
  371. {
  372. $data['value'] = json_decode($data['value'], true) ?: '';
  373. $formbuider[] = $this->builder->textarea($data['menu_name'], $data['info'], $data['value'])->placeholder($data['desc'])->info($data['desc'])->rows(6)->col(13);
  374. return $formbuider;
  375. }
  376. /**
  377. * 创建当选表单
  378. * @param array $data
  379. * @param array $control
  380. * @param array $control_two
  381. * @return array
  382. */
  383. public function createRadioForm(array $data, $control = [], $control_two = [])
  384. {
  385. $formbuider = [];
  386. $data['value'] = json_decode($data['value'], true) ?: '0';
  387. $parameter = explode("\n", $data['parameter']);
  388. $options = [];
  389. if ($parameter) {
  390. foreach ($parameter as $v) {
  391. if (strstr($v, $this->cuttingStr) !== false) {
  392. $pdata = explode($this->cuttingStr, $v);
  393. $options[] = ['label' => $pdata[1], 'value' => (int)$pdata[0]];
  394. }
  395. }
  396. $formbuider[] = $radio = $this->builder->radio($data['menu_name'], $data['info'], (int)$data['value'])->options($options)->info($data['desc'])->col(13);
  397. if ($control) {
  398. $radio->appendControl($data['show_value'] ?? 1, is_array($control) ? $control : [$control]);
  399. }
  400. if ($control_two && isset($data['show_value2'])) {
  401. $radio->appendControl($data['show_value2'] ?? 2, is_array($control_two) ? $control_two : [$control_two]);
  402. }
  403. return $formbuider;
  404. }
  405. }
  406. /**
  407. * 创建上传组件表单
  408. * @param int $type
  409. * @param array $data
  410. * @return array
  411. */
  412. public function createUploadForm(int $type, array $data)
  413. {
  414. $formbuider = [];
  415. switch ($type) {
  416. case 1:
  417. $data['value'] = json_decode($data['value'], true) ?: '';
  418. if ($data['value'] != '') $data['value'] = set_file_url($data['value']);
  419. $formbuider[] = $this->builder->frameImage($data['menu_name'], $data['info'], $this->url('admin/widget.images/index', ['fodder' => $data['menu_name']], true), $data['value'])
  420. ->icon('ios-image')->width('950px')->height('505px')->modal(['footer-hide' => true])->info($data['desc'])->col(13);
  421. break;
  422. case 2:
  423. $data['value'] = json_decode($data['value'], true) ?: [];
  424. if ($data['value'])
  425. $data['value'] = set_file_url($data['value']);
  426. $formbuider[] = $this->builder->frameImages($data['menu_name'], $data['info'], $this->url('admin/widget.images/index', ['fodder' => $data['menu_name'], 'type' => 'many', 'maxLength' => 5], true), $data['value'])
  427. ->maxLength(5)->icon('ios-images')->width('950px')->height('505px')->modal(['footer-hide' => true])
  428. ->info($data['desc'])->col(13);
  429. break;
  430. case 3:
  431. $data['value'] = json_decode($data['value'], true) ?: '';
  432. if ($data['value'] != '') $data['value'] = set_file_url($data['value']);
  433. $formbuider[] = $this->builder->uploadFile($data['menu_name'], $data['info'], $this->url('/adminapi/file/upload/1', ['type' => 1], false, true), $data['value'])
  434. ->name('file')->info($data['desc'])->col(13)->data(['menu_name' => $data['menu_name']])->headers([
  435. 'Authori-zation' => app()->request->header('Authori-zation'),
  436. ]);
  437. break;
  438. }
  439. return $formbuider;
  440. }
  441. /**
  442. * 创建单选框
  443. * @param array $data
  444. * @return array
  445. * @throws \FormBuilder\Exception\FormBuilderException
  446. */
  447. public function createCheckboxForm(array $data)
  448. {
  449. $formbuider = [];
  450. $data['value'] = json_decode($data['value'], true) ?: [];
  451. $parameter = explode("\n", $data['parameter']);
  452. $options = [];
  453. if ($parameter) {
  454. foreach ($parameter as $v) {
  455. if (strstr($v, $this->cuttingStr) !== false) {
  456. $pdata = explode($this->cuttingStr, $v);
  457. $options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
  458. }
  459. }
  460. $formbuider[] = $this->builder->checkbox($data['menu_name'], $data['info'], $data['value'])->options($options)->info($data['desc'])->col(13);
  461. }
  462. return $formbuider;
  463. }
  464. /**
  465. * 创建选择框表单
  466. * @param array $data
  467. * @return array
  468. * @throws \FormBuilder\Exception\FormBuilderException
  469. */
  470. public function createSelectForm(array $data)
  471. {
  472. $formbuider = [];
  473. $data['value'] = json_decode($data['value'], true) ?: [];
  474. $parameter = explode("\n", $data['parameter']);
  475. $options = [];
  476. if ($parameter) {
  477. foreach ($parameter as $v) {
  478. if (strstr($v, $this->cuttingStr) !== false) {
  479. $pdata = explode($this->cuttingStr, $v);
  480. $options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
  481. }
  482. }
  483. $formbuider[] = $this->builder->select($data['menu_name'], $data['info'], $data['value'])->options($options)->info($data['desc'])->col(13);
  484. }
  485. return $formbuider;
  486. }
  487. /**
  488. * 创建颜色选择器
  489. * @param array $data
  490. * @return mixed
  491. */
  492. public function createColorForm(array $data)
  493. {
  494. $data['value'] = json_decode($data['value'], true) ?: '';
  495. $formbuider[] = $this->builder->color($data['menu_name'], $data['info'], $data['value'])->info($data['desc'])->col(13);
  496. return $formbuider;
  497. }
  498. public function bindBuilderData($data, $relatedRule)
  499. {
  500. if (!$data) return false;
  501. $p_list = array();
  502. foreach ($relatedRule as $rk => $rv) {
  503. $p_list[$rk] = $data[$rk];
  504. if (isset($rv['son_type']) && is_array($rv['son_type'])) {
  505. foreach ($rv['son_type'] as $sk => $sv) {
  506. if (is_array($sv) && isset($sv['son_type'])) {
  507. foreach ($sv['son_type'] as $ssk => $ssv) {
  508. $tmp = $data[$sk];
  509. $tmp['console'] = $data[$ssk];
  510. $p_list[$rk]['console'][] = $tmp;
  511. }
  512. } else {
  513. $p_list[$rk]['console'][] = $data[$sk];
  514. }
  515. }
  516. }
  517. }
  518. return array_values($p_list);
  519. }
  520. /**
  521. * 获取系统配置表单
  522. * @param int $id
  523. * @param array $formData
  524. * @return array
  525. * @throws \think\db\exception\DataNotFoundException
  526. * @throws \think\db\exception\DbException
  527. * @throws \think\db\exception\ModelNotFoundException
  528. */
  529. public function formTypeShine($data, $control = false, $controle_two = [])
  530. {
  531. switch ($data['type']) {
  532. case 'text'://文本框
  533. return $this->createTextForm($data['input_type'], $data);
  534. case 'radio'://单选框
  535. return $this->createRadioForm($data, $control, $controle_two);
  536. case 'textarea'://多行文本框
  537. return $this->createTextareaForm($data);
  538. case 'upload'://文件上传
  539. return $this->createUploadForm((int)$data['upload_type'], $data);
  540. case 'checkbox'://多选框
  541. return $this->createCheckboxForm($data);
  542. case 'select'://多选框
  543. return $this->createSelectForm($data);
  544. case 'color':
  545. return $this->createColorForm($data);
  546. }
  547. }
  548. /**
  549. * @param int $tabId
  550. * @param array $formData
  551. * @param array $relatedRule
  552. * @return array|bool
  553. * @throws \think\db\exception\DataNotFoundException
  554. * @throws \think\db\exception\DbException
  555. * @throws \think\db\exception\ModelNotFoundException
  556. */
  557. public function createConfigForm(int $tabId, array $relatedRule)
  558. {
  559. $list = $this->dao->getConfigTabAllList($tabId);
  560. if (!$relatedRule) {
  561. $formbuider = $this->createNoCrontrolForm($list);
  562. } else {
  563. $formbuider = $this->createBindCrontrolForm($list, $relatedRule);
  564. }
  565. return $formbuider;
  566. }
  567. /**
  568. * 创建
  569. * @param array $list
  570. * @return array
  571. * @throws \FormBuilder\Exception\FormBuilderException
  572. * @throws \think\db\exception\DataNotFoundException
  573. * @throws \think\db\exception\DbException
  574. * @throws \think\db\exception\ModelNotFoundException
  575. */
  576. public function createForm(array $list)
  577. {
  578. if (!$list) return [];
  579. $list = array_combine(array_column($list, 'menu_name'), $list);
  580. $formbuider = [];
  581. $relateRule = $this->relatedRule;
  582. $sonConfig = $this->getSonConfig();
  583. foreach ($list as $key => $data) {
  584. if (in_array($key, $sonConfig)) {
  585. continue;
  586. }
  587. switch ($data['type']) {
  588. case 'text'://文本框
  589. $formbuider = array_merge($formbuider, $this->createTextForm($data['input_type'], $data));
  590. break;
  591. case 'radio'://单选框
  592. $builder = [];
  593. if (isset($relateRule[$key])) {
  594. $role = $relateRule[$key];
  595. $data['show_value'] = $role['show_value'];
  596. foreach ($role['son_type'] as $sk => $sv) {
  597. if (isset($list[$sk])) {
  598. $son_data = $list[$sk];
  599. $son_data['show_value'] = $role['show_value'];
  600. $son_build = [];
  601. if (isset($sv['son_type'])) {
  602. foreach ($sv['son_type'] as $ssk => $ssv) {
  603. $son_data['show_value'] = $sv['show_value'];
  604. $son_build[] = $this->formTypeShine($list[$ssk])[0];
  605. unset($list[$ssk]);
  606. }
  607. }
  608. $son_build_two = [];
  609. if (isset($role['son_type'][$sk . '@'])) {
  610. $son_type_two = $role['son_type'][$sk . '@'];
  611. $son_data['show_value2'] = $son_type_two['show_value'];
  612. if (isset($son_type_two['son_type'])) {
  613. foreach ($son_type_two['son_type'] as $ssk => $ssv) {
  614. if (isset($list[$ssk]['menu_name']) && $list[$ssk]['menu_name'] == 'watermark_text_color') $list[$ssk]['type'] = 'color';
  615. $son_build_two[] = $this->formTypeShine($list[$ssk])[0];
  616. unset($list[$ssk]);
  617. }
  618. }
  619. }
  620. $builder[] = $this->formTypeShine($son_data, $son_build, $son_build_two)[0];
  621. unset($list[$sk]);
  622. }
  623. }
  624. $data['show_value'] = $role['show_value'];
  625. }
  626. $builder_two = [];
  627. if (isset($relateRule[$key . '@'])) {
  628. $role = $relateRule[$key . '@'];
  629. $data['show_value2'] = $role['show_value'];
  630. foreach ($role['son_type'] as $sk => $sv) {
  631. $son_data = $list[$sk];
  632. $son_data['show_value'] = $role['show_value'];
  633. $builder_two[] = $this->formTypeShine($son_data)[0];
  634. }
  635. }
  636. $formbuider = array_merge($formbuider, $this->createRadioForm($data, $builder, $builder_two));
  637. break;
  638. case 'textarea'://多行文本框
  639. $formbuider = array_merge($formbuider, $this->createTextareaForm($data));
  640. break;
  641. case 'upload'://文件上传
  642. $formbuider = array_merge($formbuider, $this->createUploadForm((int)$data['upload_type'], $data));
  643. break;
  644. case 'checkbox'://多选框
  645. $formbuider = array_merge($formbuider, $this->createCheckboxForm($data));
  646. break;
  647. case 'select'://多选框
  648. $formbuider = array_merge($formbuider, $this->createSelectForm($data));
  649. break;
  650. }
  651. }
  652. return $formbuider;
  653. }
  654. /**无组件绑定规则
  655. * @param array $list
  656. * @return array|bool
  657. * @throws \FormBuilder\Exception\FormBuilderException
  658. * @throws \think\db\exception\DataNotFoundException
  659. * @throws \think\db\exception\DbException
  660. * @throws \think\db\exception\ModelNotFoundException
  661. */
  662. public function createNoCrontrolForm(array $list)
  663. {
  664. if (!$list) return false;
  665. $formbuider = [];
  666. foreach ($list as $key => $data) {
  667. switch ($data['type']) {
  668. case 'text'://文本框
  669. $formbuider = array_merge($formbuider, $this->createTextForm($data['input_type'], $data));
  670. break;
  671. case 'radio'://单选框
  672. $formbuider = array_merge($formbuider, $this->createRadioForm($data));
  673. break;
  674. case 'textarea'://多行文本框
  675. $formbuider = array_merge($formbuider, $this->createTextareaForm($data));
  676. break;
  677. case 'upload'://文件上传
  678. $formbuider = array_merge($formbuider, $this->createUploadForm((int)$data['upload_type'], $data));
  679. break;
  680. case 'checkbox'://多选框
  681. $formbuider = array_merge($formbuider, $this->createCheckboxForm($data));
  682. break;
  683. case 'select'://多选框
  684. $formbuider = array_merge($formbuider, $this->createSelectForm($data));
  685. break;
  686. }
  687. }
  688. return $formbuider;
  689. }
  690. /**
  691. * 有组件绑定规则
  692. * @param array $list
  693. * @param array $relatedRule
  694. * @return array|bool
  695. * @throws \FormBuilder\Exception\FormBuilderException
  696. * @throws \think\db\exception\DataNotFoundException
  697. * @throws \think\db\exception\DbException
  698. * @throws \think\db\exception\ModelNotFoundException
  699. */
  700. public function createBindCrontrolForm(array $list, array $relatedRule)
  701. {
  702. if (!$list || !$relatedRule) return false;
  703. $formbuider = [];
  704. $new_data = array();
  705. foreach ($list as $dk => $dv) {
  706. $new_data[$dv['menu_name']] = $dv;
  707. }
  708. foreach ($relatedRule as $rk => $rv) {
  709. if (isset($rv['son_type'])) {
  710. $data = $new_data[$rk];
  711. switch ($data['type']) {
  712. case 'text'://文本框
  713. $formbuider = array_merge($formbuider, $this->createTextForm($data['input_type'], $data));
  714. break;
  715. case 'radio'://单选框
  716. $son_builder = array();
  717. foreach ($rv['son_type'] as $sk => $sv) {
  718. if (isset($sv['son_type'])) {
  719. foreach ($sv['son_type'] as $ssk => $ssv) {
  720. $son_data = $new_data[$sk];
  721. $son_data['show_value'] = $sv['show_value'];
  722. $son_builder[] = $this->formTypeShine($son_data, $this->formTypeShine($new_data[$ssk])[0])[0];
  723. }
  724. } else {
  725. $son_data = $new_data[$sk];
  726. $son_data['show_value'] = $rv['show_value'];
  727. $son_builder[] = $this->formTypeShine($son_data)[0];
  728. }
  729. }
  730. $formbuider = array_merge($formbuider, $this->createRadioForm($data, $son_builder));
  731. break;
  732. case 'textarea'://多行文本框
  733. $formbuider = array_merge($formbuider, $this->createTextareaForm($data));
  734. break;
  735. case 'upload'://文件上传
  736. $formbuider = array_merge($formbuider, $this->createUploadForm((int)$data['upload_type'], $data));
  737. break;
  738. case 'checkbox'://多选框
  739. $formbuider = array_merge($formbuider, $this->createCheckboxForm($data));
  740. break;
  741. case 'select'://多选框
  742. $formbuider = array_merge($formbuider, $this->createSelectForm($data));
  743. break;
  744. }
  745. }
  746. }
  747. return $formbuider;
  748. }
  749. /**
  750. * 系统配置form表单创建
  751. * @param int $tabId
  752. * @return array
  753. * @throws \FormBuilder\Exception\FormBuilderException
  754. * @throws \think\db\exception\DataNotFoundException
  755. * @throws \think\db\exception\DbException
  756. * @throws \think\db\exception\ModelNotFoundException
  757. */
  758. public function getConfigForm($url, int $tabId)
  759. {
  760. /** @var SystemConfigTabServices $service */
  761. $service = app()->make(SystemConfigTabServices::class);
  762. $title = $service->value(['id' => $tabId], 'title');
  763. $list = $this->dao->getConfigTabAllList($tabId);
  764. $formbuider = $this->createForm($list);
  765. $name = 'setting';
  766. if ($url) {
  767. $name = explode('/', $url)[2] ?? $name;
  768. }
  769. $postUrl = $this->postUrl[$name]['url'] ?? '/setting/config/save_basics';
  770. return create_form($title, $formbuider, $this->url($postUrl), 'POST');
  771. }
  772. /**
  773. * 新增路由增加设置项验证
  774. * @param $url
  775. * @param $post
  776. * @return bool
  777. */
  778. public function checkParam($url, $post)
  779. {
  780. $name = '';
  781. if ($url) {
  782. $name = explode('/', $url)[2] ?? $name;
  783. }
  784. $auth = $this->postUrl[$name]['auth'] ?? false;
  785. if ($auth === false) {
  786. throw new AdminException(400601);
  787. }
  788. if ($auth) {
  789. /** @var SystemConfigTabServices $systemConfigTabServices */
  790. $systemConfigTabServices = app()->make(SystemConfigTabServices::class);
  791. foreach ($post as $key => $value) {
  792. $tab_ids = $systemConfigTabServices->getColumn([['eng_title', 'IN', $auth]], 'id');
  793. if (!$tab_ids || !in_array($key, $this->dao->getColumn([['config_tab_id', 'IN', $tab_ids]], 'menu_name'))) {
  794. throw new AdminException(400602);
  795. }
  796. }
  797. }
  798. return true;
  799. }
  800. /**
  801. * 修改配置获取form表单
  802. * @param int $id
  803. * @return array
  804. * @throws \FormBuilder\Exception\FormBuilderException
  805. * @throws \think\db\exception\DataNotFoundException
  806. * @throws \think\db\exception\DbException
  807. * @throws \think\db\exception\ModelNotFoundException
  808. */
  809. public function editConfigForm(int $id)
  810. {
  811. $menu = $this->dao->get($id)->getData();
  812. if (!$menu) {
  813. throw new AdminException(100026);
  814. }
  815. /** @var SystemConfigTabServices $service */
  816. $service = app()->make(SystemConfigTabServices::class);
  817. $formbuider = [];
  818. $formbuider[] = $this->builder->input('menu_name', '字段变量', $menu['menu_name'])->disabled(1);
  819. $formbuider[] = $this->builder->hidden('type', $menu['type']);
  820. $formbuider[] = $this->builder->select('config_tab_id', '分类', (int)$menu['config_tab_id'])->setOptions($service->getSelectForm());
  821. $formbuider[] = $this->builder->input('info', '配置名称', $menu['info'])->autofocus(1);
  822. $formbuider[] = $this->builder->input('desc', '配置简介', $menu['desc']);
  823. switch ($menu['type']) {
  824. case 'text':
  825. $menu['value'] = json_decode($menu['value'], true);
  826. $formbuider[] = $this->builder->select('input_type', '类型', $menu['input_type'])->setOptions([
  827. ['value' => 'input', 'label' => '文本框']
  828. , ['value' => 'dateTime', 'label' => '时间']
  829. , ['value' => 'color', 'label' => '颜色']
  830. , ['value' => 'number', 'label' => '数字']
  831. ]);
  832. //输入框验证规则
  833. $formbuider[] = $this->builder->input('value', '默认值', $menu['value']);
  834. if (!empty($menu['required'])) {
  835. $formbuider[] = $this->builder->number('width', '文本框宽(%)', (int)$menu['width']);
  836. $formbuider[] = $this->builder->input('required', '验证规则', $menu['required'])->placeholder('多个请用,隔开例如:required:true,url:true');
  837. }
  838. break;
  839. case 'textarea':
  840. $menu['value'] = json_decode($menu['value'], true);
  841. //多行文本
  842. if (!empty($menu['high'])) {
  843. $formbuider[] = $this->builder->textarea('value', '默认值', $menu['value'])->rows(5);
  844. $formbuider[] = $this->builder->number('width', '文本框宽(%)', (int)$menu['width']);
  845. $formbuider[] = $this->builder->number('high', '多行文本框高(%)', (int)$menu['high']);
  846. } else {
  847. $formbuider[] = $this->builder->input('value', '默认值', $menu['value']);
  848. }
  849. break;
  850. case 'radio':
  851. $formbuider = array_merge($formbuider, $this->createRadioForm($menu));
  852. //单选和多选参数配置
  853. if (!empty($menu['parameter'])) {
  854. $formbuider[] = $this->builder->textarea('parameter', '配置参数', $menu['parameter'])->placeholder("参数方式例如:\n1=>白色\n2=>红色\n3=>黑色");
  855. }
  856. break;
  857. case 'checkbox':
  858. $formbuider = array_merge($formbuider, $this->createCheckboxForm($menu));
  859. //单选和多选参数配置
  860. if (!empty($menu['parameter'])) {
  861. $formbuider[] = $this->builder->textarea('parameter', '配置参数', $menu['parameter'])->placeholder("参数方式例如:\n1=>白色\n2=>红色\n3=>黑色");
  862. }
  863. break;
  864. case 'upload':
  865. $formbuider = array_merge($formbuider, $this->createUploadForm(($menu['upload_type']), $menu));
  866. //上传类型选择
  867. if (!empty($menu['upload_type'])) {
  868. $formbuider[] = $this->builder->radio('upload_type', '上传类型', $menu['upload_type'])->options([['value' => 1, 'label' => '单图'], ['value' => 2, 'label' => '多图'], ['value' => 3, 'label' => '文件']]);
  869. }
  870. break;
  871. }
  872. $formbuider[] = $this->builder->number('sort', '排序', (int)$menu['sort']);
  873. $formbuider[] = $this->builder->radio('status', '状态', $menu['status'])->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']]);
  874. return create_form('编辑字段', $formbuider, $this->url('/setting/config/' . $id), 'PUT');
  875. }
  876. /**
  877. * 字段状态
  878. * @return array
  879. */
  880. public function formStatus(): array
  881. {
  882. return [['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']];
  883. }
  884. /**
  885. * 选择文文件类型
  886. * @return array
  887. */
  888. public function uploadType(): array
  889. {
  890. return [
  891. ['value' => 1, 'label' => '单图']
  892. , ['value' => 2, 'label' => '多图']
  893. , ['value' => 3, 'label' => '文件']
  894. ];
  895. }
  896. /**
  897. * 选择文本框类型
  898. * @return array
  899. */
  900. public function textType(): array
  901. {
  902. return [
  903. ['value' => 'input', 'label' => '文本框']
  904. , ['value' => 'dateTime', 'label' => '时间']
  905. , ['value' => 'color', 'label' => '颜色']
  906. , ['value' => 'number', 'label' => '数字']
  907. ];
  908. }
  909. /**
  910. * 获取创建配置规格表单
  911. * @param int $type
  912. * @param int $tab_id
  913. * @return array
  914. */
  915. public function createFormRule(int $type, int $tab_id): array
  916. {
  917. /** @var SystemConfigTabServices $service */
  918. $service = app()->make(SystemConfigTabServices::class);
  919. $formbuider = [];
  920. $form_type = '';
  921. $info_type = [];
  922. $parameter = [];
  923. switch ($type) {
  924. case 0://文本框
  925. $form_type = 'text';
  926. $info_type = $this->builder->select('input_type', '类型')->setOptions($this->textType());
  927. $parameter[] = $this->builder->input('value', '默认值');
  928. $parameter[] = $this->builder->number('width', '文本框宽(%)', 100);
  929. $parameter[] = $this->builder->input('required', '验证规则')->placeholder('多个请用,隔开例如:required:true,url:true');
  930. break;
  931. case 1://多行文本框
  932. $form_type = 'textarea';
  933. $parameter[] = $this->builder->textarea('value', '默认值');
  934. $parameter[] = $this->builder->number('width', '文本框宽(%)', 100);
  935. $parameter[] = $this->builder->number('high', '多行文本框高(%)', 5);
  936. break;
  937. case 2://单选框
  938. $form_type = 'radio';
  939. $parameter[] = $this->builder->textarea('parameter', '配置参数')->placeholder("参数方式例如:\n1=>男\n2=>女\n3=>保密");
  940. $parameter[] = $this->builder->input('value', '默认值');
  941. break;
  942. case 3://文件上传
  943. $form_type = 'upload';
  944. $parameter[] = $this->builder->radio('upload_type', '上传类型', 1)->options($this->uploadType());
  945. break;
  946. case 4://多选框
  947. $form_type = 'checkbox';
  948. $parameter[] = $this->builder->textarea('parameter', '配置参数')->placeholder("参数方式例如:\n1=>白色\n2=>红色\n3=>黑色");
  949. break;
  950. case 5://下拉框
  951. $form_type = 'select';
  952. $parameter[] = $this->builder->textarea('parameter', '配置参数')->placeholder("参数方式例如:\n1=>白色\n2=>红色\n3=>黑色");
  953. break;
  954. }
  955. if ($form_type) {
  956. $formbuider[] = $this->builder->hidden('type', $form_type);
  957. $formbuider[] = $this->builder->select('config_tab_id', '分类', $tab_id)->setOptions($service->getSelectForm());
  958. if ($info_type) {
  959. $formbuider[] = $info_type;
  960. }
  961. $formbuider[] = $this->builder->input('info', '配置名称')->autofocus(1);
  962. $formbuider[] = $this->builder->input('menu_name', '字段变量')->placeholder('例如:site_url');
  963. $formbuider[] = $this->builder->input('desc', '配置简介');
  964. $formbuider = array_merge($formbuider, $parameter);
  965. $formbuider[] = $this->builder->number('sort', '排序', 0);
  966. $formbuider[] = $this->builder->radio('status', '状态', 1)->options($this->formStatus());
  967. }
  968. return create_form('添加字段', $formbuider, $this->url('/setting/config'), 'POST');
  969. }
  970. /**
  971. * radio 和 checkbox规则的判断
  972. * @param $data
  973. * @return bool
  974. */
  975. public function valiDateRadioAndCheckbox($data)
  976. {
  977. $option = [];
  978. $option_new = [];
  979. $data['parameter'] = str_replace("\r\n", "\n", $data['parameter']);//防止不兼容
  980. $parameter = explode("\n", $data['parameter']);
  981. if (count($parameter) < 2) {
  982. throw new AdminException(400603);
  983. }
  984. foreach ($parameter as $k => $v) {
  985. if (isset($v) && !empty($v)) {
  986. $option[$k] = explode('=>', $v);
  987. }
  988. }
  989. if (count($option) < 2) {
  990. throw new AdminException(400603);
  991. }
  992. $bool = 1;
  993. foreach ($option as $k => $v) {
  994. $option_new[$k] = $option[$k][0];
  995. foreach ($v as $kk => $vv) {
  996. $vv_num = strlen($vv);
  997. if (!$vv_num) {
  998. $bool = 0;
  999. }
  1000. }
  1001. }
  1002. if (!$bool) {
  1003. throw new AdminException(400603);
  1004. }
  1005. $num1 = count($option_new);//提取该数组的数目
  1006. $arr2 = array_unique($option_new);//合并相同的元素
  1007. $num2 = count($arr2);//提取合并后数组个数
  1008. if ($num1 > $num2) {
  1009. throw new AdminException(400603);
  1010. }
  1011. return true;
  1012. }
  1013. /**
  1014. * 验证参数
  1015. * @param $data
  1016. * @return bool
  1017. */
  1018. public function valiDateValue($data)
  1019. {
  1020. if (!$data || !isset($data['required']) || !$data['required']) {
  1021. return true;
  1022. }
  1023. $valids = explode(',', $data['required']);
  1024. foreach ($valids as $valid) {
  1025. $valid = explode(':', $valid);
  1026. if (isset($valid[0]) && isset($valid[1])) {
  1027. $k = strtolower(trim($valid[0]));
  1028. $v = strtolower(trim($valid[1]));
  1029. switch ($k) {
  1030. case 'required':
  1031. if ($v == 'true' && $data['value'] === '') {
  1032. throw new AdminException(400604, ['name' => $data['info'] ?? '']);
  1033. }
  1034. break;
  1035. case 'url':
  1036. if ($v == 'true' && !check_link($data['value'])) {
  1037. throw new AdminException(400605, ['name' => $data['info'] ?? '']);
  1038. }
  1039. break;
  1040. }
  1041. }
  1042. }
  1043. }
  1044. /**保存平台电子面单打印信息
  1045. * @param array $data
  1046. * @return bool
  1047. */
  1048. public function saveExpressInfo(array $data)
  1049. {
  1050. if (!is_array($data) || !$data) return false;
  1051. // config_export_id 快递公司id
  1052. // config_export_temp_id 快递公司模板id
  1053. // config_export_com 快递公司编码
  1054. // config_export_to_name 发货人姓名
  1055. // config_export_to_tel 发货人电话
  1056. // config_export_to_address 发货人详细地址
  1057. // config_export_siid 电子面单打印机编号
  1058. foreach ($data as $key => $value) {
  1059. $this->dao->update(['menu_name' => 'config_export_' . $key], ['value' => json_encode($value)]);
  1060. }
  1061. \crmeb\services\CacheService::clear();
  1062. return true;
  1063. }
  1064. /**
  1065. * 获取分享海报 兼容方法
  1066. */
  1067. public function getSpreadBanner()
  1068. {
  1069. //配置
  1070. $banner = sys_config('spread_banner', []);
  1071. if (!$banner) {
  1072. //组合数据
  1073. $banner = sys_data('routine_spread_banner');
  1074. if ($banner) {
  1075. $banner = array_column($banner, 'pic');
  1076. $this->dao->update(['menu_name' => 'spread_banner'], ['value' => json_encode($banner)]);
  1077. \crmeb\services\CacheService::clear();
  1078. }
  1079. }
  1080. return $banner;
  1081. }
  1082. /**
  1083. * 保存wss配置
  1084. * @param int $wssOpen
  1085. * @param string $wssLocalpk
  1086. * @param string $wssLocalCert
  1087. */
  1088. public function saveSslFilePath(int $wssOpen, string $wssLocalpk, string $wssLocalCert)
  1089. {
  1090. $wssFile = root_path() . '.wss';
  1091. $content = <<<WSS
  1092. wssOpen = $wssOpen
  1093. wssLocalpk = $wssLocalpk
  1094. wssLocalCert = $wssLocalCert
  1095. WSS;
  1096. try {
  1097. file_put_contents($wssFile, $content);
  1098. } catch (\Throwable $e) {
  1099. throw new AdminException(400606);
  1100. }
  1101. }
  1102. /**
  1103. * 获取wss配置
  1104. * @param string $key
  1105. * @return array|false|mixed
  1106. */
  1107. public function getSslFilePath(string $key = '')
  1108. {
  1109. $wssFile = root_path() . '.wss';
  1110. try {
  1111. $content = parse_ini_file($wssFile);
  1112. } catch (\Throwable $e) {
  1113. $content = [];
  1114. }
  1115. return $content[$key] ?? $content;
  1116. }
  1117. /**
  1118. * 检测缩略图水印配置是否更改
  1119. * @param array $post
  1120. * @return bool
  1121. */
  1122. public function checkThumbParam(array $post)
  1123. {
  1124. unset($post['upload_type'], $post['image_watermark_status']);
  1125. /** @var SystemConfigTabServices $systemConfigTabServices */
  1126. $systemConfigTabServices = app()->make(SystemConfigTabServices::class);
  1127. //上传配置->基础配置
  1128. $tab_id = $systemConfigTabServices->getColumn(['eng_title' => 'base_config'], 'id');
  1129. if ($tab_id) {
  1130. $all = $this->dao->getColumn(['config_tab_id' => $tab_id], 'value', 'menu_name');
  1131. if (array_intersect(array_keys($all), array_keys($post))) {
  1132. foreach ($post as $key => $item) {
  1133. //配置更改删除原来生成的缩略图
  1134. if (isset($all[$key]) && $item != json_decode($all[$key], true)) {
  1135. try {
  1136. FileService::delDir(public_path('uploads/thumb_water'));
  1137. break;
  1138. } catch (\Throwable $e) {
  1139. }
  1140. }
  1141. }
  1142. }
  1143. }
  1144. return true;
  1145. }
  1146. /**
  1147. * 变更分销绑定关系模式
  1148. * @param array $post
  1149. * @return bool
  1150. */
  1151. public function checkBrokerageBinding(array $post)
  1152. {
  1153. try {
  1154. $config_data = $post['store_brokerage_binding_status'];
  1155. $config_one = $this->dao->getOne(['menu_name' => 'store_brokerage_binding_status']);
  1156. $config_old = json_decode($config_one['value'], true);
  1157. if ($config_old != 2 && $config_data == 2) {
  1158. //自动解绑上级绑定
  1159. /** @var AgentManageServices $agentManage */
  1160. $agentManage = app()->make(AgentManageServices::class);
  1161. $agentManage->resetSpreadTime();
  1162. }
  1163. } catch (\Throwable $e) {
  1164. Log::error('变更分销绑定模式重置绑定时间失败,失败原因:' . $e->getMessage());
  1165. return false;
  1166. }
  1167. return true;
  1168. }
  1169. }