SystemConfigServices.php 55 KB

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