SystemConfigServices.php 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545
  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\jobs\agent\SystemJob;
  14. use app\services\activity\coupon\StoreCouponIssueServices;
  15. use app\services\activity\newcomer\StoreNewcomerServices;
  16. use app\services\BaseServices;
  17. use app\services\other\CacheServices;
  18. use app\services\store\StoreConfigServices;
  19. use app\services\user\UserIntegralServices;
  20. use app\services\user\UserServices;
  21. use crmeb\exceptions\AdminException;
  22. use crmeb\form\Build;
  23. use crmeb\form\components\Alert;
  24. use crmeb\form\components\InputNumber;
  25. use crmeb\form\validate\StrRules;
  26. use crmeb\services\FileService;
  27. use crmeb\services\FormBuilder;
  28. use crmeb\services\wechat\contract\ServeConfigInterface;
  29. use crmeb\traits\ServicesTrait;
  30. use think\exception\ValidateException;
  31. use think\facade\Log;
  32. /**
  33. * 系统配置
  34. * Class SystemConfigServices
  35. * @package app\services\system\config
  36. * @mixin SystemConfigDao
  37. */
  38. class SystemConfigServices extends BaseServices implements ServeConfigInterface
  39. {
  40. use ServicesTrait;
  41. /**
  42. * form表单句柄
  43. * @var FormBuilder
  44. */
  45. protected $builder;
  46. /**
  47. * 表单数据切割符号
  48. * @var string
  49. */
  50. protected $cuttingStr = '=>';
  51. /**
  52. * 表单提交url
  53. * @var string[]
  54. */
  55. protected $postUrl = [
  56. 'setting' => [
  57. 'url' => '/setting/config/save_basics',
  58. 'auth' => [],
  59. ],
  60. 'serve' => [
  61. 'url' => '/serve/sms_config/save_basics',
  62. 'auth' => ['short_letter_switch'],
  63. ],
  64. 'freight' => [
  65. 'url' => '/freight/config/save_basics',
  66. 'auth' => ['express'],
  67. ],
  68. 'agent' => [
  69. 'url' => '/agent/config/save_basics',
  70. 'auth' => ['fenxiao'],
  71. ],
  72. 'marketing' => [
  73. 'url' => '/marketing/integral_config/save_basics',
  74. 'auth' => ['point'],
  75. ],
  76. 'store' => [
  77. 'url' => '/store/finance/header_basics',
  78. 'auth' => [],
  79. ]
  80. ];
  81. /**
  82. * 子集控制规则
  83. * @var array[]
  84. */
  85. protected $relatedRule = [
  86. 'brokerage_func_status' => [
  87. 'son_type' => [
  88. 'store_brokerage_statu' => [
  89. 'son_type' => ['store_brokerage_price' => ''],
  90. 'show_value' => 3
  91. ],
  92. 'brokerage_bindind' => '',
  93. 'store_brokerage_binding_status' => [
  94. 'son_type' => ['store_brokerage_binding_time' => ''],
  95. 'show_value' => 2
  96. ],
  97. 'spread_banner' => '',
  98. ],
  99. 'show_value' => 1
  100. ],
  101. 'brokerage_user_status' => [
  102. 'son_type' => [
  103. 'uni_brokerage_price' => '',
  104. 'day_brokerage_price_upper' => '',
  105. ],
  106. 'show_value' => 1
  107. ],
  108. 'pay_success_printing_switch' => [
  109. 'son_type' => [
  110. 'develop_id' => '',
  111. 'printing_api_key' => '',
  112. 'printing_client_id' => '',
  113. 'terminal_number' => '',
  114. ],
  115. 'show_value' => 1
  116. ],
  117. 'wss_open' => [
  118. 'son_type' => [
  119. 'wss_local_cert' => '',
  120. 'wss_local_pk' => '',
  121. ],
  122. 'show_value' => 1
  123. ],
  124. 'invoice_func_status' => [
  125. 'son_type' => [
  126. 'special_invoice_status' => '',
  127. ],
  128. 'show_value' => 1
  129. ],
  130. 'member_func_status' => [
  131. 'son_type' => [
  132. 'member_price_status' => '',
  133. 'order_give_exp' => '',
  134. 'sign_give_exp' => '',
  135. 'invite_user_exp' => ''
  136. ],
  137. 'show_value' => 1
  138. ],
  139. 'balance_func_status' => [
  140. 'son_type' => [
  141. 'recharge_attention' => '',
  142. 'recharge_switch' => '',
  143. 'store_user_min_recharge' => '',
  144. ],
  145. 'show_value' => 1
  146. ],
  147. 'system_product_copy_type' => [
  148. 'son_type' => [
  149. 'copy_product_apikey' => '',
  150. ],
  151. 'show_value' => 2
  152. ],
  153. 'logistics_type' => [
  154. 'son_type' => [
  155. 'system_express_app_code' => '',
  156. ],
  157. 'show_value' => 2
  158. ],
  159. 'ali_pay_status' => [
  160. 'son_type' => [
  161. 'ali_pay_appid' => '',
  162. 'alipay_merchant_private_key' => '',
  163. 'alipay_public_key' => '',
  164. ],
  165. 'show_value' => 1
  166. ],
  167. 'pay_weixin_open' => [
  168. 'son_type' => [
  169. 'pay_weixin_mchid' => '',
  170. 'pay_weixin_key' => '',
  171. 'pay_weixin_client_cert' => '',
  172. 'pay_weixin_client_key' => '',
  173. 'paydir' => '',
  174. 'pay_routine_open' => ''
  175. ],
  176. 'show_value' => 1
  177. ],
  178. 'pay_routine_open' => [
  179. 'son_type' => [
  180. 'pay_routine_mchid' => ''
  181. ],
  182. 'show_value' => 1
  183. ],
  184. 'config_export_open' => [
  185. 'son_type' => [
  186. 'config_export_to_name' => '',
  187. 'config_export_to_tel' => '',
  188. 'config_export_to_address' => '',
  189. 'config_export_siid' => '',
  190. ],
  191. 'show_value' => 1
  192. ],
  193. 'image_watermark_status' => [
  194. 'son_type' => [
  195. 'watermark_type' => [
  196. 'son_type' => [
  197. 'watermark_image' => '',
  198. 'watermark_opacity' => '',
  199. 'watermark_rotate' => '',
  200. ],
  201. 'show_value' => 1
  202. ],
  203. 'watermark_position' => '',
  204. 'watermark_x' => '',
  205. 'watermark_y' => '',
  206. 'watermark_type@' => [
  207. 'son_type' => [
  208. 'watermark_text' => '',
  209. 'watermark_text_size' => '',
  210. 'watermark_text_color' => '',
  211. 'watermark_text_angle' => ''
  212. ],
  213. 'show_value' => 2
  214. ],
  215. ],
  216. 'show_value' => 1
  217. ],
  218. 'share_qrcode' => [
  219. 'son_type' => [
  220. 'spread_share_forever' => '',
  221. ],
  222. 'show_value' => 1
  223. ],
  224. 'integral_effective_status' => [
  225. 'son_type' => [
  226. 'integral_effective_time' => [
  227. 'son_type' => [
  228. 'next_clear_month_time' => '',
  229. ],
  230. 'show_value' => 1
  231. ],
  232. 'integral_effective_time@' => [
  233. 'son_type' => [
  234. 'next_clear_quarter_time' => '',
  235. ],
  236. 'show_value' => 2
  237. ],
  238. 'integral_effective_time#' => [
  239. 'son_type' => [
  240. 'next_clear_year_time' => '',
  241. ],
  242. 'show_value' => 3
  243. ],
  244. ],
  245. 'show_value' => 1
  246. ],
  247. 'user_extract_bank_status' => [
  248. 'son_type' => [
  249. 'user_extract_bank' => '',
  250. ],
  251. 'show_value' => 1
  252. ],
  253. ];
  254. /**
  255. * SystemConfigServices constructor.
  256. * @param SystemConfigDao $dao
  257. */
  258. public function __construct(SystemConfigDao $dao, FormBuilder $builder)
  259. {
  260. $this->dao = $dao;
  261. $this->builder = $builder;
  262. }
  263. public function getSonConfig()
  264. {
  265. $sonConfig = [];
  266. $rolateRule = $this->relatedRule;
  267. if ($rolateRule) {
  268. foreach ($rolateRule as $key => $value) {
  269. $sonConfig = array_merge($sonConfig, array_keys($value['son_type']));
  270. foreach ($value['son_type'] as $k => $v) {
  271. if (isset($v['son_type'])) {
  272. $sonConfig = array_merge($sonConfig, array_keys($v['son_type']));
  273. }
  274. }
  275. }
  276. }
  277. return $sonConfig;
  278. }
  279. /**
  280. * 获取单个系统配置
  281. * @param string $configName
  282. * @param int $type
  283. * @param int $relation_id
  284. * @param $default
  285. * @return mixed|null
  286. */
  287. public function getConfigValue(string $configName, int $type = 1, int $relation_id = 0, $default = null)
  288. {
  289. if ($relation_id) {//查门店、供应商
  290. /** @var StoreConfigServices $service */
  291. $service = app()->make(StoreConfigServices::class);
  292. return $service->getConfig($configName, $type, $relation_id);
  293. } else {//平台
  294. $value = $this->dao->getConfigValue($configName);
  295. return is_null($value) ? $default : json_decode($value, true);
  296. }
  297. }
  298. /**
  299. * 获取全部配置
  300. * @param array $configName
  301. * @return array
  302. */
  303. public function getConfigAll(array $configName = [], int $type = 1, int $relation_id = 0)
  304. {
  305. if ($relation_id) {
  306. /** @var StoreConfigServices $service */
  307. $service = app()->make(StoreConfigServices::class);
  308. return $service->getConfigAll($configName, $type, $relation_id);
  309. } else {
  310. return array_map(function ($item) {
  311. return json_decode($item, true);
  312. }, $this->dao->getConfigAll($configName));
  313. }
  314. }
  315. /**
  316. * 获取配置并分页
  317. * @param array $where
  318. * @return array
  319. * @throws \think\db\exception\DataNotFoundException
  320. * @throws \think\db\exception\DbException
  321. * @throws \think\db\exception\ModelNotFoundException
  322. */
  323. public function getConfigList(array $where)
  324. {
  325. [$page, $limit] = $this->getPageValue();
  326. $list = $this->dao->getConfigList($where, $page, $limit);
  327. $count = $this->dao->count($where);
  328. foreach ($list as &$item) {
  329. $item['value'] = $item['value'] ? json_decode($item['value'], true) ?: '' : '';
  330. if ($item['type'] == 'radio' || $item['type'] == 'checkbox') {
  331. $item['value'] = $this->getRadioOrCheckboxValueInfo($item['menu_name'], $item['value']);
  332. }
  333. if ($item['type'] == 'upload' && !empty($item['value'])) {
  334. if ($item['upload_type'] == 1 || $item['upload_type'] == 3) {
  335. $item['value'] = [set_file_url($item['value'])];
  336. } elseif ($item['upload_type'] == 2) {
  337. $item['value'] = set_file_url($item['value']);
  338. }
  339. foreach ($item['value'] as $key => $value) {
  340. $tidy_srr[$key]['filepath'] = $value;
  341. $tidy_srr[$key]['filename'] = basename($value);
  342. }
  343. $item['value'] = $tidy_srr;
  344. }
  345. }
  346. return compact('count', 'list');
  347. }
  348. /**
  349. * 获取单选按钮或者多选按钮的显示值
  350. * @param $menu_name
  351. * @param $value
  352. * @return string
  353. * @throws \think\db\exception\DataNotFoundException
  354. * @throws \think\db\exception\ModelNotFoundException
  355. * @throws \think\exception\DbException
  356. */
  357. public function getRadioOrCheckboxValueInfo(string $menu_name, $value): string
  358. {
  359. $option = [];
  360. $config_one = $this->dao->getOne(['menu_name' => $menu_name]);
  361. if (!$config_one) {
  362. return '';
  363. }
  364. $parameter = explode("\n", $config_one['parameter']);
  365. foreach ($parameter as $k => $v) {
  366. if (isset($v) && strlen($v) > 0) {
  367. $data = explode('=>', $v);
  368. $option[$data[0]] = $data[1];
  369. }
  370. }
  371. $str = '';
  372. if (is_array($value)) {
  373. foreach ($value as $v) {
  374. $str .= $option[$v] . ',';
  375. }
  376. } else {
  377. $str .= !empty($value) ? $option[$value] ?? '' : $option[0] ?? '';
  378. }
  379. return $str;
  380. }
  381. /**
  382. * 获取系统配置信息
  383. * @param int $tabId
  384. * @return array
  385. * @throws \think\db\exception\DataNotFoundException
  386. * @throws \think\db\exception\DbException
  387. * @throws \think\db\exception\ModelNotFoundException
  388. */
  389. public function getReadList(int $tabId)
  390. {
  391. $info = $this->dao->getConfigTabAllList($tabId);
  392. foreach ($info as $k => $v) {
  393. if (!is_null(json_decode($v['value'])))
  394. $info[$k]['value'] = json_decode($v['value'], true);
  395. if ($v['type'] == 'upload' && !empty($v['value'])) {
  396. if ($v['upload_type'] == 1 || $v['upload_type'] == 3) $info[$k]['value'] = explode(',', $v['value']);
  397. }
  398. }
  399. return $info;
  400. }
  401. /**
  402. * 创建单行表单
  403. * @param string $type
  404. * @param array $data
  405. * @return array
  406. */
  407. public function createTextForm(string $type, array $data)
  408. {
  409. $formbuider = [];
  410. switch ($type) {
  411. case 'input':
  412. $data['value'] = isset($data['value']) ? json_decode($data['value'], true) : '';
  413. $formbuider[] = $this->builder->input($data['menu_name'], $data['info'], $data['value'])->info($data['desc'])->placeholder($data['desc'])->col(13);
  414. break;
  415. case 'number':
  416. $data['value'] = isset($data['value']) ? json_decode($data['value'], true) : 0;
  417. if ($data['menu_name'] == 'integral_max_num' || $data['menu_name'] == 'order_give_integral') {
  418. $formbuider[] = $this->builder->number($data['menu_name'], $data['info'], (float)$data['value'])->info($data['desc'])->precision(0);
  419. } else {
  420. $formbuider[] = $this->builder->number($data['menu_name'], $data['info'], (float)$data['value'])->info($data['desc']);
  421. }
  422. break;
  423. case 'dateTime':
  424. $formbuider[] = $this->builder->dateTime($data['menu_name'], $data['info'], $data['value'])->info($data['desc']);
  425. break;
  426. case 'color':
  427. $data['value'] = isset($data['value']) ? json_decode($data['value'], true) : '';
  428. $formbuider[] = $this->builder->color($data['menu_name'], $data['info'], $data['value'])->info($data['desc']);
  429. break;
  430. default:
  431. $data['value'] = isset($data['value']) ? json_decode($data['value'], true) : '';
  432. $formbuider[] = $this->builder->input($data['menu_name'], $data['info'], $data['value'])->info($data['desc'])->placeholder($data['desc'])->col(13);
  433. break;
  434. }
  435. return $formbuider;
  436. }
  437. /**
  438. * 创建多行文本框
  439. * @param array $data
  440. * @return mixed
  441. */
  442. public function createTextareaForm(array $data)
  443. {
  444. $data['value'] = json_decode($data['value'], true) ?: '';
  445. $formbuider[] = $this->builder->textarea($data['menu_name'], $data['info'], $data['value'])->placeholder($data['desc'])->info($data['desc'])->rows(6)->col(13);
  446. return $formbuider;
  447. }
  448. /**
  449. * 创建当选表单
  450. * @param array $data
  451. * @param false $control
  452. * @param array $control_two
  453. * @param array $controlle_three
  454. * @return array
  455. */
  456. public function createRadioForm(array $data, $control = false, $control_two = [], $controlle_three = [])
  457. {
  458. $formbuider = [];
  459. $data['value'] = json_decode($data['value'], true) ?: '0';
  460. $parameter = explode("\n", $data['parameter']);
  461. $options = [];
  462. if ($parameter) {
  463. foreach ($parameter as $v) {
  464. if (strstr($v, $this->cuttingStr) !== false) {
  465. $pdata = explode($this->cuttingStr, $v);
  466. $options[] = ['label' => $pdata[1], 'value' => (int)$pdata[0]];
  467. }
  468. }
  469. $formbuider[] = $radio = $this->builder->radio($data['menu_name'], $data['info'], (int)$data['value'])->options($options)->info($data['desc'])->col(13);
  470. if ($control) {
  471. $radio->appendControl(isset($data['show_value']) ? $data['show_value'] : 1, is_array($control) ? $control : [$control]);
  472. }
  473. if ($control_two && isset($data['show_value2'])) {
  474. $radio->appendControl(isset($data['show_value2']) ? $data['show_value2'] : 2, is_array($control_two) ? $control_two : [$control_two]);
  475. }
  476. if ($controlle_three && isset($data['show_value3'])) {
  477. $radio->appendControl(isset($data['show_value3']) ? $data['show_value3'] : 3, is_array($controlle_three) ? $controlle_three : [$controlle_three]);
  478. }
  479. return $formbuider;
  480. }
  481. }
  482. /**
  483. * 创建上传组件表单
  484. * @param int $type
  485. * @param array $data
  486. * @param int $admin_type
  487. * @return array
  488. */
  489. public function createUpoadForm(int $type, array $data, int $admin_type = 0)
  490. {
  491. $formbuider = [];
  492. switch ($admin_type) {
  493. case 0://平台
  494. $from = config('admin.admin_prefix');
  495. break;
  496. case 1://门店
  497. $from = config('admin.store_prefix');
  498. break;
  499. case 2://供应商
  500. $from = config('admin.supplier_prefix');
  501. break;
  502. default:
  503. $from = config('admin.admin_prefix');
  504. break;
  505. }
  506. switch ($type) {
  507. case 1:
  508. $data['value'] = json_decode($data['value'], true) ?: '';
  509. if (!$data['value']) $data['value'] = set_file_url($data['value']);
  510. $formbuider[] = $this->builder->frameImage($data['menu_name'], $data['info'], $this->url($from . '/widget.images/index', ['fodder' => $data['menu_name']], true), $data['value'])
  511. ->icon('ios-image')->width('960px')->height('505px')->modal(['footer-hide' => true])->info($data['desc'])->col(13);
  512. break;
  513. case 2:
  514. $data['value'] = json_decode($data['value'], true) ?: [];
  515. if (!$data['value']) $data['value'] = set_file_url($data['value']);
  516. $formbuider[] = $this->builder->frameImages($data['menu_name'], $data['info'], $this->url($from . '/widget.images/index', ['fodder' => $data['menu_name'], 'type' => 'many', 'maxLength' => 5], true), $data['value'])
  517. ->maxLength(5)->icon('ios-images')->width('960px')->modal(['footer-hide' => true])->height('505px')
  518. ->info($data['desc'])->col(13);
  519. break;
  520. case 3:
  521. $data['value'] = json_decode($data['value'], true) ?: '';
  522. if (!$data['value']) $data['value'] = set_file_url($data['value']);
  523. $formbuider[] = $this->builder->uploadFile($data['menu_name'], $data['info'], $this->url('/adminapi/file/upload/1', ['type' => 1], false, false), $data['value'])
  524. ->name('file')->info($data['desc'])->col(13)->headers([
  525. 'Authori-zation' => app()->request->header('Authori-zation'),
  526. ]);
  527. break;
  528. }
  529. return $formbuider;
  530. }
  531. /**
  532. * 创建单选框
  533. * @param array $data
  534. * @return array
  535. * @throws \FormBuilder\Exception\FormBuilderException
  536. */
  537. public function createCheckboxForm(array $data)
  538. {
  539. $formbuider = [];
  540. $data['value'] = json_decode($data['value'], true) ?: [];
  541. $parameter = explode("\n", $data['parameter']);
  542. $options = [];
  543. if ($parameter) {
  544. foreach ($parameter as $v) {
  545. if (strstr($v, $this->cuttingStr) !== false) {
  546. $pdata = explode($this->cuttingStr, $v);
  547. $options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
  548. }
  549. }
  550. $formbuider[] = $this->builder->checkbox($data['menu_name'], $data['info'], $data['value'])->options($options)->info($data['desc'])->col(13);
  551. }
  552. return $formbuider;
  553. }
  554. /**
  555. * 创建选择框表单
  556. * @param array $data
  557. * @return array
  558. * @throws \FormBuilder\Exception\FormBuilderException
  559. */
  560. public function createSelectForm(array $data)
  561. {
  562. $formbuider = [];
  563. $data['value'] = json_decode($data['value'], true) ?: [];
  564. $parameter = explode("\n", $data['parameter']);
  565. $options = [];
  566. if ($parameter) {
  567. foreach ($parameter as $v) {
  568. if (strstr($v, $this->cuttingStr) !== false) {
  569. $pdata = explode($this->cuttingStr, $v);
  570. $options[] = ['label' => $pdata[1], 'value' => $pdata[0]];
  571. }
  572. }
  573. $formbuider[] = $this->builder->select($data['menu_name'], $data['info'], $data['value'])->options($options)->info($data['desc'])->col(13);
  574. }
  575. return $formbuider;
  576. }
  577. public function bindBuilderData($data, $relatedRule)
  578. {
  579. if (!$data) return false;
  580. $p_list = array();
  581. foreach ($relatedRule as $rk => $rv) {
  582. $p_list[$rk] = $data[$rk];
  583. if (isset($rv['son_type']) && is_array($rv['son_type'])) {
  584. foreach ($rv['son_type'] as $sk => $sv) {
  585. if (is_array($sv) && isset($sv['son_type'])) {
  586. foreach ($sv['son_type'] as $ssk => $ssv) {
  587. $tmp = $data[$sk];
  588. $tmp['console'] = $data[$ssk];
  589. $p_list[$rk]['console'][] = $tmp;
  590. }
  591. } else {
  592. $p_list[$rk]['console'][] = $data[$sk];
  593. }
  594. }
  595. }
  596. }
  597. return array_values($p_list);
  598. }
  599. /**
  600. * 获取系统配置表单
  601. * @param int $id
  602. * @param array $formData
  603. * @return array
  604. * @throws \think\db\exception\DataNotFoundException
  605. * @throws \think\db\exception\DbException
  606. * @throws \think\db\exception\ModelNotFoundException
  607. */
  608. public function formTypeShine($data, $control = false, $controle_two = [], $controlle_three = [])
  609. {
  610. switch ($data['type']) {
  611. case 'text'://文本框
  612. return $this->createTextForm($data['input_type'], $data);
  613. break;
  614. case 'radio'://单选框
  615. return $this->createRadioForm($data, $control, $controle_two, $controlle_three);
  616. break;
  617. case 'textarea'://多行文本框
  618. return $this->createTextareaForm($data);
  619. break;
  620. case 'upload'://文件上传
  621. return $this->createUpoadForm((int)$data['upload_type'], $data);
  622. break;
  623. case 'checkbox'://多选框
  624. return $this->createCheckboxForm($data);
  625. break;
  626. case 'select'://多选框
  627. return $this->createSelectForm($data);
  628. break;
  629. }
  630. }
  631. /**
  632. * @param int $tabId
  633. * @param array $formData
  634. * @param array $relatedRule
  635. * @return array|bool
  636. * @throws \think\db\exception\DataNotFoundException
  637. * @throws \think\db\exception\DbException
  638. * @throws \think\db\exception\ModelNotFoundException
  639. */
  640. public function createConfigForm(int $tabId, array $relatedRule)
  641. {
  642. $list = $this->dao->getConfigTabAllList($tabId);
  643. if (!$relatedRule) {
  644. $formbuider = $this->createNoCrontrolForm($list);
  645. } else {
  646. $formbuider = $this->createBindCrontrolForm($list, $relatedRule);
  647. }
  648. return $formbuider;
  649. }
  650. /**
  651. * 创建
  652. * @param array $list
  653. * @param int $type
  654. * @return array
  655. * @throws \FormBuilder\Exception\FormBuilderException
  656. * @throws \think\db\exception\DataNotFoundException
  657. * @throws \think\db\exception\DbException
  658. * @throws \think\db\exception\ModelNotFoundException
  659. */
  660. public function createForm(array $list, int $type = 0)
  661. {
  662. if (!$list) return [];
  663. $list = array_combine(array_column($list, 'menu_name'), $list);
  664. $formbuider = [];
  665. $relateRule = $this->relatedRule;
  666. $sonConfig = $this->getSonConfig();
  667. $next_clear_month_time = $next_clear_quarter_time = $next_clear_year_time = '';
  668. if (in_array('next_clear_month_time', $sonConfig)) {
  669. /** @var UserIntegralServices $userIntergralServices */
  670. $userIntergralServices = app()->make(UserIntegralServices::class);
  671. [$next_clear_month_time] = $userIntergralServices->getTime(1);
  672. [$next_clear_quarter_time] = $userIntergralServices->getTime(2);
  673. [$next_clear_year_time] = $userIntergralServices->getTime(3);
  674. }
  675. foreach ($list as $key => $data) {
  676. if (in_array($key, $sonConfig)) {
  677. continue;
  678. }
  679. switch ($data['type']) {
  680. case 'text'://文本框
  681. $formbuider = array_merge($formbuider, $this->createTextForm($data['input_type'], $data));
  682. break;
  683. case 'radio'://单选框
  684. $builder = [];
  685. if (isset($relateRule[$key])) {
  686. $role = $relateRule[$key];
  687. $data['show_value'] = $role['show_value'];
  688. foreach ($role['son_type'] as $sk => $sv) {
  689. if (isset($list[$sk])) {
  690. $son_data = $list[$sk];
  691. $son_data['show_value'] = $role['show_value'];
  692. $son_build = [];
  693. if (isset($sv['son_type'])) {
  694. foreach ($sv['son_type'] as $ssk => $ssv) {
  695. $son_data['show_value'] = $sv['show_value'];
  696. if ($ssk == 'next_clear_month_time') {
  697. $son_build[] = $this->builder->input('next_clear_month_time', '最近清零时间', $next_clear_month_time ? date('Y-m-d', $next_clear_month_time) : '')->info('最近清零时间')->disabled(true)->col(13);
  698. } else {
  699. $son_build[] = $this->formTypeShine($list[$ssk])[0];
  700. unset($list[$ssk]);
  701. }
  702. }
  703. }
  704. $son_build_two = [];
  705. if (isset($role['son_type'][$sk . '@'])) {
  706. $son_type_two = $role['son_type'][$sk . '@'];
  707. $son_data['show_value2'] = $son_type_two['show_value'];
  708. if (isset($son_type_two['son_type'])) {
  709. foreach ($son_type_two['son_type'] as $ssk => $ssv) {
  710. if ($ssk == 'next_clear_quarter_time') {
  711. $son_build_two[] = $this->builder->input('next_clear_quarter_time', '最近清零时间', $next_clear_quarter_time ? date('Y-m-d', $next_clear_quarter_time) : '')->info('最近清零时间')->disabled(true)->col(13);
  712. } else {
  713. $son_build_two[] = $this->formTypeShine($list[$ssk])[0];
  714. unset($list[$ssk]);
  715. }
  716. }
  717. }
  718. }
  719. $son_build_three = [];
  720. if (isset($role['son_type'][$sk . '#'])) {
  721. $son_type_two = $role['son_type'][$sk . '#'];
  722. $son_data['show_value3'] = $son_type_two['show_value'];
  723. if (isset($son_type_two['son_type'])) {
  724. foreach ($son_type_two['son_type'] as $ssk => $ssv) {
  725. if ($ssk == 'next_clear_year_time') {
  726. $son_build_three[] = $this->builder->input('next_clear_year_time', '最近清零时间', $next_clear_year_time ? date('Y-m-d', $next_clear_year_time) : '')->info('最近清零时间')->disabled(true)->col(13);
  727. } else {
  728. $son_build_three[] = $this->formTypeShine($list[$ssk])[0];
  729. unset($list[$ssk]);
  730. }
  731. }
  732. }
  733. }
  734. $builder[] = $this->formTypeShine($son_data, $son_build, $son_build_two, $son_build_three)[0];
  735. unset($list[$sk]);
  736. }
  737. }
  738. $data['show_value'] = $role['show_value'];
  739. }
  740. $formbuider = array_merge($formbuider, $this->createRadioForm($data, $builder));
  741. break;
  742. case 'textarea'://多行文本框
  743. $formbuider = array_merge($formbuider, $this->createTextareaForm($data));
  744. break;
  745. case 'upload'://文件上传
  746. $formbuider = array_merge($formbuider, $this->createUpoadForm((int)$data['upload_type'], $data, $type));
  747. break;
  748. case 'checkbox'://多选框
  749. $formbuider = array_merge($formbuider, $this->createCheckboxForm($data));
  750. break;
  751. case 'select'://多选框
  752. $formbuider = array_merge($formbuider, $this->createSelectForm($data));
  753. break;
  754. }
  755. }
  756. return $formbuider;
  757. }
  758. /**无组件绑定规则
  759. * @param array $list
  760. * @return array|bool
  761. * @throws \FormBuilder\Exception\FormBuilderException
  762. * @throws \think\db\exception\DataNotFoundException
  763. * @throws \think\db\exception\DbException
  764. * @throws \think\db\exception\ModelNotFoundException
  765. */
  766. public function createNoCrontrolForm(array $list)
  767. {
  768. if (!$list) return false;
  769. $formbuider = [];
  770. foreach ($list as $key => $data) {
  771. switch ($data['type']) {
  772. case 'text'://文本框
  773. $formbuider = array_merge($formbuider, $this->createTextForm($data['input_type'], $data));
  774. break;
  775. case 'radio'://单选框
  776. $formbuider = array_merge($formbuider, $this->createRadioForm($data));
  777. break;
  778. case 'textarea'://多行文本框
  779. $formbuider = array_merge($formbuider, $this->createTextareaForm($data));
  780. break;
  781. case 'upload'://文件上传
  782. $formbuider = array_merge($formbuider, $this->createUpoadForm((int)$data['upload_type'], $data));
  783. break;
  784. case 'checkbox'://多选框
  785. $formbuider = array_merge($formbuider, $this->createCheckboxForm($data));
  786. break;
  787. case 'select'://多选框
  788. $formbuider = array_merge($formbuider, $this->createSelectForm($data));
  789. break;
  790. }
  791. }
  792. return $formbuider;
  793. }
  794. /**
  795. * 有组件绑定规则
  796. * @param array $list
  797. * @param array $relatedRule
  798. * @return array|bool
  799. * @throws \FormBuilder\Exception\FormBuilderException
  800. * @throws \think\db\exception\DataNotFoundException
  801. * @throws \think\db\exception\DbException
  802. * @throws \think\db\exception\ModelNotFoundException
  803. */
  804. public function createBindCrontrolForm(array $list, array $relatedRule)
  805. {
  806. if (!$list || !$relatedRule) return false;
  807. $formbuider = [];
  808. $new_data = array();
  809. foreach ($list as $dk => $dv) {
  810. $new_data[$dv['menu_name']] = $dv;
  811. }
  812. foreach ($relatedRule as $rk => $rv) {
  813. if (isset($rv['son_type'])) {
  814. $data = $new_data[$rk];
  815. switch ($data['type']) {
  816. case 'text'://文本框
  817. $formbuider = array_merge($formbuider, $this->createTextForm($data['input_type'], $data));
  818. break;
  819. case 'radio'://单选框
  820. $son_builder = array();
  821. foreach ($rv['son_type'] as $sk => $sv) {
  822. if (isset($sv['son_type'])) {
  823. foreach ($sv['son_type'] as $ssk => $ssv) {
  824. $son_data = $new_data[$sk];
  825. $son_data['show_value'] = $sv['show_value'];
  826. $son_builder[] = $this->formTypeShine($son_data, $this->formTypeShine($new_data[$ssk])[0])[0];
  827. }
  828. } else {
  829. $son_data = $new_data[$sk];
  830. $son_data['show_value'] = $rv['show_value'];
  831. $son_builder[] = $this->formTypeShine($son_data)[0];
  832. }
  833. }
  834. $formbuider = array_merge($formbuider, $this->createRadioForm($data, $son_builder));
  835. break;
  836. case 'textarea'://多行文本框
  837. $formbuider = array_merge($formbuider, $this->createTextareaForm($data));
  838. break;
  839. case 'upload'://文件上传
  840. $formbuider = array_merge($formbuider, $this->createUpoadForm((int)$data['upload_type'], $data));
  841. break;
  842. case 'checkbox'://多选框
  843. $formbuider = array_merge($formbuider, $this->createCheckboxForm($data));
  844. break;
  845. case 'select'://多选框
  846. $formbuider = array_merge($formbuider, $this->createSelectForm($data));
  847. break;
  848. }
  849. }
  850. }
  851. return $formbuider;
  852. }
  853. /**
  854. * 系统配置form表单创建
  855. * @param int $tabId
  856. * @return array
  857. * @throws \FormBuilder\Exception\FormBuilderException
  858. * @throws \think\db\exception\DataNotFoundException
  859. * @throws \think\db\exception\DbException
  860. * @throws \think\db\exception\ModelNotFoundException
  861. */
  862. public function getConfigForm($url, int $tabId, int $type = 0, $relation_id = 0)
  863. {
  864. /** @var SystemConfigTabServices $service */
  865. $service = app()->make(SystemConfigTabServices::class);
  866. $title = $service->value(['id' => $tabId], 'title');
  867. $list = $this->dao->getConfigTabAllList($tabId, 1, $type, $relation_id);
  868. if ($relation_id != 0) {
  869. foreach ($list as &$item) {
  870. $item['value'] = $item['store_value'] ?? '';
  871. }
  872. }
  873. $formbuider = $this->createForm($list, $type);
  874. $name = 'setting';
  875. if ($url) {
  876. $name = explode('/', $url)[2] ?? $name;
  877. }
  878. $postUrl = $this->postUrl[$name]['url'] ?? '/setting/config/save_basics';
  879. $postUrl = $relation_id ? $url : $postUrl;
  880. return create_form($title, $formbuider, $this->url($postUrl), 'POST');
  881. }
  882. /**
  883. * 新增路由增加设置项验证
  884. * @param $url
  885. * @param $post
  886. * @return bool
  887. */
  888. public function checkParam($url, $post)
  889. {
  890. $name = '';
  891. if ($url) {
  892. $name = explode('/', $url)[2] ?? $name;
  893. }
  894. $auth = $this->postUrl[$name]['auth'] ?? false;
  895. if ($auth === false) {
  896. throw new ValidateException('请求不被允许');
  897. }
  898. if ($auth) {
  899. /** @var SystemConfigTabServices $systemConfigTabServices */
  900. $systemConfigTabServices = app()->make(SystemConfigTabServices::class);
  901. foreach ($post as $key => $value) {
  902. $tab_ids = $systemConfigTabServices->getColumn([['eng_title', 'IN', $auth]], 'id');
  903. if (!$tab_ids || !in_array($key, $this->dao->getColumn([['config_tab_id', 'IN', $tab_ids]], 'menu_name'))) {
  904. throw new ValidateException('设置类目不被允许');
  905. }
  906. }
  907. }
  908. return true;
  909. }
  910. /**
  911. * 修改配置获取form表单
  912. * @param int $id
  913. * @return array
  914. * @throws \FormBuilder\Exception\FormBuilderException
  915. * @throws \think\db\exception\DataNotFoundException
  916. * @throws \think\db\exception\DbException
  917. * @throws \think\db\exception\ModelNotFoundException
  918. */
  919. public function editConfigForm(int $id)
  920. {
  921. $menu = $this->dao->get($id)->getData();
  922. if (!$menu) {
  923. throw new AdminException('修改数据不存在!');
  924. }
  925. /** @var SystemConfigTabServices $service */
  926. $service = app()->make(SystemConfigTabServices::class);
  927. $formbuider = [];
  928. $formbuider[] = $this->builder->input('menu_name', '字段变量', $menu['menu_name'])->disabled(1);
  929. $formbuider[] = $this->builder->hidden('type', $menu['type']);
  930. $formbuider[] = $this->builder->cascader('config_tab_id', '分类', [$menu['config_tab_id']])->data($service->getSelectForm())->changeOnSelect(true);
  931. $formbuider[] = $this->builder->input('info', '配置名称', $menu['info'])->autofocus(1);
  932. $formbuider[] = $this->builder->input('desc', '配置简介', $menu['desc']);
  933. switch ($menu['type']) {
  934. case 'text':
  935. $menu['value'] = json_decode($menu['value'], true);
  936. $formbuider[] = $this->builder->select('input_type', '类型', $menu['input_type'])->setOptions([
  937. ['value' => 'input', 'label' => '文本框']
  938. , ['value' => 'dateTime', 'label' => '时间']
  939. , ['value' => 'color', 'label' => '颜色']
  940. , ['value' => 'number', 'label' => '数字']
  941. ]);
  942. //输入框验证规则
  943. if (!$menu['is_store']) {
  944. $formbuider[] = $this->builder->input('value', '默认值', $menu['value']);
  945. }
  946. if (!empty($menu['required'])) {
  947. $formbuider[] = $this->builder->number('width', '文本框宽(%)', (int)$menu['width']);
  948. $formbuider[] = $this->builder->input('required', '验证规则', $menu['required'])->placeholder('多个请用,隔开例如:required:true,url:true');
  949. }
  950. break;
  951. case 'textarea':
  952. $menu['value'] = json_decode($menu['value'], true);
  953. //多行文本
  954. if (!empty($menu['high'])) {
  955. if (!$menu['is_store']) {//友情链接 数据是数组
  956. $formbuider[] = $this->builder->textarea('value', '默认值', is_array($menu['value']) ? json_encode($menu['value']) : $menu['value'])->rows(5);
  957. }
  958. $formbuider[] = $this->builder->number('width', '文本框宽(%)', (int)$menu['width']);
  959. $formbuider[] = $this->builder->number('high', '多行文本框高(%)', (int)$menu['high']);
  960. } else {
  961. if (!$menu['is_store']) {
  962. $formbuider[] = $this->builder->input('value', '默认值', $menu['value']);
  963. }
  964. }
  965. break;
  966. case 'radio':
  967. $formbuider = array_merge($formbuider, $this->createRadioForm($menu));
  968. //单选和多选参数配置
  969. if (!empty($menu['parameter'])) {
  970. $formbuider[] = $this->builder->textarea('parameter', '配置参数', $menu['parameter'])->placeholder("参数方式例如:\n1=>白色\n2=>红色\n3=>黑色");
  971. }
  972. break;
  973. case 'checkbox':
  974. $formbuider = array_merge($formbuider, $this->createCheckboxForm($menu));
  975. //单选和多选参数配置
  976. if (!empty($menu['parameter'])) {
  977. $formbuider[] = $this->builder->textarea('parameter', '配置参数', $menu['parameter'])->placeholder("参数方式例如:\n1=>白色\n2=>红色\n3=>黑色");
  978. }
  979. break;
  980. case 'upload':
  981. $formbuider = array_merge($formbuider, $this->createUpoadForm(($menu['upload_type']), $menu));
  982. //上传类型选择
  983. if (!empty($menu['upload_type'])) {
  984. $formbuider[] = $this->builder->radio('upload_type', '上传类型', $menu['upload_type'])->options([['value' => 1, 'label' => '单图'], ['value' => 2, 'label' => '多图'], ['value' => 3, 'label' => '文件']]);
  985. }
  986. break;
  987. }
  988. $formbuider[] = $this->builder->number('sort', '排序', (int)$menu['sort'])->min(0);
  989. $formbuider[] = $this->builder->radio('status', '状态', $menu['status'])->options([['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']]);
  990. return create_form('编辑字段', $formbuider, $this->url('/setting/config/' . $id), 'PUT');
  991. }
  992. /**
  993. * 字段状态
  994. * @return array
  995. */
  996. public function formStatus(): array
  997. {
  998. return [['value' => 1, 'label' => '显示'], ['value' => 2, 'label' => '隐藏']];
  999. }
  1000. /**
  1001. * 选择文文件类型
  1002. * @return array
  1003. */
  1004. public function uploadType(): array
  1005. {
  1006. return [
  1007. ['value' => 1, 'label' => '单图']
  1008. , ['value' => 2, 'label' => '多图']
  1009. , ['value' => 3, 'label' => '文件']
  1010. ];
  1011. }
  1012. /**
  1013. * 选择文本框类型
  1014. * @return array
  1015. */
  1016. public function textType(): array
  1017. {
  1018. return [
  1019. ['value' => 'input', 'label' => '文本框']
  1020. , ['value' => 'dateTime', 'label' => '时间']
  1021. , ['value' => 'color', 'label' => '颜色']
  1022. , ['value' => 'number', 'label' => '数字']
  1023. ];
  1024. }
  1025. /**
  1026. * 获取创建配置规格表单
  1027. * @param int $type
  1028. * @param int $tab_id
  1029. * @return array
  1030. */
  1031. public function createFormRule(int $type, int $tab_id): array
  1032. {
  1033. /** @var SystemConfigTabServices $service */
  1034. $service = app()->make(SystemConfigTabServices::class);
  1035. $formbuider = [];
  1036. $form_type = '';
  1037. $info_type = [];
  1038. $parameter = [];
  1039. $formbuider[] = $this->builder->radio('is_store', '配置类型', 0)->options([
  1040. ['value' => 0, 'label' => '总后台'],
  1041. ['value' => 1, 'label' => '门店后台']
  1042. ]);
  1043. switch ($type) {
  1044. case 0://文本框
  1045. $form_type = 'text';
  1046. $info_type = $this->builder->select('input_type', '类型')->setOptions($this->textType());
  1047. $parameter[] = $this->builder->input('value', '默认值');
  1048. $parameter[] = $this->builder->number('width', '文本框宽(%)', 100);
  1049. $parameter[] = $this->builder->input('required', '验证规则')->placeholder('多个请用,隔开例如:required:true,url:true');
  1050. break;
  1051. case 1://多行文本框
  1052. $form_type = 'textarea';
  1053. $parameter[] = $this->builder->textarea('value', '默认值');
  1054. $parameter[] = $this->builder->number('width', '文本框宽(%)', 100);
  1055. $parameter[] = $this->builder->number('high', '多行文本框高(%)', 5);
  1056. break;
  1057. case 2://单选框
  1058. $form_type = 'radio';
  1059. $parameter[] = $this->builder->textarea('parameter', '配置参数')->placeholder("参数方式例如:\n1=>男\n2=>女\n3=>保密");
  1060. $parameter[] = $this->builder->input('value', '默认值');
  1061. break;
  1062. case 3://文件上传
  1063. $form_type = 'upload';
  1064. $parameter[] = $this->builder->radio('upload_type', '上传类型', 1)->options($this->uploadType());
  1065. break;
  1066. case 4://多选框
  1067. $form_type = 'checkbox';
  1068. $parameter[] = $this->builder->textarea('parameter', '配置参数')->placeholder("参数方式例如:\n1=>白色\n2=>红色\n3=>黑色");
  1069. break;
  1070. case 5://下拉框
  1071. $form_type = 'select';
  1072. $parameter[] = $this->builder->textarea('parameter', '配置参数')->placeholder("参数方式例如:\n1=>白色\n2=>红色\n3=>黑色");
  1073. break;
  1074. }
  1075. if ($form_type) {
  1076. $formbuider[] = $this->builder->hidden('type', $form_type);
  1077. $formbuider[] = $this->builder->cascader('config_tab_id', '分类', [])->data($service->getSelectForm())->changeOnSelect(true);
  1078. if ($info_type) {
  1079. $formbuider[] = $info_type;
  1080. }
  1081. $formbuider[] = $this->builder->input('info', '配置名称')->autofocus(1);
  1082. $formbuider[] = $this->builder->input('menu_name', '字段变量')->placeholder('例如:site_url');
  1083. $formbuider[] = $this->builder->input('desc', '配置简介');
  1084. $formbuider = array_merge($formbuider, $parameter);
  1085. $formbuider[] = $this->builder->number('sort', '排序', 0)->min(0);
  1086. $formbuider[] = $this->builder->radio('status', '状态', 1)->options($this->formStatus());
  1087. }
  1088. return create_form('添加字段', $formbuider, $this->url('/setting/config'), 'POST');
  1089. }
  1090. /**
  1091. * radio 和 checkbox规则的判断
  1092. * @param $data
  1093. * @return bool
  1094. */
  1095. public function valiDateRadioAndCheckbox($data)
  1096. {
  1097. $option = [];
  1098. $option_new = [];
  1099. $data['parameter'] = str_replace("\r\n", "\n", $data['parameter']);//防止不兼容
  1100. $parameter = explode("\n", $data['parameter']);
  1101. if (count($parameter) < 2) {
  1102. throw new AdminException('请输入正确格式的配置参数');
  1103. }
  1104. foreach ($parameter as $k => $v) {
  1105. if (isset($v) && !empty($v)) {
  1106. $option[$k] = explode('=>', $v);
  1107. }
  1108. }
  1109. if (count($option) < 2) {
  1110. throw new AdminException('请输入正确格式的配置参数');
  1111. }
  1112. $bool = 1;
  1113. foreach ($option as $k => $v) {
  1114. $option_new[$k] = $option[$k][0];
  1115. foreach ($v as $kk => $vv) {
  1116. $vv_num = strlen($vv);
  1117. if (!$vv_num) {
  1118. $bool = 0;
  1119. }
  1120. }
  1121. }
  1122. if (!$bool) {
  1123. throw new AdminException('请输入正确格式的配置参数');
  1124. }
  1125. $num1 = count($option_new);//提取该数组的数目
  1126. $arr2 = array_unique($option_new);//合并相同的元素
  1127. $num2 = count($arr2);//提取合并后数组个数
  1128. if ($num1 > $num2) {
  1129. throw new AdminException('请输入正确格式的配置参数');
  1130. }
  1131. return true;
  1132. }
  1133. /**
  1134. * 验证参数
  1135. * @param $data
  1136. * @return bool
  1137. */
  1138. public function valiDateValue($data)
  1139. {
  1140. if (!$data || !isset($data['required']) || !$data['required']) {
  1141. return true;
  1142. }
  1143. $valids = explode(',', $data['required']);
  1144. foreach ($valids as $valid) {
  1145. $valid = explode(':', $valid);
  1146. if (isset($valid[0]) && isset($valid[1])) {
  1147. $k = strtolower(trim($valid[0]));
  1148. $v = strtolower(trim($valid[1]));
  1149. switch ($k) {
  1150. case 'required':
  1151. if ($v == 'true' && $data['value'] === '') {
  1152. throw new ValidateException(($data['info'] ?? '') . '请输入默认值');
  1153. }
  1154. break;
  1155. case 'url':
  1156. if ($v == 'true' && !check_link($data['value'])) {
  1157. throw new ValidateException(($data['info'] ?? '') . '请输入正确url');
  1158. }
  1159. break;
  1160. }
  1161. }
  1162. }
  1163. }
  1164. /**
  1165. * 保存平台电子面单打印信息
  1166. * @param array $data
  1167. * @return bool
  1168. */
  1169. public function saveExpressInfo(array $data)
  1170. {
  1171. if (!is_array($data) || !$data) return false;
  1172. // config_export_id 快递公司id
  1173. // config_export_temp_id 快递公司模板id
  1174. // config_export_com 快递公司编码
  1175. // config_export_to_name 发货人姓名
  1176. // config_export_to_tel 发货人电话
  1177. // config_export_to_address 发货人详细地址
  1178. // config_export_siid 电子面单打印机编号
  1179. foreach ($data as $key => $value) {
  1180. $this->dao->update(['menu_name' => 'config_export_' . $key], ['value' => json_encode($value)]);
  1181. }
  1182. \crmeb\services\SystemConfigService::clear();
  1183. return true;
  1184. }
  1185. /**
  1186. * 获取分享海报 兼容方法
  1187. */
  1188. public function getSpreadBanner()
  1189. {
  1190. //配置
  1191. $banner = sys_config('spread_banner', []);
  1192. if (!$banner) {
  1193. //组合数据
  1194. $banner = sys_data('routine_spread_banner');
  1195. if ($banner) {
  1196. $banner = array_column($banner, 'pic');
  1197. $this->dao->update(['menu_name' => 'spread_banner'], ['value' => json_encode($banner)]);
  1198. \crmeb\services\SystemConfigService::clear();
  1199. }
  1200. }
  1201. return $banner;
  1202. }
  1203. /**
  1204. * 保存wss配置
  1205. * @param int $wssOpen
  1206. * @param string $wssLocalpk
  1207. * @param string $wssLocalCert
  1208. */
  1209. public function saveSslFilePath(int $wssOpen, string $wssLocalpk, string $wssLocalCert)
  1210. {
  1211. $wssFile = root_path() . '.wss';
  1212. $content = <<<WSS
  1213. wssOpen = $wssOpen
  1214. wssLocalpk = $wssLocalpk
  1215. wssLocalCert = $wssLocalCert
  1216. WSS;
  1217. try {
  1218. file_put_contents($wssFile, $content);
  1219. } catch (\Throwable $e) {
  1220. throw new ValidateException('保存wss证书失败,失败原因:' . $e->getMessage());
  1221. }
  1222. }
  1223. /**
  1224. * 获取wss配置
  1225. * @param string $key
  1226. * @return array|false|mixed
  1227. */
  1228. public function getSslFilePath(string $key = '')
  1229. {
  1230. $wssFile = root_path() . '.wss';
  1231. try {
  1232. $content = parse_ini_file($wssFile);
  1233. } catch (\Throwable $e) {
  1234. $content = [];
  1235. }
  1236. if (isset($content[$key])) {
  1237. return $content[$key];
  1238. } else {
  1239. return $content;
  1240. }
  1241. }
  1242. /**
  1243. * 检测缩略图水印配置是否更改
  1244. * @param array $post
  1245. * @return bool
  1246. */
  1247. public function checkThumbParam(array $post)
  1248. {
  1249. unset($post['upload_type'], $post['image_watermark_status']);
  1250. /** @var SystemConfigTabServices $systemConfigTabServices */
  1251. $systemConfigTabServices = app()->make(SystemConfigTabServices::class);
  1252. //上传配置->基础配置
  1253. $tab_id = $systemConfigTabServices->getColumn(['eng_title' => 'base_config'], 'id');
  1254. if ($tab_id) {
  1255. $all = $this->dao->getColumn(['config_tab_id' => $tab_id], 'value', 'menu_name');
  1256. if (array_intersect(array_keys($all), array_keys($post))) {
  1257. foreach ($post as $key => $item) {
  1258. //配置更改删除原来生成的缩略图
  1259. if (isset($all[$key]) && $item != $all[$key]) {
  1260. try {
  1261. FileService::delDir(public_path('uploads/thumb_water'));
  1262. break;
  1263. } catch (\Throwable $e) {
  1264. }
  1265. }
  1266. }
  1267. }
  1268. }
  1269. return true;
  1270. }
  1271. /**
  1272. * 变更分销绑定关系模式
  1273. * @param array $post
  1274. * @return bool
  1275. */
  1276. public function checkBrokerageBinding(array $post)
  1277. {
  1278. try {
  1279. $config_data = $post['store_brokerage_binding_status'];
  1280. $config_one = $this->dao->getOne(['menu_name' => 'store_brokerage_binding_status']);
  1281. $config_old = json_decode($config_one['value'], true);
  1282. if ($config_old != 2 && $config_data == 2) {
  1283. //自动解绑上级绑定
  1284. SystemJob::dispatch('resetSpreadTime');
  1285. }
  1286. } catch (\Throwable $e) {
  1287. Log::error('变更分销绑定模式重置绑定时间失败,失败原因:' . $e->getMessage());
  1288. return false;
  1289. }
  1290. return true;
  1291. }
  1292. /**
  1293. * 获取表单
  1294. * @param string $type
  1295. * @return array
  1296. */
  1297. public function getNewFormBuildRule(string $type)
  1298. {
  1299. switch ($type) {
  1300. case 'base'://商城基础设置
  1301. $data = $this->shopBaseFormBuild();
  1302. break;
  1303. case 'store'://门店设置
  1304. $data = $this->storeFormBuild();
  1305. break;
  1306. case 'trade'://交易设置
  1307. $data = $this->shopTradeFormBuild();
  1308. break;
  1309. case 'pay'://支付设置
  1310. $data = $this->shopPayFormBuild();
  1311. break;
  1312. case 'wechat'://微信设置
  1313. $data = $this->wechatBaseFormBuild();
  1314. break;
  1315. case 'routine'://小程序设置
  1316. $data = $this->routineBaseFormBuild();
  1317. break;
  1318. case 'pc'://pc
  1319. $data = $this->pcBaseFormBuild();
  1320. break;
  1321. case 'app'://app
  1322. $data = $this->appBaseFormBuild();
  1323. break;
  1324. case 'wxopen'://开放平台
  1325. $data = $this->wxOpenBaseFormBuild();
  1326. break;
  1327. case 'third'://第三方配置
  1328. $data = $this->thirdPartyFormBuild();
  1329. break;
  1330. case 'deliver'://发货设置
  1331. $data = $this->deliverFormBuild();
  1332. break;
  1333. case 'city_deliver'://同城配送
  1334. $data = $this->cityDeliverFormBuild();
  1335. break;
  1336. case 'recharge'://充值设置
  1337. $data = $this->rechargeFormBuild();
  1338. break;
  1339. case 'user'://用户设置
  1340. $data = $this->userFormBuild();
  1341. break;
  1342. case 'svip'://付费会员
  1343. $data = $this->svipFormBuild();
  1344. break;
  1345. case 'invoice'://发票
  1346. $data = $this->invoiceFormBuild();
  1347. break;
  1348. case 'vip'://会员等级
  1349. $data = $this->vipFormBuild();
  1350. break;
  1351. case 'kefu'://客服配置
  1352. $data = $this->kefuFormBuild();
  1353. break;
  1354. case 'integral'://积分设置
  1355. $data = $this->integralFormBuild();
  1356. break;
  1357. case 'distribution'://分销设置
  1358. $data = $this->distributionFormBuild();
  1359. break;
  1360. case 'work'://企业微信设置
  1361. $data = $this->workFormBuild();
  1362. break;
  1363. case 'finance'://门店财务设置
  1364. $data = $this->financeFormBuild();
  1365. break;
  1366. case 'bargain'://砍价设置
  1367. $data = $this->bargainFormBuild();
  1368. break;
  1369. case 'supplier_finance'://供应商财务设置
  1370. $data = $this->supplierFinanceFormBuild();
  1371. break;
  1372. default:
  1373. throw new ValidateException('类型错误');
  1374. }
  1375. return $data;
  1376. }
  1377. /**
  1378. * 获取全部配置
  1379. * @param array $configName
  1380. * @param int $storeId
  1381. * @param int $type 0 正常结构 1:只返回key value
  1382. * @return array
  1383. */
  1384. public function getConfigAllField(array $configName = [], int $storeId = 0, int $type = 0)
  1385. {
  1386. $list = $this->dao->getConfigAllField($configName, $storeId, ['info', 'type', 'value', 'desc', 'parameter']);
  1387. foreach ($list as &$item) {
  1388. $item['value'] = json_decode($item['value'], true);
  1389. }
  1390. $value = [];
  1391. foreach ($configName as $key) {
  1392. if ($type) {
  1393. $value[$key] = $list[$key]['value'] ?? '';
  1394. } else {
  1395. $value[$key] = $list[$key] ?? ['info' => '', 'type' => 'text', 'value' => '', 'desc' => '', 'parameter' => ''];
  1396. }
  1397. }
  1398. return $value;
  1399. }
  1400. public function getOptions(string $parameter)
  1401. {
  1402. $parameter = explode("\n", $parameter);
  1403. $options = [];
  1404. foreach ($parameter as $v) {
  1405. if (strstr($v, $this->cuttingStr) !== false) {
  1406. $pdata = explode($this->cuttingStr, $v);
  1407. $options[] = ['label' => $pdata[1], 'value' => (int)$pdata[0]];
  1408. }
  1409. }
  1410. return $options;
  1411. }
  1412. /**
  1413. * 分销设置
  1414. * @return array
  1415. */
  1416. public function distributionFormBuild()
  1417. {
  1418. $build = new Build();
  1419. $build->url('setting/config/save_basics');
  1420. $data = $this->getConfigAllField([
  1421. 'brokerage_func_status', 'store_brokerage_statu', 'store_brokerage_price', 'brokerage_bindind',
  1422. 'store_brokerage_binding_status', 'store_brokerage_binding_time', 'spread_banner', 'store_brokerage_ratio',
  1423. 'store_brokerage_two', 'extract_time', 'is_self_brokerage', 'brokerage_user_status', 'uni_brokerage_price',
  1424. 'day_brokerage_price_upper', 'brokerage_type', 'user_extract_min_price', 'user_extract_bank_status',
  1425. 'user_extract_wechat_status', 'user_extract_alipay_status', 'user_extract_bank', 'brokerage_to_money_switch', 'brokerage_to_energy_switch', 'brokerage_trade_switch',
  1426. 'pay_weixin_client_cert', 'pay_weixin_client_key', 'brokerage_level', 'brokerage_compute_type',
  1427. 'action_integral_rate', 'static_integral_rate', 'lake_ratio', 'static_integral_ratio', 'recommend_integral', 'recommend_speed_integral',
  1428. 'extract_ratio', 'extract_ratio_active', 'extract_brokerage_ratio', 'extract_brokerage_ratio_active', 'extract_speed_ratio', 'extract_speed_num', 'extract_spread_ratio',
  1429. 'district_award', 'city_award', 'province_award', 'area_award_time', 'reorder_recommend_integral', 'starts_return_time', 'exchange_fee', 'user_exchange_min_energy', 'stock_price',
  1430. 'default_send_day', 'int_send_day', 'reorder_int_send_day', 'reorder_times', 'shop_integral_ratio', 're_now_money', 're_energy', 'system_achievement_check',
  1431. 'fail_inc_send_day', 'shop_integral_trade_commission','shop_integral_trade_commission_shop', 'shop_integral_trade_switch', 'award_order_limit_type', 'award_order_limit',
  1432. 'award_order_limit_type_2', 'award_order_limit_2',
  1433. ]);
  1434. $build->rule([
  1435. Build::tabs()->option('分销模式', [
  1436. Build::switch('brokerage_func_status', $data['brokerage_func_status']['info'], (int)$data['brokerage_func_status']['value'])
  1437. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1438. Build::radio('brokerage_level', $data['brokerage_level']['info'], $data['brokerage_level']['value'])->info($data['brokerage_level']['desc'])->options($this->getOptions($data['brokerage_level']['parameter'])),
  1439. Build::radio('store_brokerage_statu', $data['store_brokerage_statu']['info'], $data['store_brokerage_statu']['value'])
  1440. ->info($data['store_brokerage_statu']['desc'])
  1441. ->options($this->getOptions($data['store_brokerage_statu']['parameter']))
  1442. ->control(3, [
  1443. Build::inputNum('store_brokerage_price', $data['store_brokerage_price']['info'], $data['store_brokerage_price']['value'])->info($data['store_brokerage_price']['desc'])
  1444. ]),
  1445. Build::radio('brokerage_bindind', $data['brokerage_bindind']['info'], $data['brokerage_bindind']['value'])->info($data['brokerage_bindind']['desc'])->options($this->getOptions($data['brokerage_bindind']['parameter'])),
  1446. Build::radio('store_brokerage_binding_status', $data['store_brokerage_binding_status']['info'], $data['store_brokerage_binding_status']['value'])
  1447. ->options($this->getOptions($data['store_brokerage_binding_status']['parameter']))
  1448. ->control(2, [
  1449. Build::inputNum('store_brokerage_binding_time', $data['store_brokerage_binding_time']['info'], $data['store_brokerage_binding_time']['value'])->info($data['store_brokerage_binding_time']['desc']),
  1450. ])->info($data['store_brokerage_binding_status']['desc']),
  1451. Build::uploadFrame('spread_banner', $data['spread_banner']['info'], $data['spread_banner']['value'])->maxNum(5)->info($data['spread_banner']['desc'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html')
  1452. ])->info($data['brokerage_func_status']['desc']),
  1453. ])->option('返佣设置', [
  1454. // Build::radio('brokerage_compute_type', $data['brokerage_compute_type']['info'], $data['brokerage_compute_type']['value'])->options($this->getOptions($data['brokerage_compute_type']['parameter']))->info($data['brokerage_compute_type']['desc']),
  1455. // Build::inputNum('store_brokerage_ratio', $data['store_brokerage_ratio']['info'], $data['store_brokerage_ratio']['value'])->min(0)->info($data['store_brokerage_ratio']['desc']),
  1456. // Build::inputNum('store_brokerage_two', $data['store_brokerage_two']['info'], $data['store_brokerage_two']['value'])->min(0)->info($data['store_brokerage_two']['desc']),
  1457. // Build::inputNum('extract_time', $data['extract_time']['info'], $data['extract_time']['value'])->min(0)->info($data['extract_time']['desc']),
  1458. // Build::switch('is_self_brokerage', $data['is_self_brokerage']['info'], (int)$data['is_self_brokerage']['value'])
  1459. // ->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['is_self_brokerage']['desc']),
  1460. // Build::switch('brokerage_user_status', $data['brokerage_user_status']['info'], (int)$data['brokerage_user_status']['value'])->control(1, [
  1461. // Build::inputNum('uni_brokerage_price', $data['uni_brokerage_price']['info'], $data['uni_brokerage_price']['value'])->min(0)->info($data['uni_brokerage_price']['desc']),
  1462. // Build::inputNum('day_brokerage_price_upper', $data['day_brokerage_price_upper']['info'], $data['day_brokerage_price_upper']['value'])->min(-1)->info($data['day_brokerage_price_upper']['desc']),
  1463. // ])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['brokerage_user_status']['desc']),
  1464. // Build::inputNum('static_integral_ratio', $data['static_integral_ratio']['info'], $data['static_integral_ratio']['value'])->min(0)->info($data['static_integral_ratio']['desc']),
  1465. // Build::inputNum('lake_ratio', $data['lake_ratio']['info'], $data['lake_ratio']['value'])->min(0)->info($data['lake_ratio']['desc']),
  1466. Build::inputNum('recommend_integral', $data['recommend_integral']['info'], $data['recommend_integral']['value'])->min(0)->info($data['recommend_integral']['desc']),
  1467. Build::inputNum('reorder_recommend_integral', $data['reorder_recommend_integral']['info'], $data['reorder_recommend_integral']['value'])->min(0)->info($data['reorder_recommend_integral']['desc']),
  1468. Build::inputNum('recommend_speed_integral', $data['recommend_speed_integral']['info'], $data['recommend_speed_integral']['value'])->min(0)->info($data['recommend_speed_integral']['desc']),
  1469. Build::inputNum('static_integral_rate', $data['static_integral_rate']['info'], $data['static_integral_rate']['value'])->min(0)->info($data['static_integral_rate']['desc']),
  1470. // Build::inputNum('action_integral_rate', $data['action_integral_rate']['info'], $data['action_integral_rate']['value'])->min(0)->info($data['action_integral_rate']['desc']),
  1471. // Build::inputNum('extract_ratio', $data['extract_ratio']['info'], $data['extract_ratio']['value'])->min(0)->info($data['extract_ratio']['desc']),
  1472. // Build::inputNum('extract_ratio_active', $data['extract_ratio_active']['info'], $data['extract_ratio_active']['value'])->min(0)->info($data['extract_ratio_active']['desc']),
  1473. // Build::inputNum('extract_brokerage_ratio', $data['extract_brokerage_ratio']['info'], $data['extract_brokerage_ratio']['value'])->min(0)->info($data['extract_brokerage_ratio']['desc']),
  1474. Build::inputNum('extract_brokerage_ratio_active', $data['extract_brokerage_ratio_active']['info'], $data['extract_brokerage_ratio_active']['value'])->min(0)->info($data['extract_brokerage_ratio_active']['desc']),
  1475. // Build::inputNum('extract_speed_ratio', $data['extract_speed_ratio']['info'], $data['extract_speed_ratio']['value'])->min(0)->info($data['extract_speed_ratio']['desc']),
  1476. // Build::inputNum('extract_speed_num', $data['extract_speed_num']['info'], $data['extract_speed_num']['value'])->min(0)->info($data['extract_speed_num']['desc']),
  1477. // Build::inputNum('extract_spread_ratio', $data['extract_spread_ratio']['info'], $data['extract_spread_ratio']['value'])->min(0)->info($data['extract_spread_ratio']['desc']),
  1478. Build::inputNum('province_award', $data['province_award']['info'], $data['province_award']['value'])->min(0)->info($data['province_award']['desc']),
  1479. Build::inputNum('city_award', $data['city_award']['info'], $data['city_award']['value'])->min(0)->info($data['city_award']['desc']),
  1480. Build::inputNum('district_award', $data['district_award']['info'], $data['district_award']['value'])->min(0)->info($data['district_award']['desc']),
  1481. Build::inputNum('area_award_time', $data['area_award_time']['info'], $data['area_award_time']['value'])->min(0)->info($data['area_award_time']['desc']),
  1482. // Build::inputNum('starts_return_time', $data['starts_return_time']['info'], $data['starts_return_time']['value'])->min(0)->info($data['starts_return_time']['desc']),
  1483. Build::inputNum('default_send_day', $data['default_send_day']['info'], $data['default_send_day']['value'])->min(0)->info($data['default_send_day']['desc']),
  1484. Build::inputNum('int_send_day', $data['int_send_day']['info'], $data['int_send_day']['value'])->min(0)->info($data['int_send_day']['desc']),
  1485. Build::inputNum('reorder_int_send_day', $data['reorder_int_send_day']['info'], $data['reorder_int_send_day']['value'])->min(0)->info($data['reorder_int_send_day']['desc']),
  1486. Build::inputNum('reorder_times', $data['reorder_times']['info'], $data['reorder_times']['value'])->min(0)->info($data['reorder_times']['desc']),
  1487. Build::inputNum('shop_integral_ratio', $data['shop_integral_ratio']['info'], $data['shop_integral_ratio']['value'])->min(0)->info($data['shop_integral_ratio']['desc']),
  1488. Build::inputNum('re_now_money', $data['re_now_money']['info'], $data['re_now_money']['value'])->min(0)->info($data['re_now_money']['desc']),
  1489. Build::inputNum('re_energy', $data['re_energy']['info'], $data['re_energy']['value'])->min(0)->info($data['re_energy']['desc']),
  1490. Build::inputNum('system_achievement_check', $data['system_achievement_check']['info'], $data['system_achievement_check']['value'])->min(0)->info($data['system_achievement_check']['desc']),
  1491. Build::inputNum('fail_inc_send_day', $data['fail_inc_send_day']['info'], $data['fail_inc_send_day']['value'])->min(0)->info($data['fail_inc_send_day']['desc']),
  1492. Build::inputNum('shop_integral_trade_commission', $data['shop_integral_trade_commission']['info'], $data['shop_integral_trade_commission']['value'])->min(0)->info($data['shop_integral_trade_commission']['desc']),
  1493. Build::inputNum('shop_integral_trade_commission_shop', $data['shop_integral_trade_commission_shop']['info'], $data['shop_integral_trade_commission_shop']['value'])->min(0)->info($data['shop_integral_trade_commission_shop']['desc']),
  1494. Build::switch('award_order_limit_type', $data['award_order_limit_type']['info'], $data['award_order_limit_type']['value'])->trueValue('累计', 1)->falseValue('单个订单', 0),
  1495. Build::inputNum('award_order_limit', $data['award_order_limit']['info'], $data['award_order_limit']['value'])->min(0)->info($data['award_order_limit']['desc']),
  1496. Build::switch('award_order_limit_type_2', $data['award_order_limit_type_2']['info'], $data['award_order_limit_type_2']['value'])->trueValue('累计', 1)->falseValue('单个订单', 0),
  1497. Build::inputNum('award_order_limit_2', $data['award_order_limit_2']['info'], $data['award_order_limit_2']['value'])->min(0)->info($data['award_order_limit_2']['desc']),
  1498. ])->option('提现设置', [
  1499. Build::alert('微信提现到零钱为自动到账(需要开通微信:企业付款到零钱(商家转账到零钱),并确保配置微信支付证书正确,特别注意:需要配置场景、开启API发起转账),其他方式均需要手动转账', Alert::WARNING)->showIcon(true),
  1500. Build::radio('brokerage_type', $data['brokerage_type']['info'], $data['brokerage_type']['value'])->options($this->getOptions($data['brokerage_type']['parameter']))->control(1, [
  1501. Build::uploadImage('pay_weixin_client_cert', $data['pay_weixin_client_cert']['info'], $data['pay_weixin_client_cert']['value'])
  1502. ->url('/file/upload/1?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  1503. ->type('file')->icon('md-add')->info($data['pay_weixin_client_cert']['desc']),
  1504. Build::uploadImage('pay_weixin_client_key', $data['pay_weixin_client_key']['info'], $data['pay_weixin_client_key']['value'])
  1505. ->url('/file/upload/1?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  1506. ->type('file')->icon('md-add')->info($data['pay_weixin_client_key']['desc']),
  1507. ])->info($data['brokerage_type']['desc']),
  1508. Build::inputNum('user_extract_min_price', $data['user_extract_min_price']['info'], $data['user_extract_min_price']['value'])->info($data['user_extract_min_price']['desc']),
  1509. Build::switch('user_extract_bank_status', $data['user_extract_bank_status']['info'], (int)$data['user_extract_bank_status']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->control(1, [
  1510. Build::input('user_extract_bank', $data['user_extract_bank']['info'], $data['user_extract_bank']['value'])->type('textarea')->rows(6)->info($data['user_extract_bank']['desc'])
  1511. ])->info($data['user_extract_bank_status']['desc']),
  1512. Build::switch('user_extract_wechat_status', $data['user_extract_wechat_status']['info'], (int)$data['user_extract_wechat_status']['value'])->info($data['user_extract_wechat_status']['desc'])->trueValue('开启', 1)->falseValue('关闭', 0),
  1513. Build::switch('user_extract_alipay_status', $data['user_extract_alipay_status']['info'], (int)$data['user_extract_alipay_status']['value'])->info($data['user_extract_alipay_status']['desc'])->trueValue('开启', 1)->falseValue('关闭', 0),
  1514. ])->option('营销设置', [
  1515. Build::inputNum('user_exchange_min_energy', $data['user_exchange_min_energy']['info'], $data['user_exchange_min_energy']['value'])->info($data['user_exchange_min_energy']['desc']),
  1516. Build::inputNum('exchange_fee', $data['exchange_fee']['info'], $data['exchange_fee']['value'])->info($data['exchange_fee']['desc']),
  1517. Build::inputNum('stock_price', $data['stock_price']['info'], $data['stock_price']['value'])->info($data['stock_price']['desc']),
  1518. Build::switch('brokerage_to_money_switch', $data['brokerage_to_money_switch']['info'], (int)$data['brokerage_to_money_switch']['value'])->info($data['brokerage_to_money_switch']['desc'])->trueValue('开启', 1)->falseValue('关闭', 0),
  1519. Build::switch('brokerage_to_energy_switch', $data['brokerage_to_energy_switch']['info'], (int)$data['brokerage_to_energy_switch']['value'])->info($data['brokerage_to_energy_switch']['desc'])->trueValue('开启', 1)->falseValue('关闭', 0),
  1520. Build::switch('brokerage_trade_switch', $data['brokerage_trade_switch']['info'], (int)$data['brokerage_trade_switch']['value'])->info($data['brokerage_trade_switch']['desc'])->trueValue('开启', 1)->falseValue('关闭', 0),
  1521. Build::switch('shop_integral_trade_switch', $data['shop_integral_trade_switch']['info'], (int)$data['shop_integral_trade_switch']['value'])->info($data['shop_integral_trade_switch']['desc'])->trueValue('开启', 1)->falseValue('关闭', 0),
  1522. ]),
  1523. ]);
  1524. return $build->toArray();
  1525. }
  1526. /**
  1527. * 积分设置
  1528. * @return array
  1529. */
  1530. public function integralFormBuild()
  1531. {
  1532. $build = new Build();
  1533. $build->url('setting/config/save_basics');
  1534. $data = $this->getConfigAllField([
  1535. 'integral_ratio_status', 'integral_ratio', 'integral_max_type', 'integral_max_num', 'integral_max_rate', 'order_give_integral', 'integral_effective_status',
  1536. 'integral_effective_time', 'next_clear_month_time', 'next_clear_quarter_time', 'next_clear_year_time'
  1537. ]);
  1538. /** @var UserIntegralServices $userIntergralServices */
  1539. $userIntergralServices = app()->make(UserIntegralServices::class);
  1540. [$next_clear_month_time] = $userIntergralServices->getTime(1);
  1541. [$next_clear_quarter_time] = $userIntergralServices->getTime(2);
  1542. [$next_clear_year_time] = $userIntergralServices->getTime(3);
  1543. $build->rule([
  1544. Build::card('积分设置')->components([
  1545. Build::switch('integral_ratio_status', $data['integral_ratio_status']['info'], (int)$data['integral_ratio_status']['value'])
  1546. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1547. Build::inputNum('integral_ratio', $data['integral_ratio']['info'], $data['integral_ratio']['value'])->info($data['integral_ratio']['desc'])->min(0),
  1548. Build::radio('integral_max_type', $data['integral_max_type']['info'], $data['integral_max_type']['value'])->control(1, [
  1549. Build::inputNum('integral_max_num', $data['integral_max_num']['info'], $data['integral_max_num']['value'])->info($data['integral_max_num']['desc'])->min(0),
  1550. ])->control(2, [
  1551. Build::inputNum('integral_max_rate', $data['integral_max_rate']['info'], $data['integral_max_rate']['value'])->info($data['integral_max_rate']['desc'])->min(0),
  1552. ])->options($this->getOptions($data['integral_max_type']['parameter']))
  1553. ])->info($data['integral_ratio_status']['desc']),
  1554. Build::inputNum('order_give_integral', $data['order_give_integral']['info'], $data['order_give_integral']['value'])->info($data['order_give_integral']['desc'])->min(0),
  1555. Build::radio('integral_effective_status', $data['integral_effective_status']['info'], $data['integral_effective_status']['value'])
  1556. ->info($data['integral_effective_status']['desc'])->control(1, [
  1557. Build::radio('integral_effective_time', $data['integral_effective_time']['info'], $data['integral_effective_time']['value'])
  1558. ->info($data['integral_effective_time']['desc'])->control(1, [
  1559. Build::input('next_clear_month_time', '最近清零时间', $next_clear_month_time ? date('Y-m-d', $next_clear_month_time) : '')->disabled()->info('最近清零时间')
  1560. ])->control(2, [
  1561. Build::input('next_clear_quarter_time', '最近清零时间', $next_clear_quarter_time ? date('Y-m-d', $next_clear_quarter_time) : '')->info('最近清零时间')->disabled()
  1562. ])->control(3, [
  1563. Build::input('next_clear_year_time', '最近清零时间', $next_clear_year_time ? date('Y-m-d', $next_clear_year_time) : '')->info('最近清零时间')->disabled()
  1564. ])->options($this->getOptions($data['integral_effective_time']['parameter']))
  1565. ])->options($this->getOptions($data['integral_effective_status']['parameter'])),
  1566. ]),
  1567. ]);
  1568. return $build->toArray();
  1569. }
  1570. /**
  1571. * 客服配置
  1572. * @return array
  1573. */
  1574. public function kefuFormBuild()
  1575. {
  1576. $build = new Build();
  1577. $build->url('setting/config/save_basics');
  1578. $data = $this->getConfigAllField([
  1579. 'customer_type', 'service_feedback', 'customer_phone', 'customer_url',
  1580. // 'tourist_avatar'
  1581. ]);
  1582. $options = $this->getOptions($data['customer_type']['parameter']);
  1583. $build->rule([
  1584. Build::card('客服设置')->components([
  1585. Build::radio('customer_type', $data['customer_type']['info'], $data['customer_type']['value'])
  1586. ->options($options)->control(0, [
  1587. // Build::uploadFrame('tourist_avatar', $data['tourist_avatar']['info'], $data['tourist_avatar']['value'])->maxNum(5)->info($data['tourist_avatar']['desc'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html'),
  1588. Build::input('service_feedback', $data['service_feedback']['info'], $data['service_feedback']['value'])->type('textarea')->rows(5)->info($data['service_feedback']['desc']),
  1589. ])->control(1, [
  1590. Build::input('customer_phone', $data['customer_phone']['info'], $data['customer_phone']['value'])->info($data['customer_phone']['desc'])->validate(StrRules::pattern(StrRules::PHONE_NUMBER)->message('请输入正确的手机号')),
  1591. ])->control(2, [
  1592. Build::input('customer_url', $data['customer_url']['info'], $data['customer_url']['value'])->info($data['customer_url']['desc']),
  1593. ])->info($data['customer_type']['desc']),
  1594. ]),
  1595. ]);
  1596. return $build->toArray();
  1597. }
  1598. /**
  1599. * 等级设置
  1600. * @return array
  1601. */
  1602. public function vipFormBuild()
  1603. {
  1604. $build = new Build();
  1605. $build->url('setting/config/save_basics');
  1606. $data = $this->getConfigAllField([
  1607. 'member_func_status', 'member_price_status', 'order_give_exp', 'sign_give_exp', 'invite_user_exp'
  1608. ]);
  1609. $build->rule([
  1610. Build::card('等级设置')->components([
  1611. Build::switch('member_func_status', $data['member_func_status']['info'], (int)$data['member_func_status']['value'])
  1612. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1613. // Build::switch('member_price_status', $data['member_price_status']['info'], (int)$data['member_price_status']['value'])
  1614. // ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['member_price_status']['desc']),
  1615. Build::inputNum('order_give_exp', $data['order_give_exp']['info'], $data['order_give_exp']['value'])->info($data['order_give_exp']['desc'])->min(0),
  1616. Build::inputNum('sign_give_exp', $data['sign_give_exp']['info'], $data['sign_give_exp']['value'])->info($data['sign_give_exp']['desc'])->min(0),
  1617. Build::inputNum('invite_user_exp', $data['invite_user_exp']['info'], $data['invite_user_exp']['value'])->info($data['invite_user_exp']['desc'])->min(0),
  1618. ])->info($data['member_func_status']['desc']),
  1619. ]),
  1620. ]);
  1621. return $build->toArray();
  1622. }
  1623. /**
  1624. * 发票
  1625. * @return array
  1626. */
  1627. public function invoiceFormBuild()
  1628. {
  1629. $build = new Build();
  1630. $build->url('setting/config/save_basics');
  1631. $data = $this->getConfigAllField([
  1632. 'invoice_func_status', 'special_invoice_status'
  1633. ]);
  1634. $build->rule([
  1635. Build::card('发票设置')->components([
  1636. Build::switch('invoice_func_status', $data['invoice_func_status']['info'], (int)$data['invoice_func_status']['value'])
  1637. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['invoice_func_status']['desc']),
  1638. Build::switch('special_invoice_status', $data['special_invoice_status']['info'], (int)$data['special_invoice_status']['value'])
  1639. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['special_invoice_status']['desc']),
  1640. ]),
  1641. ]);
  1642. return $build->toArray();
  1643. }
  1644. /**
  1645. * 付费会员
  1646. * @return array
  1647. */
  1648. public function svipFormBuild()
  1649. {
  1650. $build = new Build();
  1651. $build->url('setting/config/save_basics');
  1652. $data = $this->getConfigAllField([
  1653. 'member_card_status', 'svip_price_status'
  1654. ]);
  1655. //缺少svip会员价格是否展示字段
  1656. $build->rule([
  1657. Build::card('会员设置')->components([
  1658. Build::switch('member_card_status', $data['member_card_status']['info'], (int)$data['member_card_status']['value'])
  1659. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['member_card_status']['desc'])->control(1, [
  1660. Build::switch('svip_price_status', $data['svip_price_status']['info'], (int)$data['svip_price_status']['value'])->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['svip_price_status']['desc'])
  1661. ])
  1662. ]),
  1663. ]);
  1664. return $build->toArray();
  1665. }
  1666. /**
  1667. * 充值设置
  1668. * @return array
  1669. */
  1670. public function rechargeFormBuild()
  1671. {
  1672. $build = new Build();
  1673. $build->url('setting/config/save_basics');
  1674. $data = $this->getConfigAllField([
  1675. 'balance_func_status', 'recharge_attention', 'recharge_switch', 'store_user_min_recharge'
  1676. ]);
  1677. $build->rule([
  1678. Build::card('充值设置')->components([
  1679. Build::switch('balance_func_status', $data['balance_func_status']['info'], (int)$data['balance_func_status']['value'])->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1680. Build::input('recharge_attention', $data['recharge_attention']['info'], $data['recharge_attention']['value'])->rows(5)->type($data['recharge_attention']['type'])->info($data['recharge_attention']['desc']),
  1681. Build::switch('recharge_switch', $data['recharge_switch']['info'], (int)$data['recharge_switch']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['recharge_switch']['desc']),
  1682. Build::inputNum('store_user_min_recharge', $data['store_user_min_recharge']['info'], $data['store_user_min_recharge']['value'])->info($data['store_user_min_recharge']['desc'])->min(0.01)->max(999999999),
  1683. ])->info($data['balance_func_status']['desc']),
  1684. ]),
  1685. ]);
  1686. return $build->toArray();
  1687. }
  1688. /**
  1689. * 用户设置
  1690. * @return array
  1691. */
  1692. public function userFormBuild()
  1693. {
  1694. $build = new Build();
  1695. $build->url('setting/config/save_basics');
  1696. $data = $this->getConfigAllField([
  1697. 'h5_avatar',
  1698. 'store_user_mobile', 'register_integral_status', 'register_give_integral', 'register_money_status', 'register_give_money', 'register_coupon_status', 'register_give_coupon', 'first_order_status', 'first_order_discount', 'first_order_discount_limit', 'register_price_status',
  1699. 'member_func_status', 'member_price_status', 'order_give_exp', 'sign_give_exp', 'invite_user_exp', 'level_activate_status', 'level_activate_status', 'level_integral_status', 'level_give_integral', 'level_money_status', 'level_give_money', 'level_coupon_status', 'level_give_coupon',
  1700. 'member_card_status', 'svip_price_status'
  1701. ]);
  1702. $build->rule([
  1703. Build::tabs()->option('基础信息', [
  1704. Build::uploadFrame('h5_avatar', $data['h5_avatar']['info'], $data['h5_avatar']['value'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html')->info($data['h5_avatar']['desc']),
  1705. ])->option('登录注册', [
  1706. Build::alert('多端(公众号、小程序)账号统一,可以开启强制手机号登录实现,也可以绑定微信开放平台实现:https://open.weixin.qq.com', Alert::WARNING)->showIcon(true),
  1707. Build::radio('store_user_mobile', $data['store_user_mobile']['info'], $data['store_user_mobile']['value'])->options($this->getOptions($data['store_user_mobile']['parameter']))->info($data['store_user_mobile']['desc'])
  1708. ])->option('等级会员', [
  1709. Build::switch('member_func_status', $data['member_func_status']['info'], (int)$data['member_func_status']['value'])
  1710. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1711. // Build::switch('member_price_status', $data['member_price_status']['info'], (int)$data['member_price_status']['value'])
  1712. // ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['member_price_status']['desc']),
  1713. Build::inputNum('order_give_exp', $data['order_give_exp']['info'], $data['order_give_exp']['value'])->info($data['order_give_exp']['desc'])->min(0),
  1714. Build::inputNum('sign_give_exp', $data['sign_give_exp']['info'], $data['sign_give_exp']['value'])->info($data['sign_give_exp']['desc'])->min(0),
  1715. Build::inputNum('invite_user_exp', $data['invite_user_exp']['info'], $data['invite_user_exp']['value'])->info($data['invite_user_exp']['desc'])->min(0),
  1716. ])->info($data['member_func_status']['desc']),
  1717. ])->option('付费会员', [
  1718. Build::switch('member_card_status', $data['member_card_status']['info'], (int)$data['member_card_status']['value'])
  1719. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['member_card_status']['desc'])->control(1, [
  1720. Build::switch('svip_price_status', $data['svip_price_status']['info'], (int)$data['svip_price_status']['value'])->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['svip_price_status']['desc'])
  1721. ])
  1722. ])
  1723. ]);
  1724. return $build->toArray();
  1725. }
  1726. /**
  1727. * 发货设置
  1728. * @return array
  1729. */
  1730. public function deliverFormBuild()
  1731. {
  1732. $build = new Build();
  1733. $build->url('setting/config/save_basics');
  1734. $data = $this->getConfigAllField([
  1735. 'store_free_postage', 'offline_postage',
  1736. // 'store_self_mention'
  1737. ]);
  1738. $build->rule([
  1739. Build::card('发货设置')->components([
  1740. Build::switch('whole_free_shipping', '全场包邮', (int)$data['store_free_postage']['value'] > 0 ? 1 : 0)
  1741. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1742. Build::inputNum('store_free_postage', $data['store_free_postage']['info'], $data['store_free_postage']['value'])->info($data['store_free_postage']['desc'])->min(0)
  1743. ])->info('开启全场包邮必须设置包邮金额大于0的金额才能开启'),
  1744. Build::switch('offline_postage', '线下支付是否包邮', (int)$data['offline_postage']['value'] > 0 ? 1 : 0)
  1745. ->falseValue('不包邮', 0)->trueValue('包邮', 1)->info($data['offline_postage']['desc'] ?? ''),
  1746. // Build::switch('store_self_mention', '是否开启到店自提', (int)$data['store_self_mention']['value'] > 0 ? 1 : 0)
  1747. // ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['store_self_mention']['desc'] ?? ''),
  1748. ]),
  1749. ]);
  1750. return $build->toArray();
  1751. }
  1752. /**
  1753. * 同城设置
  1754. * @return array
  1755. */
  1756. public function cityDeliverFormBuild()
  1757. {
  1758. $build = new Build();
  1759. $build->url('setting/config/save_basics');
  1760. $data = $this->getConfigAllField([
  1761. 'city_delivery_status', 'self_delivery_status', 'dada_delivery_status', 'dada_app_key', 'dada_app_sercret', 'dada_source_id', 'uupt_appkey', 'uu_delivery_status', 'uupt_app_id', 'uupt_open_id'
  1762. ]);
  1763. $build->rule([
  1764. Build::card('同城配送')->components([
  1765. Build::switch('city_delivery_status', $data['city_delivery_status']['info'], (int)$data['city_delivery_status']['value'])
  1766. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1767. Build::switch('self_delivery_status', $data['self_delivery_status']['info'], (int)$data['self_delivery_status']['value'])->info($data['self_delivery_status']['desc']),
  1768. Build::switch('dada_delivery_status', $data['dada_delivery_status']['info'], (int)$data['dada_delivery_status']['value'])->control(1, [
  1769. Build::input('dada_app_key', $data['dada_app_key']['info'], $data['dada_app_key']['value'])->info($data['dada_app_key']['desc']),
  1770. Build::input('dada_app_sercret', $data['dada_app_sercret']['info'], $data['dada_app_sercret']['value'])->info($data['dada_app_sercret']['desc']),
  1771. Build::input('dada_source_id', $data['dada_source_id']['info'], $data['dada_source_id']['value'])->info($data['dada_source_id']['desc']),
  1772. ])->info($data['dada_delivery_status']['desc']),
  1773. Build::switch('uu_delivery_status', $data['uu_delivery_status']['info'], (int)$data['uu_delivery_status']['value'])->control(1, [
  1774. Build::input('uupt_appkey', $data['uupt_appkey']['info'], $data['uupt_appkey']['value'])->info($data['uupt_appkey']['desc']),
  1775. Build::input('uupt_app_id', $data['uupt_app_id']['info'], $data['uupt_app_id']['value'])->info($data['uupt_app_id']['desc']),
  1776. Build::input('uupt_open_id', $data['uupt_open_id']['info'], $data['uupt_open_id']['value'])->info($data['uupt_open_id']['desc']),
  1777. ])->info($data['uu_delivery_status']['desc']),
  1778. ])->info($data['city_delivery_status']['desc'])
  1779. ]),
  1780. ]);
  1781. return $build->toArray();
  1782. }
  1783. /**
  1784. * 第三方配置
  1785. * @return array
  1786. */
  1787. public function thirdPartyFormBuild()
  1788. {
  1789. $build = new Build();
  1790. $build->url('setting/config/save_basics');
  1791. $data = $this->getConfigAllField([
  1792. 'pay_success_printing_switch', 'develop_id', 'printing_api_key', 'printing_client_id', 'terminal_number',
  1793. 'print_type', 'fey_user', 'fey_ukey', 'fey_sn',
  1794. 'system_product_copy_type', 'copy_product_apikey', 'logistics_type',
  1795. 'system_express_app_code', 'config_export_open', 'config_export_siid', 'config_export_to_name', 'config_export_to_tel',
  1796. 'tengxun_map_key', 'system_statistics', 'config_export_to_address', 'verify_expire_time', 'erp_open',
  1797. 'erp_type', 'jst_appkey', 'jst_appsecret', 'jst_default_shopid', 'jst_login_account', 'jst_login_password'
  1798. ]);
  1799. $build->rule([
  1800. Build::tabs()->option('小票打印配置', [
  1801. Build::switch('pay_success_printing_switch', $data['pay_success_printing_switch']['info'], (int)$data['pay_success_printing_switch']['value'])->control(1, [
  1802. Build::radio('print_type', $data['print_type']['info'], $data['print_type']['value'])->control(1, [
  1803. Build::input('develop_id', $data['develop_id']['info'], $data['develop_id']['value'])->info($data['develop_id']['desc']),
  1804. Build::input('printing_api_key', $data['printing_api_key']['info'], $data['printing_api_key']['value'])->info($data['printing_api_key']['desc']),
  1805. Build::input('printing_client_id', $data['printing_client_id']['info'], $data['printing_client_id']['value'])->info($data['printing_client_id']['desc']),
  1806. Build::input('terminal_number', $data['terminal_number']['info'], $data['terminal_number']['value'])->info($data['terminal_number']['desc']),
  1807. ])->control(2, [
  1808. Build::input('fey_user', $data['fey_user']['info'], $data['fey_user']['value'])->info($data['fey_user']['desc']),
  1809. Build::input('fey_ukey', $data['fey_ukey']['info'], $data['fey_ukey']['value'])->info($data['fey_ukey']['desc']),
  1810. Build::input('fey_sn', $data['fey_sn']['info'], $data['fey_sn']['value'])->info($data['fey_sn']['desc'])
  1811. ])->options($this->getOptions($data['print_type']['parameter']))->info($data['print_type']['desc'])
  1812. ])->trueValue('打开', 1)->falseValue('关闭', 0),
  1813. ])->option('采集商品配置', [
  1814. Build::radio('system_product_copy_type', $data['system_product_copy_type']['info'], $data['system_product_copy_type']['value'])->control(2, [
  1815. Build::input('copy_product_apikey', $data['copy_product_apikey']['info'], $data['copy_product_apikey']['value'])->info($data['copy_product_apikey']['desc'])
  1816. ])->options($this->getOptions($data['system_product_copy_type']['parameter']))->info($data['system_product_copy_type']['desc'])
  1817. ])->option('物流查询', [
  1818. Build::radio('logistics_type', $data['logistics_type']['info'], $data['logistics_type']['value'])->control(2, [
  1819. Build::input('system_express_app_code', $data['system_express_app_code']['info'], $data['system_express_app_code']['value'])->info($data['system_express_app_code']['desc'])
  1820. ])->options($this->getOptions($data['logistics_type']['parameter']))->info($data['logistics_type']['desc'])
  1821. ])->option('电子面单', [
  1822. Build::radio('config_export_open', $data['config_export_open']['info'], $data['config_export_open']['value'])->control(1, [
  1823. Build::input('config_export_to_name', $data['config_export_to_name']['info'], $data['config_export_to_name']['value'])->info($data['config_export_to_name']['desc']),
  1824. Build::input('config_export_to_tel', $data['config_export_to_tel']['info'], $data['config_export_to_tel']['value'])->info($data['config_export_to_tel']['desc']),
  1825. Build::input('config_export_to_address', $data['config_export_to_address']['info'], $data['config_export_to_address']['value'])->info($data['config_export_to_address']['desc']),
  1826. Build::input('config_export_siid', $data['config_export_siid']['info'], $data['config_export_siid']['value'])->info($data['config_export_siid']['desc']),
  1827. ])->options($this->getOptions($data['config_export_open']['parameter']))->info($data['config_export_open']['desc'])
  1828. ])->option('地图配置', [
  1829. Build::input('tengxun_map_key', $data['tengxun_map_key']['info'], $data['tengxun_map_key']['value'])->info($data['tengxun_map_key']['desc']),
  1830. ])->option('短信', [
  1831. Build::inputNum('verify_expire_time', $data['verify_expire_time']['info'], $data['verify_expire_time']['value'])->info($data['verify_expire_time']['desc'])->min(0),
  1832. ])->option('统计', [
  1833. Build::input('system_statistics', $data['system_statistics']['info'], $data['system_statistics']['value'])->rows(7)->type('textarea')->info($data['system_statistics']['desc']),
  1834. ])->option('ERP配置', [
  1835. Build::switch('erp_open', $data['erp_open']['info'], (int)$data['erp_open']['value'])->control(1, [
  1836. Build::radio('erp_type', $data['erp_type']['info'], $data['erp_type']['value'])->control(1, [
  1837. Build::input('jst_login_account', $data['jst_login_account']['info'], $data['jst_login_account']['value'])->info($data['jst_login_account']['desc']),
  1838. Build::input('jst_login_password', $data['jst_login_password']['info'], $data['jst_login_password']['value'])->info($data['jst_login_password']['desc']),
  1839. Build::input('jst_appkey', $data['jst_appkey']['info'], $data['jst_appkey']['value'])->info($data['jst_appkey']['desc']),
  1840. Build::input('jst_appsecret', $data['jst_appsecret']['info'], $data['jst_appsecret']['value'])->info($data['jst_appsecret']['desc']),
  1841. Build::input('jst_default_shopid', $data['jst_default_shopid']['info'], $data['jst_default_shopid']['value'])->info($data['jst_default_shopid']['desc']),
  1842. ])->options($this->getOptions($data['erp_type']['parameter']))->info($data['erp_type']['desc'])
  1843. ])->trueValue('打开', 1)->falseValue('关闭', 0),
  1844. ]),
  1845. ]);
  1846. return $build->toArray();
  1847. }
  1848. /**
  1849. * 微信开放平台
  1850. * @return array
  1851. */
  1852. public function wxOpenBaseFormBuild()
  1853. {
  1854. $build = new Build();
  1855. $build->url('setting/config/save_basics');
  1856. $data = $this->getConfigAllField([
  1857. 'wechat_open_app_id', 'wechat_open_app_secret'
  1858. ]);
  1859. $build->rule([
  1860. Build::card('微信开放平台')->components([
  1861. Build::alert('小程序、公众号、PC端登录、APP微信登录或企业微信用户同步必须配置微信开放平台,申请微信开放平台地址:https://open.weixin.qq.com', 'warning')->showIcon(true),
  1862. Build::input('wechat_open_app_id', $data['wechat_open_app_id']['info'], $data['wechat_open_app_id']['value'])->info($data['wechat_open_app_id']['desc']),
  1863. Build::input('wechat_open_app_secret', $data['wechat_open_app_secret']['info'], $data['wechat_open_app_secret']['value'])->info($data['wechat_open_app_secret']['desc']),
  1864. ]),
  1865. ]);
  1866. return $build->toArray();
  1867. }
  1868. /**
  1869. * PC设置
  1870. * @return array
  1871. */
  1872. public function pcBaseFormBuild()
  1873. {
  1874. $build = new Build();
  1875. $build->url('setting/config/save_basics');
  1876. $data = $this->getConfigAllField([
  1877. 'pc_logo', 'bast_number', 'first_number', 'product_phone_buy_url', 'contact_number',
  1878. 'company_address', 'copyright', 'seo_title', 'site_keywords', 'site_description', 'record_No',
  1879. 'wechat_open_app_id', 'wechat_open_app_secret', 'links_open', 'links_list', 'filing_list'
  1880. ]);
  1881. $base[] = Build::uploadFrame('pc_logo', $data['pc_logo']['info'], $data['pc_logo']['value'])->info($data['pc_logo']['desc'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html');
  1882. foreach (['contact_number', 'company_address', 'copyright', 'seo_title', 'site_keywords', 'site_description', 'record_No'] as $key) {
  1883. $base[] = Build::input($key, $data[$key]['info'], $data[$key]['value'])->info($data[$key]['desc'])->type($data[$key]['type']);
  1884. }
  1885. $open = [];
  1886. foreach (['wechat_open_app_id', 'wechat_open_app_secret'] as $key) {
  1887. $open[] = Build::input($key, $data[$key]['info'], $data[$key]['value'])->info($data[$key]['desc'])->type($data[$key]['type']);
  1888. }
  1889. $build->rule([
  1890. Build::card('基础设置')->components($base),
  1891. Build::card('商品设置')->components([
  1892. Build::inputNum('bast_number', $data['bast_number']['info'], $data['bast_number']['value'])->info($data['bast_number']['desc'])->min(0),
  1893. Build::inputNum('first_number', $data['first_number']['info'], $data['first_number']['value'])->info($data['first_number']['desc'])->min(0),
  1894. Build::radio('product_phone_buy_url', $data['product_phone_buy_url']['info'], $data['product_phone_buy_url']['value'])->info($data['product_phone_buy_url']['desc'])->options($this->getOptions($data['product_phone_buy_url']['parameter'])),
  1895. ]),
  1896. Build::card('微信开放平台(pc端用户扫码登录使用)')->components($open),
  1897. Build::card('友情链接')->components([
  1898. Build::switch('links_open', $data['links_open']['info'], (int)$data['links_open']['value'])->info($data['links_open']['desc'])->control(1, [
  1899. Build::diyTable('links_list', $data['links_list']['info'], is_array($data['links_list']['value']) ? $data['links_list']['value'] : [])->info($data['links_list']['desc'])
  1900. ->column('链接名称', 'name')->column('链接地址', 'url')->column('排序', 'sort', InputNumber::NAME, ['editable' => false]),
  1901. ])->trueValue('开启', 1)->falseValue('关闭', 0),
  1902. ]),
  1903. Build::card('底部(公安备案等自定义)')->components([
  1904. Build::diyTable('filing_list', $data['filing_list']['info'], is_array($data['filing_list']['value']) ? $data['filing_list']['value'] : [])->info($data['filing_list']['desc'])
  1905. ->column('图标', 'icon', 'image')->column('名称', 'name')->column('链接地址', 'url')->column('排序', 'sort', InputNumber::NAME, ['editable' => false])
  1906. ]),
  1907. ]);
  1908. return $build->toArray();
  1909. }
  1910. /**
  1911. * PC设置
  1912. * @return array
  1913. */
  1914. public function appBaseFormBuild()
  1915. {
  1916. $build = new Build();
  1917. $build->url('setting/config/save_basics');
  1918. $data = $this->getConfigAllField([
  1919. 'wechat_app_appid', 'wechat_app_appsecret', 'app_version', 'app_apk'
  1920. ]);
  1921. $open = [];
  1922. foreach (['wechat_app_appid', 'wechat_app_appsecret', 'app_version'] as $key) {
  1923. $open[] = Build::input($key, $data[$key]['info'], $data[$key]['value'])->info($data[$key]['desc'])->type($data[$key]['type']);
  1924. }
  1925. $open[] = Build::uploadImage('app_apk', $data['app_apk']['info'], $data['app_apk']['value'])
  1926. ->url('/file/upload/0?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  1927. ->type('file')->icon('md-add')->info($data['app_apk']['desc']);
  1928. $build->rule([
  1929. Build::card('微信开放平台(微信登录、支付都需要开通此配置)')->components($open),
  1930. ]);
  1931. return $build->toArray();
  1932. }
  1933. /**
  1934. * 微信基础配置
  1935. * @return array
  1936. */
  1937. public function wechatBaseFormBuild()
  1938. {
  1939. $build = new Build();
  1940. $build->url('setting/config/save_basics');
  1941. $data = $this->getConfigAllField([
  1942. 'share_qrcode', 'spread_share_forever', 'wechat_qrcode', 'wechat_appid',
  1943. 'wechat_appsecret', 'wechat_encodingaeskey', 'wechat_token', 'api', 'wechat_encode',
  1944. // 'wechat_share_img', 'wechat_share_title', 'wechat_share_synopsis',
  1945. 'create_wechat_user'
  1946. ]);
  1947. $build->rule([
  1948. Build::card('公众号开发者信息')->components([
  1949. Build::input('wechat_appid', $data['wechat_appid']['info'], $data['wechat_appid']['value'])->info($data['wechat_appid']['desc']),
  1950. Build::input('wechat_appsecret', $data['wechat_appsecret']['info'], $data['wechat_appsecret']['value'])->info($data['wechat_appsecret']['desc']),
  1951. ]),
  1952. Build::card('服务器配置')->components([
  1953. Build::input('wechat_encodingaeskey', $data['wechat_encodingaeskey']['info'], $data['wechat_encodingaeskey']['value'])->info($data['wechat_encodingaeskey']['desc'])->randAESK(),
  1954. Build::input('wechat_token', $data['wechat_token']['info'], $data['wechat_token']['value'])->info($data['wechat_token']['desc'])->randToken(),
  1955. Build::input('api', $data['api']['info'], sys_config('site_url') . '/api/wechat/serve')->info($data['api']['desc'])->disabled()->copy(),
  1956. Build::radio('wechat_encode', $data['wechat_encode']['info'], $data['wechat_encode']['value'])->vertical(true)->info($data['wechat_encode']['desc'])->options($this->getOptions($data['wechat_encode']['parameter'])),
  1957. ]),
  1958. Build::card('微信公众号')->components([
  1959. Build::radio('share_qrcode', $data['share_qrcode']['info'], $data['share_qrcode']['value'])->info($data['share_qrcode']['desc'])->options($this->getOptions($data['share_qrcode']['parameter'])),
  1960. Build::radio('spread_share_forever', $data['spread_share_forever']['info'], $data['spread_share_forever']['value'])->info($data['spread_share_forever']['desc'])->options($this->getOptions($data['spread_share_forever']['parameter'])),
  1961. Build::uploadFrame('wechat_qrcode', $data['wechat_qrcode']['info'], $data['wechat_qrcode']['value'])->info($data['wechat_qrcode']['desc'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html'),
  1962. Build::switch('create_wechat_user', $data['create_wechat_user']['info'], (int)$data['create_wechat_user']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['create_wechat_user']['desc']),
  1963. ]),
  1964. // Build::card('首页分享')->components([
  1965. // Build::uploadFrame('wechat_share_img', $data['wechat_share_img']['info'], $data['wechat_share_img']['value'])->info($data['wechat_share_img']['desc'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html'),
  1966. // Build::input('wechat_share_title', $data['wechat_share_title']['info'], $data['wechat_share_title']['value'])->info($data['wechat_share_title']['desc']),
  1967. // Build::input('wechat_share_synopsis', $data['wechat_share_synopsis']['info'], $data['wechat_share_synopsis']['value'])->type('textarea')->info($data['wechat_share_synopsis']['desc']),
  1968. // ])
  1969. ]);
  1970. return $build->toArray();
  1971. }
  1972. /**
  1973. * 小程序基础配置
  1974. * @return array
  1975. */
  1976. public function routineBaseFormBuild()
  1977. {
  1978. $data = $this->getConfigAllField([
  1979. 'routine_appId', 'routine_appsecret', 'routine_contact_type', 'routine_name', 'store_user_avatar', 'order_shipping_open', 'routine_auth_type', 'store_user_agreement'
  1980. ]);
  1981. return $data;
  1982. }
  1983. /**
  1984. * 支付
  1985. * @return array
  1986. */
  1987. public function shopPayFormBuild()
  1988. {
  1989. $build = new Build();
  1990. $build->url('setting/config/save_basics');
  1991. $data = $this->getConfigAllField([
  1992. 'pay_weixin_open', 'pay_weixin_mchid', 'pay_weixin_key', 'paydir', 'yue_pay_status', 'is_cashier_yue_pay_verify', 'offline_pay_status',
  1993. 'offline_pay_status', 'ali_pay_status', 'ali_pay_appid', 'alipay_public_key', 'alipay_merchant_private_key',
  1994. 'pay_weixin_client_cert', 'pay_wechat_type', 'pay_weixin_serial_no', 'v3_pay_weixin_key', 'pay_weixin_client_key', 'pay_routine_open', 'pay_routine_mchid'
  1995. ]);
  1996. $site_url = sys_config('site_url', '');
  1997. $build->rule([
  1998. Build::tabs()->option('微信支付', [
  1999. Build::alert('登录微信商户(地址:https://pay.weixin.qq.com,支付授权目录、回调链接:' . $site_url . '; http,https最好都配置),帮助文档地址:https://doc.crmeb.com/web/pro/crmebprov2/1203', Alert::WARNING)->showIcon(true),
  2000. Build::switch('pay_weixin_open', $data['pay_weixin_open']['info'], (int)$data['pay_weixin_open']['value'])->control(1, [
  2001. Build::input('pay_weixin_mchid', $data['pay_weixin_mchid']['info'], $data['pay_weixin_mchid']['value'])->info($data['pay_weixin_mchid']['desc']),
  2002. Build::radio('pay_wechat_type', $data['pay_wechat_type']['info'], (int)$data['pay_wechat_type']['value'])->control(1, [
  2003. Build::input('pay_weixin_serial_no', $data['pay_weixin_serial_no']['info'], $data['pay_weixin_serial_no']['value'])->info($data['pay_weixin_serial_no']['desc']),
  2004. Build::input('v3_pay_weixin_key', $data['v3_pay_weixin_key']['info'], $data['v3_pay_weixin_key']['value'])->info($data['v3_pay_weixin_key']['desc']),
  2005. ])->control(0, [
  2006. Build::input('pay_weixin_key', $data['pay_weixin_key']['info'], $data['pay_weixin_key']['value'])->info($data['pay_weixin_key']['desc']),
  2007. ])->options($this->getOptions($data['pay_wechat_type']['parameter']))->info($data['pay_wechat_type']['desc']),
  2008. Build::uploadImage('pay_weixin_client_cert', $data['pay_weixin_client_cert']['info'], $data['pay_weixin_client_cert']['value'])
  2009. ->url('/file/upload/1?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  2010. ->type('file')->icon('md-add')->info($data['pay_weixin_client_cert']['desc']),
  2011. Build::uploadImage('pay_weixin_client_key', $data['pay_weixin_client_key']['info'], $data['pay_weixin_client_key']['value'])
  2012. ->url('/file/upload/1?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  2013. ->type('file')->icon('md-add')->info($data['pay_weixin_client_key']['desc']),
  2014. Build::switch('pay_routine_open', $data['pay_routine_open']['info'], (int)$data['pay_routine_open']['value'])->control(1, [
  2015. Build::input('pay_routine_mchid', $data['pay_routine_mchid']['info'], $data['pay_routine_mchid']['value'])->info($data['pay_routine_mchid']['desc'])
  2016. ])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['pay_routine_open']['desc'])
  2017. ])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['pay_weixin_open']['desc']),
  2018. ])->option('余额支付', [
  2019. Build::switch('yue_pay_status', $data['yue_pay_status']['info'], (int)$data['yue_pay_status']['value'])->trueValue('开启', 1)->falseValue('关闭', 2)->info($data['yue_pay_status']['desc']),
  2020. Build::switch('is_cashier_yue_pay_verify', $data['is_cashier_yue_pay_verify']['info'], (int)$data['is_cashier_yue_pay_verify']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['is_cashier_yue_pay_verify']['desc'])
  2021. ])->option('线下支付', [
  2022. Build::switch('offline_pay_status', $data['offline_pay_status']['info'], (int)$data['offline_pay_status']['value'])->trueValue('开启', 1)->falseValue('关闭', 2)->info($data['offline_pay_status']['desc'])
  2023. ])->option('支付宝支付', [
  2024. Build::alert('登录支付宝商家(地址:https://b.alipay.com,需要配置ip白名单以及回调地址回调地址:' . $site_url . '),帮助文档地址:https://doc.crmeb.com/web/pro/crmebprov2/1204', Alert::WARNING)->showIcon(true),
  2025. Build::switch('ali_pay_status', $data['ali_pay_status']['info'], (int)$data['ali_pay_status']['value'])->control(1, [
  2026. Build::input('ali_pay_appid', $data['ali_pay_appid']['info'], $data['ali_pay_appid']['value'])->info($data['ali_pay_appid']['desc']),
  2027. Build::input('alipay_public_key', $data['alipay_public_key']['info'], $data['alipay_public_key']['value'])->rows(5)->type('textarea')->info($data['alipay_public_key']['desc']),
  2028. Build::input('alipay_merchant_private_key', $data['alipay_merchant_private_key']['info'], $data['alipay_merchant_private_key']['value'])->rows(5)->type('textarea')->info($data['alipay_merchant_private_key']['desc']),
  2029. ])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['ali_pay_status']['desc']),
  2030. ]),
  2031. ]);
  2032. return $build->toArray();
  2033. }
  2034. /**
  2035. * 砍价设置
  2036. * @return array
  2037. */
  2038. public function bargainFormBuild()
  2039. {
  2040. $build = new Build();
  2041. $build->url('setting/config/save_basics');
  2042. $data = $this->getConfigAllField([
  2043. 'bargain_subscribe'
  2044. ]);
  2045. $build->rule([
  2046. Build::card('砍价设置')->components([
  2047. Build::switch('bargain_subscribe', $data['bargain_subscribe']['info'], (int)$data['bargain_subscribe']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['bargain_subscribe']['desc']),
  2048. ]),
  2049. ]);
  2050. return $build->toArray();
  2051. }
  2052. /**
  2053. * 交易设置
  2054. * @return array
  2055. */
  2056. public function shopTradeFormBuild()
  2057. {
  2058. $build = new Build();
  2059. $build->url('setting/config/save_basics');
  2060. $data = $this->getConfigAllField([
  2061. 'store_stock', 'order_cancel_time', 'order_activity_time',
  2062. 'order_bargain_time', 'order_seckill_time', 'order_pink_time',
  2063. 'system_delivery_time', 'refund_name', 'refund_phone', 'refund_address', 'stor_reason', 'collate_not_operating_time', 'reminder_deadline_second_card_time',
  2064. 'bargain_subscribe', 'system_comment_time', 'rebate_points_orders_time', 'table_code_not_operating_time',
  2065. 'max_price', 'min_price', 'order_time'
  2066. // 'store_cashier_order_rate', 'store_recharge_order_rate', 'store_self_order_rate', 'store_svip_order_rate', 'store_writeoff_order_rate'
  2067. ]);
  2068. $timeData[] = Build::alert('营销活动未支付时间如果设置为0将使用默认活动取消时间,优先使用单独活动配置', Alert::WARNING)->showIcon(true);
  2069. foreach (['order_cancel_time', 'order_activity_time',
  2070. 'order_bargain_time', 'order_seckill_time', 'order_pink_time', 'rebate_points_orders_time', 'table_code_not_operating_time', 'collate_not_operating_time', 'reminder_deadline_second_card_time'] as $item) {
  2071. $timeData[] = Build::inputNum($item, $data[$item]['info'], $data[$item]['value'])->info($data[$item]['desc'])->min(0);
  2072. }
  2073. $refund[] = Build::alert('售后处理默认退货地址(门店订单退货默认门店地址)', Alert::WARNING)->showIcon(true);
  2074. foreach (['refund_name', 'refund_phone', 'refund_address', 'stor_reason'] as $key) {
  2075. $rule = Build::input($key, $data[$key]['info'], $data[$key]['value'])->rows(5)->type($data[$key]['type'])->info($data[$key]['desc']);
  2076. if ('refund_phone' === $key) {
  2077. $rule->validate(StrRules::pattern(StrRules::PHONE_NUMBER)->message('请输入正确的手机号码'));
  2078. }
  2079. $refund[] = $rule;
  2080. }
  2081. // $store[] = Build::alert('需要和门店对账,请仔细配置(配置立即生效,不影响已成交订单)', Alert::WARNING)->showIcon(true);
  2082. // foreach (['store_cashier_order_rate', 'store_recharge_order_rate', 'store_self_order_rate', 'store_svip_order_rate', 'store_writeoff_order_rate'] as $key) {
  2083. // $store[] = Build::inputNum($key, $data[$key]['info'], $data[$key]['value'])->min(0)->info($data[$key]['desc']);
  2084. // }
  2085. $build->rule([
  2086. Build::card('库存警戒')->components([
  2087. Build::inputNum('store_stock', $data['store_stock']['info'], $data['store_stock']['value'])->info($data['store_stock']['desc'])->min(0),
  2088. ]),
  2089. Build::card('订单取消时间')->components($timeData),
  2090. Build::card('自动收货时间')->components([
  2091. Build::alert('输入0为不设置自动收货', Alert::WARNING)->showIcon(true),
  2092. Build::inputNum('system_delivery_time', $data['system_delivery_time']['info'], $data['system_delivery_time']['value'])->info($data['system_delivery_time']['desc'])->min(0),
  2093. ]),
  2094. Build::card('下单设置')->components([
  2095. Build::inputNum('order_time', $data['order_time']['info'], $data['order_time']['value'])->info($data['order_time']['desc'])->min(0),
  2096. Build::inputNum('min_price', $data['min_price']['info'], $data['min_price']['value'])->info($data['min_price']['desc'])->min(0),
  2097. Build::inputNum('max_price', $data['max_price']['info'], $data['max_price']['value'])->info($data['max_price']['desc'])->min(0),
  2098. ]),
  2099. Build::card('自动默认好评时间')->components([
  2100. Build::alert('输入0为不设置自动默认好评', Alert::WARNING)->showIcon(true),
  2101. Build::inputNum('system_comment_time', $data['system_comment_time']['info'], $data['system_comment_time']['value'])->info($data['system_comment_time']['desc'])->min(0),
  2102. ]),
  2103. Build::card('售后退款设置')->components($refund),
  2104. // Build::card('门店手续费设置')->components($store),
  2105. ]);
  2106. return $build->toArray();
  2107. }
  2108. /**
  2109. * 商城首页
  2110. * @return array
  2111. */
  2112. public function shopBaseFormBuild()
  2113. {
  2114. $build = new Build();
  2115. $build->url('setting/config/save_basics');
  2116. $data = $this->getConfigAllField([
  2117. 'station_open', 'site_name', 'site_url', 'wap_login_logo', 'site_phone',
  2118. 'admin_login_slide', 'site_logo', 'site_logo_square', 'login_logo',
  2119. 'navigation_open', 'cache_config', 'start_login_logo',
  2120. // 'store_func_status',
  2121. 'video_func_status', 'product_video_status',
  2122. // 'h5_avatar', 'store_user_mobile'
  2123. 'wechat_share_img', 'wechat_share_title', 'wechat_share_synopsis', 'product_poster_title',
  2124. 'hidden_integral'
  2125. ]);
  2126. $system = [];
  2127. foreach (['site_name', 'site_url', 'site_phone', 'cache_config'] as $key) {
  2128. $system[] = Build::input($key, $data[$key]['info'], $data[$key]['value'])->maxlength($key === 'site_name' ? 20 : null)->info($data[$key]['desc'])->type($data[$key]['type']);
  2129. }
  2130. $setting = [];
  2131. foreach (['site_logo', 'site_logo_square', 'login_logo', 'admin_login_slide', 'start_login_logo'] as $key) {
  2132. $setting[] = Build::uploadFrame($key, $data[$key]['info'], $data[$key]['value'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html')->info($data[$key]['desc'])->maxNum($key === 'admin_login_slide' ? 5 : 1);
  2133. }
  2134. $build->rule([
  2135. Build::tabs()->option('系统信息', [
  2136. Build::switch('station_open', $data['station_open']['info'], (int)$data['station_open']['value'])->control(1, $system)->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['station_open']['desc']),
  2137. Build::switch('hidden_integral', $data['hidden_integral']['info'], (int)$data['hidden_integral']['value'])->trueValue('显示', 1)->falseValue('隐藏', 0)->info($data['hidden_integral']['desc']),
  2138. ])->option('后台设置', $setting)
  2139. ->option('移动端设置', [
  2140. Build::uploadFrame('wap_login_logo', $data['wap_login_logo']['info'], $data['wap_login_logo']['value'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html')->info($data['wap_login_logo']['desc']),
  2141. // Build::uploadFrame('h5_avatar', $data['h5_avatar']['info'], $data['h5_avatar']['value'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html')->info($data['h5_avatar']['desc']),
  2142. // Build::radio('store_user_mobile', $data['store_user_mobile']['info'], $data['store_user_mobile']['value'])->options($this->getOptions($data['store_user_mobile']['parameter']))->info($data['store_user_mobile']['desc']),
  2143. Build::switch('navigation_open', $data['navigation_open']['info'], (int)$data['navigation_open']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['navigation_open']['desc']),
  2144. // Build::switch('store_func_status', $data['store_func_status']['info'], (int)$data['store_func_status']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['store_func_status']['desc']),
  2145. Build::switch('video_func_status', $data['video_func_status']['info'], (int)$data['video_func_status']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['video_func_status']['desc']),
  2146. Build::switch('product_video_status', $data['product_video_status']['info'], (int)$data['product_video_status']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['product_video_status']['desc']),
  2147. ])
  2148. ->option('分享设置', [
  2149. Build::uploadFrame('wechat_share_img', $data['wechat_share_img']['info'], $data['wechat_share_img']['value'])->info($data['wechat_share_img']['desc'])->url('/' . config('admin.admin_prefix') . '/widget.images/index.html'),
  2150. Build::input('wechat_share_title', $data['wechat_share_title']['info'], $data['wechat_share_title']['value'])->info($data['wechat_share_title']['desc']),
  2151. Build::input('wechat_share_synopsis', $data['wechat_share_synopsis']['info'], $data['wechat_share_synopsis']['value'])->type('textarea')->info($data['wechat_share_synopsis']['desc']),
  2152. Build::input('product_poster_title', $data['product_poster_title']['info'], $data['product_poster_title']['value'])->maxlength(25)->info($data['product_poster_title']['desc']),
  2153. ]),
  2154. // ->option('APP微信开放平台', [
  2155. // Build::alert('小程序、公众号、PC端登录、APP微信登录或企业微信用户同步必须配置微信开放平台,申请微信开放平台地址:https://open.weixin.qq.com', 'warning')->showIcon(true),
  2156. // Build::input('wechat_app_appid', $data['wechat_app_appid']['info'], $data['wechat_app_appid']['value'])->info($data['wechat_app_appid']['desc']),
  2157. // Build::input('wechat_app_appsecret', $data['wechat_app_appsecret']['info'], $data['wechat_app_appsecret']['value'])->info($data['wechat_app_appsecret']['desc']),
  2158. // ]),
  2159. ]);
  2160. return $build->toArray();
  2161. }
  2162. /**
  2163. * 门店设置
  2164. * @return array
  2165. */
  2166. public function storeFormBuild()
  2167. {
  2168. $build = new Build();
  2169. $build->url('setting/config/save_basics');
  2170. $data = $this->getConfigAllField([
  2171. 'store_func_status', 'store_delivery_scope', 'store_splicing_switch', 'store_self_mention'
  2172. ]);
  2173. $build->rule([
  2174. Build::card('门店设置')->components([
  2175. Build::switch('store_func_status', $data['store_func_status']['info'], (int)$data['store_func_status']['value'])
  2176. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  2177. Build::switch('store_self_mention', $data['store_self_mention']['info'], (int)$data['store_self_mention']['value'] > 0 ? 1 : 0)
  2178. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['store_self_mention']['desc'] ?? ''),
  2179. Build::switch('store_delivery_scope', $data['store_delivery_scope']['info'], (int)$data['store_delivery_scope']['value'])
  2180. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['store_delivery_scope']['desc']),
  2181. Build::switch('store_splicing_switch', $data['store_splicing_switch']['info'], (int)$data['store_splicing_switch']['value'])
  2182. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['store_splicing_switch']['desc']),
  2183. ])->info($data['store_func_status']['desc']),
  2184. ]),
  2185. ]);
  2186. return $build->toArray();
  2187. }
  2188. /**
  2189. * 企业微信配置
  2190. * @return array
  2191. */
  2192. public function workFormBuild()
  2193. {
  2194. $build = new Build();
  2195. $build->url('setting/config/save_basics');
  2196. $data = $this->getConfigAllField([
  2197. 'wechat_work_corpid', 'wechat_work_address_secret', 'wechat_work_token', 'wechat_work_aes_key',
  2198. 'wechat_work_user_secret', 'wechat_work_build_agent_id', 'wechat_work_build_secret',
  2199. ]);
  2200. $build->rule([
  2201. Build::card('企业微信基础配置')->components([
  2202. Build::input('wechat_work_corpid', $data['wechat_work_corpid']['info'], $data['wechat_work_corpid']['value'])->info($data['wechat_work_corpid']['desc']),
  2203. ]),
  2204. Build::card('企业微信通讯录配置')->components([
  2205. Build::alert('1.请先登录企业微信:https://work.weixin.qq.com 客户与上下游->客户联系->关联微信开发者ID。2.请必须绑定微信开放平台', Alert::WARNING)->closable(true),
  2206. Build::input('wechat_work_address_secret', $data['wechat_work_address_secret']['info'], $data['wechat_work_address_secret']['value'])->info($data['wechat_work_address_secret']['desc']),
  2207. Build::input('wechat_work_token', $data['wechat_work_token']['info'], $data['wechat_work_token']['value'])->randToken()->copy()->info($data['wechat_work_token']['desc']),
  2208. Build::input('wechat_work_aes_key', $data['wechat_work_aes_key']['info'], $data['wechat_work_aes_key']['value'])->randAESK()->copy()->info($data['wechat_work_aes_key']['desc']),
  2209. Build::input('work_address_url', '服务器地址', sys_config('site_url') . '/api/work/serve')->disabled()->copy(),
  2210. ]),
  2211. Build::card('企业微信客户设置')->components([
  2212. Build::input('wechat_work_user_secret', $data['wechat_work_user_secret']['info'], $data['wechat_work_user_secret']['value'])->info($data['wechat_work_user_secret']['desc']),
  2213. ]),
  2214. Build::card('企业微信自建应用设置')->components([
  2215. Build::input('wechat_work_build_agent_id', $data['wechat_work_build_agent_id']['info'], $data['wechat_work_build_agent_id']['value'])->info($data['wechat_work_build_agent_id']['desc']),
  2216. Build::input('wechat_work_build_secret', $data['wechat_work_build_secret']['info'], $data['wechat_work_build_secret']['value'])->info($data['wechat_work_build_secret']['desc']),
  2217. ]),
  2218. ]);
  2219. return $build->toArray();
  2220. }
  2221. /**
  2222. * 门店财务设置
  2223. * @return array
  2224. */
  2225. public function financeFormBuild()
  2226. {
  2227. $build = new Build();
  2228. $build->url('setting/config/save_basics');
  2229. $data = $this->getConfigAllField([
  2230. 'store_cashier_order_rate', 'store_self_order_rate', 'store_writeoff_order_rate', 'store_recharge_order_rate',
  2231. 'store_svip_order_rate', 'store_extract_min_price', 'store_extract_max_price',
  2232. ]);
  2233. $build->rule([
  2234. Build::tabs()->option('手续费', [
  2235. Build::inputNum('store_cashier_order_rate', $data['store_cashier_order_rate']['info'], $data['store_cashier_order_rate']['value'])
  2236. ->info($data['store_cashier_order_rate']['desc'])->min(0),
  2237. Build::inputNum('store_self_order_rate', $data['store_self_order_rate']['info'], $data['store_self_order_rate']['value'])
  2238. ->info($data['store_self_order_rate']['desc'])->min(0),
  2239. Build::inputNum('store_writeoff_order_rate', $data['store_writeoff_order_rate']['info'], $data['store_writeoff_order_rate']['value'])
  2240. ->info($data['store_writeoff_order_rate']['desc'])->min(0),
  2241. Build::inputNum('store_recharge_order_rate', $data['store_recharge_order_rate']['info'], $data['store_recharge_order_rate']['value'])
  2242. ->info($data['store_recharge_order_rate']['desc'])->min(0),
  2243. Build::inputNum('store_svip_order_rate', $data['store_svip_order_rate']['info'], $data['store_svip_order_rate']['value'])
  2244. ->info($data['store_svip_order_rate']['desc'])->min(0),
  2245. ])->option('提现设置', [
  2246. Build::inputNum('store_extract_min_price', $data['store_extract_min_price']['info'], $data['store_extract_min_price']['value'])
  2247. ->info($data['store_extract_min_price']['desc'])->min(0),
  2248. Build::inputNum('store_extract_max_price', $data['store_extract_max_price']['info'], $data['store_extract_max_price']['value'])
  2249. ->info($data['store_extract_max_price']['desc'])->min(0),
  2250. ])
  2251. ]);
  2252. return $build->toArray();
  2253. }
  2254. /**
  2255. * 供应商财务设置
  2256. * @return array
  2257. */
  2258. public function supplierFinanceFormBuild()
  2259. {
  2260. $build = new Build();
  2261. $build->url('setting/config/save_basics');
  2262. $data = $this->getConfigAllField(['supplier_extract_min_price', 'supplier_extract_max_price']);
  2263. $build->rule([
  2264. Build::tabs()->option('财务设置', [
  2265. Build::inputNum('supplier_extract_min_price', $data['supplier_extract_min_price']['info'], $data['supplier_extract_min_price']['value'])
  2266. ->info($data['supplier_extract_min_price']['desc'])->min(0),
  2267. Build::inputNum('supplier_extract_max_price', $data['supplier_extract_max_price']['info'], $data['supplier_extract_max_price']['value'])
  2268. ->info($data['supplier_extract_max_price']['desc'])->min(0),
  2269. ])
  2270. ]);
  2271. return $build->toArray();
  2272. }
  2273. /**
  2274. * 获取缩略图配置
  2275. * @return array
  2276. */
  2277. public function getImageConfig()
  2278. {
  2279. return $this->getConfigAllField([
  2280. 'image_watermark_status', 'thumb_big_width', 'thumb_big_height', 'thumb_mid_width',
  2281. 'thumb_mid_height', 'thumb_small_width', 'thumb_small_height', 'watermark_type',
  2282. 'watermark_text', 'watermark_text_angle', 'watermark_text_color', 'watermark_text_size',
  2283. 'watermark_position', 'watermark_image', 'watermark_opacity', 'watermark_rotate',
  2284. 'watermark_x', 'watermark_y', 'upload_type'
  2285. ]);
  2286. }
  2287. /**
  2288. * 获取配置
  2289. * @param string $key
  2290. * @param null $default
  2291. * @return mixed
  2292. */
  2293. public function getConfig(string $key, $default = null)
  2294. {
  2295. return sys_config($key, $default);
  2296. }
  2297. /**
  2298. * 获取用户基础配置
  2299. * @param string $type
  2300. * @return mixed
  2301. */
  2302. public function getUserConfig(string $type = 'basic')
  2303. {
  2304. switch ($type) {
  2305. case 'basic'://基础
  2306. $data = $this->getConfigAllField(['h5_avatar', 'user_extend_info'], 0, 1);
  2307. if (!$data['user_extend_info']) {//没保存过,获取默认数据
  2308. /** @var UserServices $userServices */
  2309. $userServices = app()->make(UserServices::class);
  2310. $data['user_extend_info'] = $userServices->defaultExtendInfo;
  2311. }
  2312. break;
  2313. case 'register'://注册
  2314. $data = $this->getConfigAllField(['store_user_mobile', 'routine_auth_type', 'store_user_agreement', 'newcomer_status', 'newcomer_limit_status', 'newcomer_limit_time', 'register_integral_status', 'register_give_integral', 'register_money_status', 'register_give_money', 'register_coupon_status', 'register_give_coupon', 'first_order_status', 'first_order_discount', 'first_order_discount_limit', 'register_price_status'], 0, 1);
  2315. /** @var StoreNewcomerServices $newcomerServices */
  2316. $newcomerServices = app()->make(StoreNewcomerServices::class);
  2317. $data['product'] = $newcomerServices->getCustomerProduct();
  2318. /** @var CacheServices $cache */
  2319. $cache = app()->make(CacheServices::class);
  2320. $data['newcomer_agreement'] = $cache->getDbCache('newcomer_agreement', '');
  2321. $ids = $data['register_give_coupon'] ?? [];
  2322. $data['register_give_coupon'] = [];
  2323. if ($data['register_coupon_status'] && $ids) {
  2324. /** @var StoreCouponIssueServices $couponServices */
  2325. $couponServices = app()->make(StoreCouponIssueServices::class);
  2326. $coupon = $couponServices->getList(['id' => $ids]);
  2327. $data['register_give_coupon'] = $coupon;
  2328. }
  2329. $data['register_notice'] = '多端(公众号、小程序)账号统一,可以开启强制手机号登录实现,也可以绑定微信开放平台实现:https://open.weixin.qq.com';
  2330. break;
  2331. case 'level'://等级
  2332. $data = $this->getConfigAllField(['member_func_status', 'member_price_status', 'order_give_exp', 'sign_give_exp', 'invite_user_exp', 'level_activate_status', 'level_activate_status', 'level_integral_status', 'level_give_integral', 'level_money_status', 'level_give_money', 'level_coupon_status', 'level_give_coupon', 'level_extend_info'], 0, 1);
  2333. $ids = $data['level_give_coupon'] ?? [];
  2334. $data['level_give_coupon'] = [];
  2335. if ($data['level_coupon_status'] && $ids) {
  2336. /** @var StoreCouponIssueServices $couponServices */
  2337. $couponServices = app()->make(StoreCouponIssueServices::class);
  2338. $coupon = $couponServices->getList(['id' => $ids]);
  2339. $data['level_give_coupon'] = $coupon;
  2340. }
  2341. break;
  2342. case 'svip'://付费会员
  2343. $data = $this->getConfigAllField(['member_card_status', 'svip_price_status'], 0, 1);
  2344. break;
  2345. default:
  2346. throw new AdminException('类型错误');
  2347. break;
  2348. }
  2349. return $data;
  2350. }
  2351. /**
  2352. * 保存用户设置
  2353. * @param string $type
  2354. * @param array $data
  2355. * @return bool
  2356. */
  2357. public function saveUserConfig(string $type, array $data)
  2358. {
  2359. switch ($type) {
  2360. case 'basic'://基础
  2361. break;
  2362. case 'register'://注册
  2363. $products = $data['product'] ?? [];
  2364. //新人专享商品
  2365. /** @var StoreNewcomerServices $newcomerServices */
  2366. $newcomerServices = app()->make(StoreNewcomerServices::class);
  2367. $newcomerServices->saveNewcomer($products);
  2368. //新人专享规则说明
  2369. /** @var CacheServices $cache */
  2370. $cache = app()->make(CacheServices::class);
  2371. $content = $data['newcomer_agreement'] ?? '';
  2372. $cache->setDbCache('newcomer_agreement', $content);
  2373. unset($data['product'], $data['newcomer_agreement']);
  2374. break;
  2375. case 'level'://等级
  2376. break;
  2377. case 'svip'://付费会员
  2378. break;
  2379. }
  2380. foreach ($data as $k => $v) {
  2381. $config_one = $this->dao->getOne(['menu_name' => $k]);
  2382. if ($config_one) {
  2383. $config_one['value'] = $v;
  2384. $this->valiDateValue($config_one);
  2385. $this->dao->update($k, ['value' => json_encode($v)], 'menu_name');
  2386. }
  2387. }
  2388. \crmeb\services\SystemConfigService::clear();
  2389. return true;
  2390. }
  2391. }