SystemConfigServices.php 48 KB

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