SystemConfigServices.php 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511
  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',
  1426. 'pay_weixin_client_cert', 'pay_weixin_client_key', 'withdraw_fee', '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_brokerage_ratio', 'extract_speed_ratio', 'extract_speed_num', 'extract_spread_ratio',
  1429. ]);
  1430. $build->rule([
  1431. Build::tabs()->option('分销模式', [
  1432. Build::switch('brokerage_func_status', $data['brokerage_func_status']['info'], (int)$data['brokerage_func_status']['value'])
  1433. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1434. Build::radio('brokerage_level', $data['brokerage_level']['info'], $data['brokerage_level']['value'])->info($data['brokerage_level']['desc'])->options($this->getOptions($data['brokerage_level']['parameter'])),
  1435. Build::radio('store_brokerage_statu', $data['store_brokerage_statu']['info'], $data['store_brokerage_statu']['value'])
  1436. ->info($data['store_brokerage_statu']['desc'])
  1437. ->options($this->getOptions($data['store_brokerage_statu']['parameter']))
  1438. ->control(3, [
  1439. Build::inputNum('store_brokerage_price', $data['store_brokerage_price']['info'], $data['store_brokerage_price']['value'])->info($data['store_brokerage_price']['desc'])
  1440. ]),
  1441. Build::radio('brokerage_bindind', $data['brokerage_bindind']['info'], $data['brokerage_bindind']['value'])->info($data['brokerage_bindind']['desc'])->options($this->getOptions($data['brokerage_bindind']['parameter'])),
  1442. Build::radio('store_brokerage_binding_status', $data['store_brokerage_binding_status']['info'], $data['store_brokerage_binding_status']['value'])
  1443. ->options($this->getOptions($data['store_brokerage_binding_status']['parameter']))
  1444. ->control(2, [
  1445. 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']),
  1446. ])->info($data['store_brokerage_binding_status']['desc']),
  1447. 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')
  1448. ])->info($data['brokerage_func_status']['desc']),
  1449. ])->option('返佣设置', [
  1450. // 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']),
  1451. // Build::inputNum('store_brokerage_ratio', $data['store_brokerage_ratio']['info'], $data['store_brokerage_ratio']['value'])->min(0)->info($data['store_brokerage_ratio']['desc']),
  1452. // Build::inputNum('store_brokerage_two', $data['store_brokerage_two']['info'], $data['store_brokerage_two']['value'])->min(0)->info($data['store_brokerage_two']['desc']),
  1453. // Build::inputNum('extract_time', $data['extract_time']['info'], $data['extract_time']['value'])->min(0)->info($data['extract_time']['desc']),
  1454. // Build::switch('is_self_brokerage', $data['is_self_brokerage']['info'], (int)$data['is_self_brokerage']['value'])
  1455. // ->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['is_self_brokerage']['desc']),
  1456. // Build::switch('brokerage_user_status', $data['brokerage_user_status']['info'], (int)$data['brokerage_user_status']['value'])->control(1, [
  1457. // Build::inputNum('uni_brokerage_price', $data['uni_brokerage_price']['info'], $data['uni_brokerage_price']['value'])->min(0)->info($data['uni_brokerage_price']['desc']),
  1458. // 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']),
  1459. // ])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['brokerage_user_status']['desc']),
  1460. Build::inputNum('static_integral_ratio', $data['static_integral_ratio']['info'], $data['static_integral_ratio']['value'])->min(0)->info($data['static_integral_ratio']['desc']),
  1461. Build::inputNum('lake_ratio', $data['lake_ratio']['info'], $data['lake_ratio']['value'])->min(0)->info($data['lake_ratio']['desc']),
  1462. Build::inputNum('recommend_integral', $data['recommend_integral']['info'], $data['recommend_integral']['value'])->min(0)->info($data['recommend_integral']['desc']),
  1463. Build::inputNum('recommend_speed_integral', $data['recommend_speed_integral']['info'], $data['recommend_speed_integral']['value'])->min(0)->info($data['recommend_speed_integral']['desc']),
  1464. Build::inputNum('static_integral_rate', $data['static_integral_rate']['info'], $data['static_integral_rate']['value'])->min(0)->info($data['static_integral_rate']['desc']),
  1465. Build::inputNum('action_integral_rate', $data['action_integral_rate']['info'], $data['action_integral_rate']['value'])->min(0)->info($data['action_integral_rate']['desc']),
  1466. Build::inputNum('extract_ratio', $data['extract_ratio']['info'], $data['extract_ratio']['value'])->min(0)->info($data['extract_ratio']['desc']),
  1467. Build::inputNum('extract_brokerage_ratio', $data['extract_brokerage_ratio']['info'], $data['extract_brokerage_ratio']['value'])->min(0)->info($data['extract_brokerage_ratio']['desc']),
  1468. Build::inputNum('extract_speed_ratio', $data['extract_speed_ratio']['info'], $data['extract_speed_ratio']['value'])->min(0)->info($data['extract_speed_ratio']['desc']),
  1469. Build::inputNum('extract_speed_num', $data['extract_speed_num']['info'], $data['extract_speed_num']['value'])->min(0)->info($data['extract_speed_num']['desc']),
  1470. Build::inputNum('extract_spread_ratio', $data['extract_spread_ratio']['info'], $data['extract_spread_ratio']['value'])->min(0)->info($data['extract_spread_ratio']['desc']),
  1471. ])->option('提现设置', [
  1472. Build::alert('微信提现到零钱为自动到账(需要开通微信:企业付款到零钱(商家转账到零钱),并确保配置微信支付证书正确,特别注意:需要配置场景、开启API发起转账),其他方式均需要手动转账', Alert::WARNING)->showIcon(true),
  1473. Build::radio('brokerage_type', $data['brokerage_type']['info'], $data['brokerage_type']['value'])->options($this->getOptions($data['brokerage_type']['parameter']))->control(1, [
  1474. Build::uploadImage('pay_weixin_client_cert', $data['pay_weixin_client_cert']['info'], $data['pay_weixin_client_cert']['value'])
  1475. ->url('/file/upload/1?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  1476. ->type('file')->icon('md-add')->info($data['pay_weixin_client_cert']['desc']),
  1477. Build::uploadImage('pay_weixin_client_key', $data['pay_weixin_client_key']['info'], $data['pay_weixin_client_key']['value'])
  1478. ->url('/file/upload/1?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  1479. ->type('file')->icon('md-add')->info($data['pay_weixin_client_key']['desc']),
  1480. ])->info($data['brokerage_type']['desc']),
  1481. 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']),
  1482. Build::inputNum('withdraw_fee', $data['withdraw_fee']['info'], $data['withdraw_fee']['value'])->info($data['withdraw_fee']['desc']),
  1483. 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, [
  1484. 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'])
  1485. ])->info($data['user_extract_bank_status']['desc']),
  1486. 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),
  1487. 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),
  1488. ]),
  1489. ]);
  1490. return $build->toArray();
  1491. }
  1492. /**
  1493. * 积分设置
  1494. * @return array
  1495. */
  1496. public function integralFormBuild()
  1497. {
  1498. $build = new Build();
  1499. $build->url('setting/config/save_basics');
  1500. $data = $this->getConfigAllField([
  1501. 'integral_ratio_status', 'integral_ratio', 'integral_max_type', 'integral_max_num', 'integral_max_rate', 'order_give_integral', 'integral_effective_status',
  1502. 'integral_effective_time', 'next_clear_month_time', 'next_clear_quarter_time', 'next_clear_year_time'
  1503. ]);
  1504. /** @var UserIntegralServices $userIntergralServices */
  1505. $userIntergralServices = app()->make(UserIntegralServices::class);
  1506. [$next_clear_month_time] = $userIntergralServices->getTime(1);
  1507. [$next_clear_quarter_time] = $userIntergralServices->getTime(2);
  1508. [$next_clear_year_time] = $userIntergralServices->getTime(3);
  1509. $build->rule([
  1510. Build::card('积分设置')->components([
  1511. Build::switch('integral_ratio_status', $data['integral_ratio_status']['info'], (int)$data['integral_ratio_status']['value'])
  1512. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1513. Build::inputNum('integral_ratio', $data['integral_ratio']['info'], $data['integral_ratio']['value'])->info($data['integral_ratio']['desc'])->min(0),
  1514. Build::radio('integral_max_type', $data['integral_max_type']['info'], $data['integral_max_type']['value'])->control(1, [
  1515. Build::inputNum('integral_max_num', $data['integral_max_num']['info'], $data['integral_max_num']['value'])->info($data['integral_max_num']['desc'])->min(0),
  1516. ])->control(2, [
  1517. Build::inputNum('integral_max_rate', $data['integral_max_rate']['info'], $data['integral_max_rate']['value'])->info($data['integral_max_rate']['desc'])->min(0),
  1518. ])->options($this->getOptions($data['integral_max_type']['parameter']))
  1519. ])->info($data['integral_ratio_status']['desc']),
  1520. Build::inputNum('order_give_integral', $data['order_give_integral']['info'], $data['order_give_integral']['value'])->info($data['order_give_integral']['desc'])->min(0),
  1521. Build::radio('integral_effective_status', $data['integral_effective_status']['info'], $data['integral_effective_status']['value'])
  1522. ->info($data['integral_effective_status']['desc'])->control(1, [
  1523. Build::radio('integral_effective_time', $data['integral_effective_time']['info'], $data['integral_effective_time']['value'])
  1524. ->info($data['integral_effective_time']['desc'])->control(1, [
  1525. Build::input('next_clear_month_time', '最近清零时间', $next_clear_month_time ? date('Y-m-d', $next_clear_month_time) : '')->disabled()->info('最近清零时间')
  1526. ])->control(2, [
  1527. Build::input('next_clear_quarter_time', '最近清零时间', $next_clear_quarter_time ? date('Y-m-d', $next_clear_quarter_time) : '')->info('最近清零时间')->disabled()
  1528. ])->control(3, [
  1529. Build::input('next_clear_year_time', '最近清零时间', $next_clear_year_time ? date('Y-m-d', $next_clear_year_time) : '')->info('最近清零时间')->disabled()
  1530. ])->options($this->getOptions($data['integral_effective_time']['parameter']))
  1531. ])->options($this->getOptions($data['integral_effective_status']['parameter'])),
  1532. ]),
  1533. ]);
  1534. return $build->toArray();
  1535. }
  1536. /**
  1537. * 客服配置
  1538. * @return array
  1539. */
  1540. public function kefuFormBuild()
  1541. {
  1542. $build = new Build();
  1543. $build->url('setting/config/save_basics');
  1544. $data = $this->getConfigAllField([
  1545. 'customer_type', 'service_feedback', 'customer_phone', 'customer_url',
  1546. // 'tourist_avatar'
  1547. ]);
  1548. $options = $this->getOptions($data['customer_type']['parameter']);
  1549. $build->rule([
  1550. Build::card('客服设置')->components([
  1551. Build::radio('customer_type', $data['customer_type']['info'], $data['customer_type']['value'])
  1552. ->options($options)->control(0, [
  1553. // 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'),
  1554. Build::input('service_feedback', $data['service_feedback']['info'], $data['service_feedback']['value'])->type('textarea')->rows(5)->info($data['service_feedback']['desc']),
  1555. ])->control(1, [
  1556. Build::input('customer_phone', $data['customer_phone']['info'], $data['customer_phone']['value'])->info($data['customer_phone']['desc'])->validate(StrRules::pattern(StrRules::PHONE_NUMBER)->message('请输入正确的手机号')),
  1557. ])->control(2, [
  1558. Build::input('customer_url', $data['customer_url']['info'], $data['customer_url']['value'])->info($data['customer_url']['desc']),
  1559. ])->info($data['customer_type']['desc']),
  1560. ]),
  1561. ]);
  1562. return $build->toArray();
  1563. }
  1564. /**
  1565. * 等级设置
  1566. * @return array
  1567. */
  1568. public function vipFormBuild()
  1569. {
  1570. $build = new Build();
  1571. $build->url('setting/config/save_basics');
  1572. $data = $this->getConfigAllField([
  1573. 'member_func_status', 'member_price_status', 'order_give_exp', 'sign_give_exp', 'invite_user_exp'
  1574. ]);
  1575. $build->rule([
  1576. Build::card('等级设置')->components([
  1577. Build::switch('member_func_status', $data['member_func_status']['info'], (int)$data['member_func_status']['value'])
  1578. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1579. // Build::switch('member_price_status', $data['member_price_status']['info'], (int)$data['member_price_status']['value'])
  1580. // ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['member_price_status']['desc']),
  1581. Build::inputNum('order_give_exp', $data['order_give_exp']['info'], $data['order_give_exp']['value'])->info($data['order_give_exp']['desc'])->min(0),
  1582. Build::inputNum('sign_give_exp', $data['sign_give_exp']['info'], $data['sign_give_exp']['value'])->info($data['sign_give_exp']['desc'])->min(0),
  1583. Build::inputNum('invite_user_exp', $data['invite_user_exp']['info'], $data['invite_user_exp']['value'])->info($data['invite_user_exp']['desc'])->min(0),
  1584. ])->info($data['member_func_status']['desc']),
  1585. ]),
  1586. ]);
  1587. return $build->toArray();
  1588. }
  1589. /**
  1590. * 发票
  1591. * @return array
  1592. */
  1593. public function invoiceFormBuild()
  1594. {
  1595. $build = new Build();
  1596. $build->url('setting/config/save_basics');
  1597. $data = $this->getConfigAllField([
  1598. 'invoice_func_status', 'special_invoice_status'
  1599. ]);
  1600. $build->rule([
  1601. Build::card('发票设置')->components([
  1602. Build::switch('invoice_func_status', $data['invoice_func_status']['info'], (int)$data['invoice_func_status']['value'])
  1603. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['invoice_func_status']['desc']),
  1604. Build::switch('special_invoice_status', $data['special_invoice_status']['info'], (int)$data['special_invoice_status']['value'])
  1605. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['special_invoice_status']['desc']),
  1606. ]),
  1607. ]);
  1608. return $build->toArray();
  1609. }
  1610. /**
  1611. * 付费会员
  1612. * @return array
  1613. */
  1614. public function svipFormBuild()
  1615. {
  1616. $build = new Build();
  1617. $build->url('setting/config/save_basics');
  1618. $data = $this->getConfigAllField([
  1619. 'member_card_status', 'svip_price_status'
  1620. ]);
  1621. //缺少svip会员价格是否展示字段
  1622. $build->rule([
  1623. Build::card('会员设置')->components([
  1624. Build::switch('member_card_status', $data['member_card_status']['info'], (int)$data['member_card_status']['value'])
  1625. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['member_card_status']['desc'])->control(1, [
  1626. 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'])
  1627. ])
  1628. ]),
  1629. ]);
  1630. return $build->toArray();
  1631. }
  1632. /**
  1633. * 充值设置
  1634. * @return array
  1635. */
  1636. public function rechargeFormBuild()
  1637. {
  1638. $build = new Build();
  1639. $build->url('setting/config/save_basics');
  1640. $data = $this->getConfigAllField([
  1641. 'balance_func_status', 'recharge_attention', 'recharge_switch', 'store_user_min_recharge'
  1642. ]);
  1643. $build->rule([
  1644. Build::card('充值设置')->components([
  1645. Build::switch('balance_func_status', $data['balance_func_status']['info'], (int)$data['balance_func_status']['value'])->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1646. Build::input('recharge_attention', $data['recharge_attention']['info'], $data['recharge_attention']['value'])->rows(5)->type($data['recharge_attention']['type'])->info($data['recharge_attention']['desc']),
  1647. Build::switch('recharge_switch', $data['recharge_switch']['info'], (int)$data['recharge_switch']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['recharge_switch']['desc']),
  1648. 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),
  1649. ])->info($data['balance_func_status']['desc']),
  1650. ]),
  1651. ]);
  1652. return $build->toArray();
  1653. }
  1654. /**
  1655. * 用户设置
  1656. * @return array
  1657. */
  1658. public function userFormBuild()
  1659. {
  1660. $build = new Build();
  1661. $build->url('setting/config/save_basics');
  1662. $data = $this->getConfigAllField([
  1663. 'h5_avatar',
  1664. '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',
  1665. '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',
  1666. 'member_card_status', 'svip_price_status'
  1667. ]);
  1668. $build->rule([
  1669. Build::tabs()->option('基础信息', [
  1670. 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']),
  1671. ])->option('登录注册', [
  1672. Build::alert('多端(公众号、小程序)账号统一,可以开启强制手机号登录实现,也可以绑定微信开放平台实现:https://open.weixin.qq.com', Alert::WARNING)->showIcon(true),
  1673. 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'])
  1674. ])->option('等级会员', [
  1675. Build::switch('member_func_status', $data['member_func_status']['info'], (int)$data['member_func_status']['value'])
  1676. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1677. // Build::switch('member_price_status', $data['member_price_status']['info'], (int)$data['member_price_status']['value'])
  1678. // ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['member_price_status']['desc']),
  1679. Build::inputNum('order_give_exp', $data['order_give_exp']['info'], $data['order_give_exp']['value'])->info($data['order_give_exp']['desc'])->min(0),
  1680. Build::inputNum('sign_give_exp', $data['sign_give_exp']['info'], $data['sign_give_exp']['value'])->info($data['sign_give_exp']['desc'])->min(0),
  1681. Build::inputNum('invite_user_exp', $data['invite_user_exp']['info'], $data['invite_user_exp']['value'])->info($data['invite_user_exp']['desc'])->min(0),
  1682. ])->info($data['member_func_status']['desc']),
  1683. ])->option('付费会员', [
  1684. Build::switch('member_card_status', $data['member_card_status']['info'], (int)$data['member_card_status']['value'])
  1685. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['member_card_status']['desc'])->control(1, [
  1686. 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'])
  1687. ])
  1688. ])
  1689. ]);
  1690. return $build->toArray();
  1691. }
  1692. /**
  1693. * 发货设置
  1694. * @return array
  1695. */
  1696. public function deliverFormBuild()
  1697. {
  1698. $build = new Build();
  1699. $build->url('setting/config/save_basics');
  1700. $data = $this->getConfigAllField([
  1701. 'store_free_postage', 'offline_postage',
  1702. // 'store_self_mention'
  1703. ]);
  1704. $build->rule([
  1705. Build::card('发货设置')->components([
  1706. Build::switch('whole_free_shipping', '全场包邮', (int)$data['store_free_postage']['value'] > 0 ? 1 : 0)
  1707. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1708. Build::inputNum('store_free_postage', $data['store_free_postage']['info'], $data['store_free_postage']['value'])->info($data['store_free_postage']['desc'])->min(0)
  1709. ])->info('开启全场包邮必须设置包邮金额大于0的金额才能开启'),
  1710. Build::switch('offline_postage', '线下支付是否包邮', (int)$data['offline_postage']['value'] > 0 ? 1 : 0)
  1711. ->falseValue('不包邮', 0)->trueValue('包邮', 1)->info($data['offline_postage']['desc'] ?? ''),
  1712. // Build::switch('store_self_mention', '是否开启到店自提', (int)$data['store_self_mention']['value'] > 0 ? 1 : 0)
  1713. // ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['store_self_mention']['desc'] ?? ''),
  1714. ]),
  1715. ]);
  1716. return $build->toArray();
  1717. }
  1718. /**
  1719. * 同城设置
  1720. * @return array
  1721. */
  1722. public function cityDeliverFormBuild()
  1723. {
  1724. $build = new Build();
  1725. $build->url('setting/config/save_basics');
  1726. $data = $this->getConfigAllField([
  1727. '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'
  1728. ]);
  1729. $build->rule([
  1730. Build::card('同城配送')->components([
  1731. Build::switch('city_delivery_status', $data['city_delivery_status']['info'], (int)$data['city_delivery_status']['value'])
  1732. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  1733. Build::switch('self_delivery_status', $data['self_delivery_status']['info'], (int)$data['self_delivery_status']['value'])->info($data['self_delivery_status']['desc']),
  1734. Build::switch('dada_delivery_status', $data['dada_delivery_status']['info'], (int)$data['dada_delivery_status']['value'])->control(1, [
  1735. Build::input('dada_app_key', $data['dada_app_key']['info'], $data['dada_app_key']['value'])->info($data['dada_app_key']['desc']),
  1736. Build::input('dada_app_sercret', $data['dada_app_sercret']['info'], $data['dada_app_sercret']['value'])->info($data['dada_app_sercret']['desc']),
  1737. Build::input('dada_source_id', $data['dada_source_id']['info'], $data['dada_source_id']['value'])->info($data['dada_source_id']['desc']),
  1738. ])->info($data['dada_delivery_status']['desc']),
  1739. Build::switch('uu_delivery_status', $data['uu_delivery_status']['info'], (int)$data['uu_delivery_status']['value'])->control(1, [
  1740. Build::input('uupt_appkey', $data['uupt_appkey']['info'], $data['uupt_appkey']['value'])->info($data['uupt_appkey']['desc']),
  1741. Build::input('uupt_app_id', $data['uupt_app_id']['info'], $data['uupt_app_id']['value'])->info($data['uupt_app_id']['desc']),
  1742. Build::input('uupt_open_id', $data['uupt_open_id']['info'], $data['uupt_open_id']['value'])->info($data['uupt_open_id']['desc']),
  1743. ])->info($data['uu_delivery_status']['desc']),
  1744. ])->info($data['city_delivery_status']['desc'])
  1745. ]),
  1746. ]);
  1747. return $build->toArray();
  1748. }
  1749. /**
  1750. * 第三方配置
  1751. * @return array
  1752. */
  1753. public function thirdPartyFormBuild()
  1754. {
  1755. $build = new Build();
  1756. $build->url('setting/config/save_basics');
  1757. $data = $this->getConfigAllField([
  1758. 'pay_success_printing_switch', 'develop_id', 'printing_api_key', 'printing_client_id', 'terminal_number',
  1759. 'print_type', 'fey_user', 'fey_ukey', 'fey_sn',
  1760. 'system_product_copy_type', 'copy_product_apikey', 'logistics_type',
  1761. 'system_express_app_code', 'config_export_open', 'config_export_siid', 'config_export_to_name', 'config_export_to_tel',
  1762. 'tengxun_map_key', 'system_statistics', 'config_export_to_address', 'verify_expire_time', 'erp_open',
  1763. 'erp_type', 'jst_appkey', 'jst_appsecret', 'jst_default_shopid', 'jst_login_account', 'jst_login_password'
  1764. ]);
  1765. $build->rule([
  1766. Build::tabs()->option('小票打印配置', [
  1767. Build::switch('pay_success_printing_switch', $data['pay_success_printing_switch']['info'], (int)$data['pay_success_printing_switch']['value'])->control(1, [
  1768. Build::radio('print_type', $data['print_type']['info'], $data['print_type']['value'])->control(1, [
  1769. Build::input('develop_id', $data['develop_id']['info'], $data['develop_id']['value'])->info($data['develop_id']['desc']),
  1770. Build::input('printing_api_key', $data['printing_api_key']['info'], $data['printing_api_key']['value'])->info($data['printing_api_key']['desc']),
  1771. Build::input('printing_client_id', $data['printing_client_id']['info'], $data['printing_client_id']['value'])->info($data['printing_client_id']['desc']),
  1772. Build::input('terminal_number', $data['terminal_number']['info'], $data['terminal_number']['value'])->info($data['terminal_number']['desc']),
  1773. ])->control(2, [
  1774. Build::input('fey_user', $data['fey_user']['info'], $data['fey_user']['value'])->info($data['fey_user']['desc']),
  1775. Build::input('fey_ukey', $data['fey_ukey']['info'], $data['fey_ukey']['value'])->info($data['fey_ukey']['desc']),
  1776. Build::input('fey_sn', $data['fey_sn']['info'], $data['fey_sn']['value'])->info($data['fey_sn']['desc'])
  1777. ])->options($this->getOptions($data['print_type']['parameter']))->info($data['print_type']['desc'])
  1778. ])->trueValue('打开', 1)->falseValue('关闭', 0),
  1779. ])->option('采集商品配置', [
  1780. Build::radio('system_product_copy_type', $data['system_product_copy_type']['info'], $data['system_product_copy_type']['value'])->control(2, [
  1781. Build::input('copy_product_apikey', $data['copy_product_apikey']['info'], $data['copy_product_apikey']['value'])->info($data['copy_product_apikey']['desc'])
  1782. ])->options($this->getOptions($data['system_product_copy_type']['parameter']))->info($data['system_product_copy_type']['desc'])
  1783. ])->option('物流查询', [
  1784. Build::radio('logistics_type', $data['logistics_type']['info'], $data['logistics_type']['value'])->control(2, [
  1785. 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'])
  1786. ])->options($this->getOptions($data['logistics_type']['parameter']))->info($data['logistics_type']['desc'])
  1787. ])->option('电子面单', [
  1788. Build::radio('config_export_open', $data['config_export_open']['info'], $data['config_export_open']['value'])->control(1, [
  1789. 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']),
  1790. 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']),
  1791. 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']),
  1792. Build::input('config_export_siid', $data['config_export_siid']['info'], $data['config_export_siid']['value'])->info($data['config_export_siid']['desc']),
  1793. ])->options($this->getOptions($data['config_export_open']['parameter']))->info($data['config_export_open']['desc'])
  1794. ])->option('地图配置', [
  1795. Build::input('tengxun_map_key', $data['tengxun_map_key']['info'], $data['tengxun_map_key']['value'])->info($data['tengxun_map_key']['desc']),
  1796. ])->option('短信', [
  1797. Build::inputNum('verify_expire_time', $data['verify_expire_time']['info'], $data['verify_expire_time']['value'])->info($data['verify_expire_time']['desc'])->min(0),
  1798. ])->option('统计', [
  1799. Build::input('system_statistics', $data['system_statistics']['info'], $data['system_statistics']['value'])->rows(7)->type('textarea')->info($data['system_statistics']['desc']),
  1800. ])->option('ERP配置', [
  1801. Build::switch('erp_open', $data['erp_open']['info'], (int)$data['erp_open']['value'])->control(1, [
  1802. Build::radio('erp_type', $data['erp_type']['info'], $data['erp_type']['value'])->control(1, [
  1803. Build::input('jst_login_account', $data['jst_login_account']['info'], $data['jst_login_account']['value'])->info($data['jst_login_account']['desc']),
  1804. Build::input('jst_login_password', $data['jst_login_password']['info'], $data['jst_login_password']['value'])->info($data['jst_login_password']['desc']),
  1805. Build::input('jst_appkey', $data['jst_appkey']['info'], $data['jst_appkey']['value'])->info($data['jst_appkey']['desc']),
  1806. Build::input('jst_appsecret', $data['jst_appsecret']['info'], $data['jst_appsecret']['value'])->info($data['jst_appsecret']['desc']),
  1807. Build::input('jst_default_shopid', $data['jst_default_shopid']['info'], $data['jst_default_shopid']['value'])->info($data['jst_default_shopid']['desc']),
  1808. ])->options($this->getOptions($data['erp_type']['parameter']))->info($data['erp_type']['desc'])
  1809. ])->trueValue('打开', 1)->falseValue('关闭', 0),
  1810. ]),
  1811. ]);
  1812. return $build->toArray();
  1813. }
  1814. /**
  1815. * 微信开放平台
  1816. * @return array
  1817. */
  1818. public function wxOpenBaseFormBuild()
  1819. {
  1820. $build = new Build();
  1821. $build->url('setting/config/save_basics');
  1822. $data = $this->getConfigAllField([
  1823. 'wechat_open_app_id', 'wechat_open_app_secret'
  1824. ]);
  1825. $build->rule([
  1826. Build::card('微信开放平台')->components([
  1827. Build::alert('小程序、公众号、PC端登录、APP微信登录或企业微信用户同步必须配置微信开放平台,申请微信开放平台地址:https://open.weixin.qq.com', 'warning')->showIcon(true),
  1828. 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']),
  1829. 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']),
  1830. ]),
  1831. ]);
  1832. return $build->toArray();
  1833. }
  1834. /**
  1835. * PC设置
  1836. * @return array
  1837. */
  1838. public function pcBaseFormBuild()
  1839. {
  1840. $build = new Build();
  1841. $build->url('setting/config/save_basics');
  1842. $data = $this->getConfigAllField([
  1843. 'pc_logo', 'bast_number', 'first_number', 'product_phone_buy_url', 'contact_number',
  1844. 'company_address', 'copyright', 'seo_title', 'site_keywords', 'site_description', 'record_No',
  1845. 'wechat_open_app_id', 'wechat_open_app_secret', 'links_open', 'links_list', 'filing_list'
  1846. ]);
  1847. $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');
  1848. foreach (['contact_number', 'company_address', 'copyright', 'seo_title', 'site_keywords', 'site_description', 'record_No'] as $key) {
  1849. $base[] = Build::input($key, $data[$key]['info'], $data[$key]['value'])->info($data[$key]['desc'])->type($data[$key]['type']);
  1850. }
  1851. $open = [];
  1852. foreach (['wechat_open_app_id', 'wechat_open_app_secret'] as $key) {
  1853. $open[] = Build::input($key, $data[$key]['info'], $data[$key]['value'])->info($data[$key]['desc'])->type($data[$key]['type']);
  1854. }
  1855. $build->rule([
  1856. Build::card('基础设置')->components($base),
  1857. Build::card('商品设置')->components([
  1858. Build::inputNum('bast_number', $data['bast_number']['info'], $data['bast_number']['value'])->info($data['bast_number']['desc'])->min(0),
  1859. Build::inputNum('first_number', $data['first_number']['info'], $data['first_number']['value'])->info($data['first_number']['desc'])->min(0),
  1860. 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'])),
  1861. ]),
  1862. Build::card('微信开放平台(pc端用户扫码登录使用)')->components($open),
  1863. Build::card('友情链接')->components([
  1864. Build::switch('links_open', $data['links_open']['info'], (int)$data['links_open']['value'])->info($data['links_open']['desc'])->control(1, [
  1865. Build::diyTable('links_list', $data['links_list']['info'], is_array($data['links_list']['value']) ? $data['links_list']['value'] : [])->info($data['links_list']['desc'])
  1866. ->column('链接名称', 'name')->column('链接地址', 'url')->column('排序', 'sort', InputNumber::NAME, ['editable' => false]),
  1867. ])->trueValue('开启', 1)->falseValue('关闭', 0),
  1868. ]),
  1869. Build::card('底部(公安备案等自定义)')->components([
  1870. Build::diyTable('filing_list', $data['filing_list']['info'], is_array($data['filing_list']['value']) ? $data['filing_list']['value'] : [])->info($data['filing_list']['desc'])
  1871. ->column('图标', 'icon', 'image')->column('名称', 'name')->column('链接地址', 'url')->column('排序', 'sort', InputNumber::NAME, ['editable' => false])
  1872. ]),
  1873. ]);
  1874. return $build->toArray();
  1875. }
  1876. /**
  1877. * PC设置
  1878. * @return array
  1879. */
  1880. public function appBaseFormBuild()
  1881. {
  1882. $build = new Build();
  1883. $build->url('setting/config/save_basics');
  1884. $data = $this->getConfigAllField([
  1885. 'wechat_app_appid', 'wechat_app_appsecret', 'app_version', 'app_apk'
  1886. ]);
  1887. $open = [];
  1888. foreach (['wechat_app_appid', 'wechat_app_appsecret', 'app_version'] as $key) {
  1889. $open[] = Build::input($key, $data[$key]['info'], $data[$key]['value'])->info($data[$key]['desc'])->type($data[$key]['type']);
  1890. }
  1891. $open[] = Build::uploadImage('app_apk', $data['app_apk']['info'], $data['app_apk']['value'])
  1892. ->url('/file/upload/0?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  1893. ->type('file')->icon('md-add')->info($data['app_apk']['desc']);
  1894. $build->rule([
  1895. Build::card('微信开放平台(微信登录、支付都需要开通此配置)')->components($open),
  1896. ]);
  1897. return $build->toArray();
  1898. }
  1899. /**
  1900. * 微信基础配置
  1901. * @return array
  1902. */
  1903. public function wechatBaseFormBuild()
  1904. {
  1905. $build = new Build();
  1906. $build->url('setting/config/save_basics');
  1907. $data = $this->getConfigAllField([
  1908. 'share_qrcode', 'spread_share_forever', 'wechat_qrcode', 'wechat_appid',
  1909. 'wechat_appsecret', 'wechat_encodingaeskey', 'wechat_token', 'api', 'wechat_encode',
  1910. // 'wechat_share_img', 'wechat_share_title', 'wechat_share_synopsis',
  1911. 'create_wechat_user'
  1912. ]);
  1913. $build->rule([
  1914. Build::card('公众号开发者信息')->components([
  1915. Build::input('wechat_appid', $data['wechat_appid']['info'], $data['wechat_appid']['value'])->info($data['wechat_appid']['desc']),
  1916. Build::input('wechat_appsecret', $data['wechat_appsecret']['info'], $data['wechat_appsecret']['value'])->info($data['wechat_appsecret']['desc']),
  1917. ]),
  1918. Build::card('服务器配置')->components([
  1919. Build::input('wechat_encodingaeskey', $data['wechat_encodingaeskey']['info'], $data['wechat_encodingaeskey']['value'])->info($data['wechat_encodingaeskey']['desc'])->randAESK(),
  1920. Build::input('wechat_token', $data['wechat_token']['info'], $data['wechat_token']['value'])->info($data['wechat_token']['desc'])->randToken(),
  1921. Build::input('api', $data['api']['info'], sys_config('site_url') . '/api/wechat/serve')->info($data['api']['desc'])->disabled()->copy(),
  1922. 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'])),
  1923. ]),
  1924. Build::card('微信公众号')->components([
  1925. Build::radio('share_qrcode', $data['share_qrcode']['info'], $data['share_qrcode']['value'])->info($data['share_qrcode']['desc'])->options($this->getOptions($data['share_qrcode']['parameter'])),
  1926. 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'])),
  1927. 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'),
  1928. 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']),
  1929. ]),
  1930. // Build::card('首页分享')->components([
  1931. // 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'),
  1932. // Build::input('wechat_share_title', $data['wechat_share_title']['info'], $data['wechat_share_title']['value'])->info($data['wechat_share_title']['desc']),
  1933. // Build::input('wechat_share_synopsis', $data['wechat_share_synopsis']['info'], $data['wechat_share_synopsis']['value'])->type('textarea')->info($data['wechat_share_synopsis']['desc']),
  1934. // ])
  1935. ]);
  1936. return $build->toArray();
  1937. }
  1938. /**
  1939. * 小程序基础配置
  1940. * @return array
  1941. */
  1942. public function routineBaseFormBuild()
  1943. {
  1944. $data = $this->getConfigAllField([
  1945. 'routine_appId', 'routine_appsecret', 'routine_contact_type', 'routine_name', 'store_user_avatar', 'order_shipping_open', 'routine_auth_type', 'store_user_agreement'
  1946. ]);
  1947. return $data;
  1948. }
  1949. /**
  1950. * 支付
  1951. * @return array
  1952. */
  1953. public function shopPayFormBuild()
  1954. {
  1955. $build = new Build();
  1956. $build->url('setting/config/save_basics');
  1957. $data = $this->getConfigAllField([
  1958. 'pay_weixin_open', 'pay_weixin_mchid', 'pay_weixin_key', 'paydir', 'yue_pay_status', 'is_cashier_yue_pay_verify', 'offline_pay_status',
  1959. 'offline_pay_status', 'ali_pay_status', 'ali_pay_appid', 'alipay_public_key', 'alipay_merchant_private_key',
  1960. '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'
  1961. ]);
  1962. $site_url = sys_config('site_url', '');
  1963. $build->rule([
  1964. Build::tabs()->option('微信支付', [
  1965. Build::alert('登录微信商户(地址:https://pay.weixin.qq.com,支付授权目录、回调链接:' . $site_url . '; http,https最好都配置),帮助文档地址:https://doc.crmeb.com/web/pro/crmebprov2/1203', Alert::WARNING)->showIcon(true),
  1966. Build::switch('pay_weixin_open', $data['pay_weixin_open']['info'], (int)$data['pay_weixin_open']['value'])->control(1, [
  1967. Build::input('pay_weixin_mchid', $data['pay_weixin_mchid']['info'], $data['pay_weixin_mchid']['value'])->info($data['pay_weixin_mchid']['desc']),
  1968. Build::radio('pay_wechat_type', $data['pay_wechat_type']['info'], (int)$data['pay_wechat_type']['value'])->control(1, [
  1969. 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']),
  1970. 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']),
  1971. ])->control(0, [
  1972. Build::input('pay_weixin_key', $data['pay_weixin_key']['info'], $data['pay_weixin_key']['value'])->info($data['pay_weixin_key']['desc']),
  1973. ])->options($this->getOptions($data['pay_wechat_type']['parameter']))->info($data['pay_wechat_type']['desc']),
  1974. Build::uploadImage('pay_weixin_client_cert', $data['pay_weixin_client_cert']['info'], $data['pay_weixin_client_cert']['value'])
  1975. ->url('/file/upload/1?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  1976. ->type('file')->icon('md-add')->info($data['pay_weixin_client_cert']['desc']),
  1977. Build::uploadImage('pay_weixin_client_key', $data['pay_weixin_client_key']['info'], $data['pay_weixin_client_key']['value'])
  1978. ->url('/file/upload/1?type=1')->format(config('upload.fileExt'))->headers(['Authori-zation' => app()->request->header('Authori-zation')])
  1979. ->type('file')->icon('md-add')->info($data['pay_weixin_client_key']['desc']),
  1980. Build::switch('pay_routine_open', $data['pay_routine_open']['info'], (int)$data['pay_routine_open']['value'])->control(1, [
  1981. Build::input('pay_routine_mchid', $data['pay_routine_mchid']['info'], $data['pay_routine_mchid']['value'])->info($data['pay_routine_mchid']['desc'])
  1982. ])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['pay_routine_open']['desc'])
  1983. ])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['pay_weixin_open']['desc']),
  1984. ])->option('余额支付', [
  1985. 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']),
  1986. 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'])
  1987. ])->option('线下支付', [
  1988. 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'])
  1989. ])->option('支付宝支付', [
  1990. Build::alert('登录支付宝商家(地址:https://b.alipay.com,需要配置ip白名单以及回调地址回调地址:' . $site_url . '),帮助文档地址:https://doc.crmeb.com/web/pro/crmebprov2/1204', Alert::WARNING)->showIcon(true),
  1991. Build::switch('ali_pay_status', $data['ali_pay_status']['info'], (int)$data['ali_pay_status']['value'])->control(1, [
  1992. Build::input('ali_pay_appid', $data['ali_pay_appid']['info'], $data['ali_pay_appid']['value'])->info($data['ali_pay_appid']['desc']),
  1993. 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']),
  1994. 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']),
  1995. ])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['ali_pay_status']['desc']),
  1996. ]),
  1997. ]);
  1998. return $build->toArray();
  1999. }
  2000. /**
  2001. * 砍价设置
  2002. * @return array
  2003. */
  2004. public function bargainFormBuild()
  2005. {
  2006. $build = new Build();
  2007. $build->url('setting/config/save_basics');
  2008. $data = $this->getConfigAllField([
  2009. 'bargain_subscribe'
  2010. ]);
  2011. $build->rule([
  2012. Build::card('砍价设置')->components([
  2013. Build::switch('bargain_subscribe', $data['bargain_subscribe']['info'], (int)$data['bargain_subscribe']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['bargain_subscribe']['desc']),
  2014. ]),
  2015. ]);
  2016. return $build->toArray();
  2017. }
  2018. /**
  2019. * 交易设置
  2020. * @return array
  2021. */
  2022. public function shopTradeFormBuild()
  2023. {
  2024. $build = new Build();
  2025. $build->url('setting/config/save_basics');
  2026. $data = $this->getConfigAllField([
  2027. 'store_stock', 'order_cancel_time', 'order_activity_time',
  2028. 'order_bargain_time', 'order_seckill_time', 'order_pink_time',
  2029. 'system_delivery_time', 'refund_name', 'refund_phone', 'refund_address', 'stor_reason', 'collate_not_operating_time', 'reminder_deadline_second_card_time',
  2030. 'bargain_subscribe', 'system_comment_time', 'rebate_points_orders_time', 'table_code_not_operating_time',
  2031. 'max_price', 'min_price', 'order_time'
  2032. // 'store_cashier_order_rate', 'store_recharge_order_rate', 'store_self_order_rate', 'store_svip_order_rate', 'store_writeoff_order_rate'
  2033. ]);
  2034. $timeData[] = Build::alert('营销活动未支付时间如果设置为0将使用默认活动取消时间,优先使用单独活动配置', Alert::WARNING)->showIcon(true);
  2035. foreach (['order_cancel_time', 'order_activity_time',
  2036. '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) {
  2037. $timeData[] = Build::inputNum($item, $data[$item]['info'], $data[$item]['value'])->info($data[$item]['desc'])->min(0);
  2038. }
  2039. $refund[] = Build::alert('售后处理默认退货地址(门店订单退货默认门店地址)', Alert::WARNING)->showIcon(true);
  2040. foreach (['refund_name', 'refund_phone', 'refund_address', 'stor_reason'] as $key) {
  2041. $rule = Build::input($key, $data[$key]['info'], $data[$key]['value'])->rows(5)->type($data[$key]['type'])->info($data[$key]['desc']);
  2042. if ('refund_phone' === $key) {
  2043. $rule->validate(StrRules::pattern(StrRules::PHONE_NUMBER)->message('请输入正确的手机号码'));
  2044. }
  2045. $refund[] = $rule;
  2046. }
  2047. // $store[] = Build::alert('需要和门店对账,请仔细配置(配置立即生效,不影响已成交订单)', Alert::WARNING)->showIcon(true);
  2048. // foreach (['store_cashier_order_rate', 'store_recharge_order_rate', 'store_self_order_rate', 'store_svip_order_rate', 'store_writeoff_order_rate'] as $key) {
  2049. // $store[] = Build::inputNum($key, $data[$key]['info'], $data[$key]['value'])->min(0)->info($data[$key]['desc']);
  2050. // }
  2051. $build->rule([
  2052. Build::card('库存警戒')->components([
  2053. Build::inputNum('store_stock', $data['store_stock']['info'], $data['store_stock']['value'])->info($data['store_stock']['desc'])->min(0),
  2054. ]),
  2055. Build::card('订单取消时间')->components($timeData),
  2056. Build::card('自动收货时间')->components([
  2057. Build::alert('输入0为不设置自动收货', Alert::WARNING)->showIcon(true),
  2058. Build::inputNum('system_delivery_time', $data['system_delivery_time']['info'], $data['system_delivery_time']['value'])->info($data['system_delivery_time']['desc'])->min(0),
  2059. ]),
  2060. Build::card('下单设置')->components([
  2061. Build::inputNum('order_time', $data['order_time']['info'], $data['order_time']['value'])->info($data['order_time']['desc'])->min(0),
  2062. Build::inputNum('min_price', $data['min_price']['info'], $data['min_price']['value'])->info($data['min_price']['desc'])->min(0),
  2063. Build::inputNum('max_price', $data['max_price']['info'], $data['max_price']['value'])->info($data['max_price']['desc'])->min(0),
  2064. ]),
  2065. Build::card('自动默认好评时间')->components([
  2066. Build::alert('输入0为不设置自动默认好评', Alert::WARNING)->showIcon(true),
  2067. Build::inputNum('system_comment_time', $data['system_comment_time']['info'], $data['system_comment_time']['value'])->info($data['system_comment_time']['desc'])->min(0),
  2068. ]),
  2069. Build::card('售后退款设置')->components($refund),
  2070. // Build::card('门店手续费设置')->components($store),
  2071. ]);
  2072. return $build->toArray();
  2073. }
  2074. /**
  2075. * 商城首页
  2076. * @return array
  2077. */
  2078. public function shopBaseFormBuild()
  2079. {
  2080. $build = new Build();
  2081. $build->url('setting/config/save_basics');
  2082. $data = $this->getConfigAllField([
  2083. 'station_open', 'site_name', 'site_url', 'wap_login_logo', 'site_phone',
  2084. 'admin_login_slide', 'site_logo', 'site_logo_square', 'login_logo',
  2085. 'navigation_open', 'cache_config', 'start_login_logo',
  2086. // 'store_func_status',
  2087. 'video_func_status', 'product_video_status',
  2088. // 'h5_avatar', 'store_user_mobile'
  2089. 'wechat_share_img', 'wechat_share_title', 'wechat_share_synopsis', 'product_poster_title',
  2090. 'hidden_integral'
  2091. ]);
  2092. $system = [];
  2093. foreach (['site_name', 'site_url', 'site_phone', 'cache_config'] as $key) {
  2094. $system[] = Build::input($key, $data[$key]['info'], $data[$key]['value'])->maxlength($key === 'site_name' ? 20 : null)->info($data[$key]['desc'])->type($data[$key]['type']);
  2095. }
  2096. $setting = [];
  2097. foreach (['site_logo', 'site_logo_square', 'login_logo', 'admin_login_slide', 'start_login_logo'] as $key) {
  2098. $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);
  2099. }
  2100. $build->rule([
  2101. Build::tabs()->option('系统信息', [
  2102. 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']),
  2103. Build::switch('hidden_integral', $data['hidden_integral']['info'], (int)$data['hidden_integral']['value'])->trueValue('显示', 1)->falseValue('隐藏', 0)->info($data['hidden_integral']['desc']),
  2104. ])->option('后台设置', $setting)
  2105. ->option('移动端设置', [
  2106. 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']),
  2107. // 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']),
  2108. // 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']),
  2109. Build::switch('navigation_open', $data['navigation_open']['info'], (int)$data['navigation_open']['value'])->trueValue('开启', 1)->falseValue('关闭', 0)->info($data['navigation_open']['desc']),
  2110. // 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']),
  2111. 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']),
  2112. 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']),
  2113. ])
  2114. ->option('分享设置', [
  2115. 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'),
  2116. Build::input('wechat_share_title', $data['wechat_share_title']['info'], $data['wechat_share_title']['value'])->info($data['wechat_share_title']['desc']),
  2117. Build::input('wechat_share_synopsis', $data['wechat_share_synopsis']['info'], $data['wechat_share_synopsis']['value'])->type('textarea')->info($data['wechat_share_synopsis']['desc']),
  2118. Build::input('product_poster_title', $data['product_poster_title']['info'], $data['product_poster_title']['value'])->maxlength(25)->info($data['product_poster_title']['desc']),
  2119. ]),
  2120. // ->option('APP微信开放平台', [
  2121. // Build::alert('小程序、公众号、PC端登录、APP微信登录或企业微信用户同步必须配置微信开放平台,申请微信开放平台地址:https://open.weixin.qq.com', 'warning')->showIcon(true),
  2122. // Build::input('wechat_app_appid', $data['wechat_app_appid']['info'], $data['wechat_app_appid']['value'])->info($data['wechat_app_appid']['desc']),
  2123. // Build::input('wechat_app_appsecret', $data['wechat_app_appsecret']['info'], $data['wechat_app_appsecret']['value'])->info($data['wechat_app_appsecret']['desc']),
  2124. // ]),
  2125. ]);
  2126. return $build->toArray();
  2127. }
  2128. /**
  2129. * 门店设置
  2130. * @return array
  2131. */
  2132. public function storeFormBuild()
  2133. {
  2134. $build = new Build();
  2135. $build->url('setting/config/save_basics');
  2136. $data = $this->getConfigAllField([
  2137. 'store_func_status', 'store_delivery_scope', 'store_splicing_switch', 'store_self_mention'
  2138. ]);
  2139. $build->rule([
  2140. Build::card('门店设置')->components([
  2141. Build::switch('store_func_status', $data['store_func_status']['info'], (int)$data['store_func_status']['value'])
  2142. ->falseValue('关闭', 0)->trueValue('开启', 1)->control(1, [
  2143. Build::switch('store_self_mention', $data['store_self_mention']['info'], (int)$data['store_self_mention']['value'] > 0 ? 1 : 0)
  2144. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['store_self_mention']['desc'] ?? ''),
  2145. Build::switch('store_delivery_scope', $data['store_delivery_scope']['info'], (int)$data['store_delivery_scope']['value'])
  2146. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['store_delivery_scope']['desc']),
  2147. Build::switch('store_splicing_switch', $data['store_splicing_switch']['info'], (int)$data['store_splicing_switch']['value'])
  2148. ->falseValue('关闭', 0)->trueValue('开启', 1)->info($data['store_splicing_switch']['desc']),
  2149. ])->info($data['store_func_status']['desc']),
  2150. ]),
  2151. ]);
  2152. return $build->toArray();
  2153. }
  2154. /**
  2155. * 企业微信配置
  2156. * @return array
  2157. */
  2158. public function workFormBuild()
  2159. {
  2160. $build = new Build();
  2161. $build->url('setting/config/save_basics');
  2162. $data = $this->getConfigAllField([
  2163. 'wechat_work_corpid', 'wechat_work_address_secret', 'wechat_work_token', 'wechat_work_aes_key',
  2164. 'wechat_work_user_secret', 'wechat_work_build_agent_id', 'wechat_work_build_secret',
  2165. ]);
  2166. $build->rule([
  2167. Build::card('企业微信基础配置')->components([
  2168. Build::input('wechat_work_corpid', $data['wechat_work_corpid']['info'], $data['wechat_work_corpid']['value'])->info($data['wechat_work_corpid']['desc']),
  2169. ]),
  2170. Build::card('企业微信通讯录配置')->components([
  2171. Build::alert('1.请先登录企业微信:https://work.weixin.qq.com 客户与上下游->客户联系->关联微信开发者ID。2.请必须绑定微信开放平台', Alert::WARNING)->closable(true),
  2172. 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']),
  2173. Build::input('wechat_work_token', $data['wechat_work_token']['info'], $data['wechat_work_token']['value'])->randToken()->copy()->info($data['wechat_work_token']['desc']),
  2174. 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']),
  2175. Build::input('work_address_url', '服务器地址', sys_config('site_url') . '/api/work/serve')->disabled()->copy(),
  2176. ]),
  2177. Build::card('企业微信客户设置')->components([
  2178. 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']),
  2179. ]),
  2180. Build::card('企业微信自建应用设置')->components([
  2181. 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']),
  2182. 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']),
  2183. ]),
  2184. ]);
  2185. return $build->toArray();
  2186. }
  2187. /**
  2188. * 门店财务设置
  2189. * @return array
  2190. */
  2191. public function financeFormBuild()
  2192. {
  2193. $build = new Build();
  2194. $build->url('setting/config/save_basics');
  2195. $data = $this->getConfigAllField([
  2196. 'store_cashier_order_rate', 'store_self_order_rate', 'store_writeoff_order_rate', 'store_recharge_order_rate',
  2197. 'store_svip_order_rate', 'store_extract_min_price', 'store_extract_max_price',
  2198. ]);
  2199. $build->rule([
  2200. Build::tabs()->option('手续费', [
  2201. Build::inputNum('store_cashier_order_rate', $data['store_cashier_order_rate']['info'], $data['store_cashier_order_rate']['value'])
  2202. ->info($data['store_cashier_order_rate']['desc'])->min(0),
  2203. Build::inputNum('store_self_order_rate', $data['store_self_order_rate']['info'], $data['store_self_order_rate']['value'])
  2204. ->info($data['store_self_order_rate']['desc'])->min(0),
  2205. Build::inputNum('store_writeoff_order_rate', $data['store_writeoff_order_rate']['info'], $data['store_writeoff_order_rate']['value'])
  2206. ->info($data['store_writeoff_order_rate']['desc'])->min(0),
  2207. Build::inputNum('store_recharge_order_rate', $data['store_recharge_order_rate']['info'], $data['store_recharge_order_rate']['value'])
  2208. ->info($data['store_recharge_order_rate']['desc'])->min(0),
  2209. Build::inputNum('store_svip_order_rate', $data['store_svip_order_rate']['info'], $data['store_svip_order_rate']['value'])
  2210. ->info($data['store_svip_order_rate']['desc'])->min(0),
  2211. ])->option('提现设置', [
  2212. Build::inputNum('store_extract_min_price', $data['store_extract_min_price']['info'], $data['store_extract_min_price']['value'])
  2213. ->info($data['store_extract_min_price']['desc'])->min(0),
  2214. Build::inputNum('store_extract_max_price', $data['store_extract_max_price']['info'], $data['store_extract_max_price']['value'])
  2215. ->info($data['store_extract_max_price']['desc'])->min(0),
  2216. ])
  2217. ]);
  2218. return $build->toArray();
  2219. }
  2220. /**
  2221. * 供应商财务设置
  2222. * @return array
  2223. */
  2224. public function supplierFinanceFormBuild()
  2225. {
  2226. $build = new Build();
  2227. $build->url('setting/config/save_basics');
  2228. $data = $this->getConfigAllField(['supplier_extract_min_price', 'supplier_extract_max_price']);
  2229. $build->rule([
  2230. Build::tabs()->option('财务设置', [
  2231. Build::inputNum('supplier_extract_min_price', $data['supplier_extract_min_price']['info'], $data['supplier_extract_min_price']['value'])
  2232. ->info($data['supplier_extract_min_price']['desc'])->min(0),
  2233. Build::inputNum('supplier_extract_max_price', $data['supplier_extract_max_price']['info'], $data['supplier_extract_max_price']['value'])
  2234. ->info($data['supplier_extract_max_price']['desc'])->min(0),
  2235. ])
  2236. ]);
  2237. return $build->toArray();
  2238. }
  2239. /**
  2240. * 获取缩略图配置
  2241. * @return array
  2242. */
  2243. public function getImageConfig()
  2244. {
  2245. return $this->getConfigAllField([
  2246. 'image_watermark_status', 'thumb_big_width', 'thumb_big_height', 'thumb_mid_width',
  2247. 'thumb_mid_height', 'thumb_small_width', 'thumb_small_height', 'watermark_type',
  2248. 'watermark_text', 'watermark_text_angle', 'watermark_text_color', 'watermark_text_size',
  2249. 'watermark_position', 'watermark_image', 'watermark_opacity', 'watermark_rotate',
  2250. 'watermark_x', 'watermark_y', 'upload_type'
  2251. ]);
  2252. }
  2253. /**
  2254. * 获取配置
  2255. * @param string $key
  2256. * @param null $default
  2257. * @return mixed
  2258. */
  2259. public function getConfig(string $key, $default = null)
  2260. {
  2261. return sys_config($key, $default);
  2262. }
  2263. /**
  2264. * 获取用户基础配置
  2265. * @param string $type
  2266. * @return mixed
  2267. */
  2268. public function getUserConfig(string $type = 'basic')
  2269. {
  2270. switch ($type) {
  2271. case 'basic'://基础
  2272. $data = $this->getConfigAllField(['h5_avatar', 'user_extend_info'], 0, 1);
  2273. if (!$data['user_extend_info']) {//没保存过,获取默认数据
  2274. /** @var UserServices $userServices */
  2275. $userServices = app()->make(UserServices::class);
  2276. $data['user_extend_info'] = $userServices->defaultExtendInfo;
  2277. }
  2278. break;
  2279. case 'register'://注册
  2280. $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);
  2281. /** @var StoreNewcomerServices $newcomerServices */
  2282. $newcomerServices = app()->make(StoreNewcomerServices::class);
  2283. $data['product'] = $newcomerServices->getCustomerProduct();
  2284. /** @var CacheServices $cache */
  2285. $cache = app()->make(CacheServices::class);
  2286. $data['newcomer_agreement'] = $cache->getDbCache('newcomer_agreement', '');
  2287. $ids = $data['register_give_coupon'] ?? [];
  2288. $data['register_give_coupon'] = [];
  2289. if ($data['register_coupon_status'] && $ids) {
  2290. /** @var StoreCouponIssueServices $couponServices */
  2291. $couponServices = app()->make(StoreCouponIssueServices::class);
  2292. $coupon = $couponServices->getList(['id' => $ids]);
  2293. $data['register_give_coupon'] = $coupon;
  2294. }
  2295. $data['register_notice'] = '多端(公众号、小程序)账号统一,可以开启强制手机号登录实现,也可以绑定微信开放平台实现:https://open.weixin.qq.com';
  2296. break;
  2297. case 'level'://等级
  2298. $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);
  2299. $ids = $data['level_give_coupon'] ?? [];
  2300. $data['level_give_coupon'] = [];
  2301. if ($data['level_coupon_status'] && $ids) {
  2302. /** @var StoreCouponIssueServices $couponServices */
  2303. $couponServices = app()->make(StoreCouponIssueServices::class);
  2304. $coupon = $couponServices->getList(['id' => $ids]);
  2305. $data['level_give_coupon'] = $coupon;
  2306. }
  2307. break;
  2308. case 'svip'://付费会员
  2309. $data = $this->getConfigAllField(['member_card_status', 'svip_price_status'], 0, 1);
  2310. break;
  2311. default:
  2312. throw new AdminException('类型错误');
  2313. break;
  2314. }
  2315. return $data;
  2316. }
  2317. /**
  2318. * 保存用户设置
  2319. * @param string $type
  2320. * @param array $data
  2321. * @return bool
  2322. */
  2323. public function saveUserConfig(string $type, array $data)
  2324. {
  2325. switch ($type) {
  2326. case 'basic'://基础
  2327. break;
  2328. case 'register'://注册
  2329. $products = $data['product'] ?? [];
  2330. //新人专享商品
  2331. /** @var StoreNewcomerServices $newcomerServices */
  2332. $newcomerServices = app()->make(StoreNewcomerServices::class);
  2333. $newcomerServices->saveNewcomer($products);
  2334. //新人专享规则说明
  2335. /** @var CacheServices $cache */
  2336. $cache = app()->make(CacheServices::class);
  2337. $content = $data['newcomer_agreement'] ?? '';
  2338. $cache->setDbCache('newcomer_agreement', $content);
  2339. unset($data['product'], $data['newcomer_agreement']);
  2340. break;
  2341. case 'level'://等级
  2342. break;
  2343. case 'svip'://付费会员
  2344. break;
  2345. }
  2346. foreach ($data as $k => $v) {
  2347. $config_one = $this->dao->getOne(['menu_name' => $k]);
  2348. if ($config_one) {
  2349. $config_one['value'] = $v;
  2350. $this->valiDateValue($config_one);
  2351. $this->dao->update($k, ['value' => json_encode($v)], 'menu_name');
  2352. }
  2353. }
  2354. \crmeb\services\SystemConfigService::clear();
  2355. return true;
  2356. }
  2357. }