Setting.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. namespace app\common\model\settings;
  3. use app\common\enum\settings\SettingEnum;
  4. use think\facade\Cache;
  5. use app\common\enum\settings\DeliveryTypeEnum;
  6. use app\common\model\BaseModel;
  7. use app\common\enum\settings\OperateTypeEnum;
  8. use think\Model;
  9. /**
  10. * 系统设置模型
  11. */
  12. class Setting extends BaseModel
  13. {
  14. protected $name = 'setting';
  15. protected $createTime = false;
  16. /**
  17. * 获取器: 转义数组格式
  18. */
  19. public function getValuesAttr($value)
  20. {
  21. return json_decode($value, true);
  22. }
  23. /**
  24. * 修改器: 转义成json格式
  25. */
  26. public function setValuesAttr($value)
  27. {
  28. return json_encode($value);
  29. }
  30. /**
  31. * 获取指定项设置
  32. */
  33. public static function getItem($key, $app_id = null)
  34. {
  35. $data = self::getAll($app_id);
  36. $data_key = $data[$key];
  37. if (isset($data_key)) {
  38. $data_key = $data[$key]['values'];
  39. jsonRecursive($data_key);
  40. } else {
  41. $data_key = [];
  42. }
  43. return $data_key;
  44. }
  45. /**
  46. * 获取系统配置
  47. */
  48. public static function getSysConfig()
  49. {
  50. $model = new static;
  51. $result = $model->withoutGlobalScope()->where('key', '=', SettingEnum::SYS_CONFIG)->value('values');
  52. if (!$result) {
  53. $result = $model->defaultData()[SettingEnum::SYS_CONFIG]['values'];
  54. } else {
  55. $result = json_decode($result, true);
  56. }
  57. return $result;
  58. }
  59. /**
  60. * 获取指定项设置
  61. */
  62. public static function getSupplierItem($key, $shop_supplier_id, $app_id = null)
  63. {
  64. $data = self::getAll($app_id, $shop_supplier_id);
  65. $data_key = $data[$key];
  66. if (isset($data_key)) {
  67. $data_key = $data[$key]['values'];
  68. jsonRecursive($data_key);
  69. } else {
  70. $data_key = [];
  71. }
  72. return $data_key;
  73. }
  74. /**
  75. * 获取设置项信息
  76. */
  77. public static function detail($key, $shop_supplier_id = 0)
  78. {
  79. $where = [];
  80. if ($shop_supplier_id) {
  81. $where['shop_supplier_id'] = $shop_supplier_id;
  82. }
  83. return (new static())->where('key', '=', $key)->where($where)->find();
  84. }
  85. /**
  86. * 全局缓存: 系统设置
  87. */
  88. public static function getAll($app_id = null, $shop_supplier_id = 0)
  89. {
  90. $static = new static;
  91. is_null($app_id) && $app_id = $static::$app_id;
  92. if (!$data = Cache::get('setting_' . $app_id . '_' . $shop_supplier_id)) {
  93. $setting = $static->where(compact('app_id'))->where('shop_supplier_id', $shop_supplier_id)->select();
  94. $data = empty($setting) ? [] : array_column($static->collection($setting)->toArray(), null, 'key');
  95. Cache::tag('cache')->set('setting_' . $app_id . '_' . $shop_supplier_id, $data);
  96. }
  97. return $static->getMergeData($data);
  98. }
  99. /**
  100. * 数组转换为数据集对象
  101. */
  102. public function collection($resultSet)
  103. {
  104. $item = current($resultSet);
  105. if ($item instanceof Model) {
  106. return \think\model\Collection::make($resultSet);
  107. } else {
  108. return \think\Collection::make($resultSet);
  109. }
  110. }
  111. /**
  112. * 合并用户设置与默认数据
  113. */
  114. private function getMergeData($userData)
  115. {
  116. $defaultData = $this->defaultData();
  117. // 商城设置:配送方式
  118. if (isset($userData['store']['values']['delivery_type'])) {
  119. unset($defaultData['store']['values']['delivery_type']);
  120. }
  121. return array_merge_multiple($defaultData, $userData);
  122. }
  123. /**
  124. * 店铺是否开启
  125. */
  126. public static function getStoreOpen()
  127. {
  128. $data = (new static())->getItem(SettingEnum::BOTTOMNAV);
  129. return $data['menu_type'] == 1;
  130. }
  131. /**
  132. * 默认配置
  133. */
  134. public function defaultData($storeName = null)
  135. {
  136. $url = base_url();
  137. return [
  138. 'store' => [
  139. 'key' => 'store',
  140. 'describe' => '商城设置',
  141. 'values' => [
  142. // 商城名称
  143. 'name' => $storeName ?: '玖玖珈商城',
  144. // 配送方式
  145. 'delivery_type' => array_keys(DeliveryTypeEnum::data()),
  146. // 快递100
  147. 'kuaidi100' => [
  148. 'customer' => '',
  149. 'key' => '',
  150. ],
  151. // 押金
  152. 'supplier_cash' => '0',
  153. // 抽成比例
  154. 'commission_rate' => '5',
  155. // 模式类型,B2B B2B2C
  156. 'operate_type' => OperateTypeEnum::B2B,
  157. // 新商品是否需要审核
  158. 'add_audit' => '1',
  159. // 审核通过后再修改是否需要审核
  160. 'edit_audit' => '1',
  161. // 供应商入驻图片
  162. 'supplier_image' => 'http://wx-cdn.jiujiuyunhui.com/202011091623282f83a8213.png',
  163. // 是否开启短信
  164. 'sms_open' => '1',
  165. // 是否记录日志
  166. 'is_get_log' => true
  167. ],
  168. ],
  169. 'mp_service' => [
  170. 'key' => 'mp_service',
  171. 'describe' => '公众号客服设置',
  172. 'values' => [
  173. // qq
  174. 'qq' => '',
  175. // 微信
  176. 'wechat' => '',
  177. // 微信公众号图片
  178. 'mp_image' => '',
  179. ],
  180. ],
  181. 'trade' => [
  182. 'key' => 'trade',
  183. 'describe' => '交易设置',
  184. 'values' => [
  185. 'order' => [
  186. 'close_days' => '3',
  187. 'receive_days' => '10',
  188. 'refund_days' => '7'
  189. ],
  190. 'freight_rule' => '10',
  191. ]
  192. ],
  193. 'storage' => [
  194. 'key' => 'storage',
  195. 'describe' => '上传设置',
  196. 'values' => [
  197. 'default' => 'local',
  198. 'engine' => [
  199. 'local' => [],
  200. 'qiniu' => [
  201. 'bucket' => '',
  202. 'access_key' => '',
  203. 'secret_key' => '',
  204. 'domain' => 'http://'
  205. ],
  206. 'aliyun' => [
  207. 'bucket' => '',
  208. 'access_key_id' => '',
  209. 'access_key_secret' => '',
  210. 'domain' => 'http://'
  211. ],
  212. 'qcloud' => [
  213. 'bucket' => '',
  214. 'region' => '',
  215. 'secret_id' => '',
  216. 'secret_key' => '',
  217. 'domain' => 'http://'
  218. ],
  219. ]
  220. ],
  221. ],
  222. 'sms' => [
  223. 'key' => 'sms',
  224. 'describe' => '短信通知',
  225. 'values' => [
  226. 'default' => 'aliyun',
  227. 'engine' => [
  228. 'aliyun' => [
  229. 'AccessKeyId' => '',
  230. 'AccessKeySecret' => '',
  231. 'sign' => '小程序商城',
  232. 'login_template' => '',
  233. 'apply_template' => '',
  234. 'supplier_reject_code' => '',
  235. 'supplier_pass_code' => ''
  236. ],
  237. ],
  238. ],
  239. ],
  240. 'tplMsg' => [
  241. 'key' => 'tplMsg',
  242. 'describe' => '模板消息',
  243. 'values' => [
  244. 'payment' => [
  245. 'is_enable' => '0',
  246. 'template_id' => '',
  247. ],
  248. 'delivery' => [
  249. 'is_enable' => '0',
  250. 'template_id' => '',
  251. ],
  252. 'refund' => [
  253. 'is_enable' => '0',
  254. 'template_id' => '',
  255. ],
  256. ],
  257. ],
  258. 'printer' => [
  259. 'key' => 'printer',
  260. 'describe' => '小票打印机设置',
  261. 'values' => [
  262. 'is_open' => '0', // 是否开启打印
  263. 'printer_id' => '', // 打印机id
  264. 'order_status' => [], // 订单类型 10下单打印 20付款打印 30确认收货打印
  265. ],
  266. ],
  267. 'full_free' => [
  268. 'key' => 'full_free',
  269. 'describe' => '满额包邮设置',
  270. 'values' => [
  271. 'is_open' => '0', // 是否开启满额包邮
  272. 'money' => '', // 单笔订单额度
  273. ],
  274. ],
  275. 'recharge' => [
  276. 'key' => 'recharge',
  277. 'describe' => '用户充值设置',
  278. 'values' => [
  279. 'is_entrance' => '1', // 是否允许用户充值
  280. 'is_custom' => '1', // 是否允许自定义金额
  281. 'is_match_plan' => '1', // 自定义金额是否自动匹配合适的套餐
  282. 'describe' => "1. 账户充值仅限微信在线方式支付,充值金额实时到账;\n" .
  283. "2. 账户充值套餐赠送的金额即时到账;\n" .
  284. "3. 账户余额有效期:自充值日起至用完即止;\n" .
  285. "4. 若有其它疑问,可拨打客服电话400-000-1234", // 充值说明
  286. ],
  287. ],
  288. 'points' => [
  289. 'key' => 'points',
  290. 'describe' => '积分设置',
  291. 'values' => [
  292. 'points_name' => '积分', // 积分名称自定义
  293. 'is_shopping_gift' => '0', // 是否开启购物送积分
  294. 'gift_ratio' => '100', // 是否开启购物送积分
  295. 'is_shopping_discount' => '0', // 是否允许下单使用积分抵扣
  296. 'discount' => [ // 积分抵扣
  297. 'discount_ratio' => '0.01', // 积分抵扣比例
  298. 'full_order_price' => '100.00', // 订单满[?]元
  299. 'max_money_ratio' => '10', // 最高可抵扣订单额百分比
  300. ],
  301. // 充值说明
  302. 'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
  303. "b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
  304. "c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
  305. "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
  306. ],
  307. ],
  308. 'officia' => [
  309. 'key' => 'officia',
  310. 'describe' => '公众号关注',
  311. 'values' => [
  312. 'status' => 0
  313. ],
  314. ],
  315. 'collection' => [
  316. 'key' => 'collection',
  317. 'describe' => '引导收藏',
  318. 'values' => [
  319. 'status' => 0
  320. ],
  321. ],
  322. 'recommend' => [
  323. 'key' => 'recommend',
  324. 'describe' => '商品推荐',
  325. 'values' => [
  326. 'is_recommend' => '0',
  327. 'location' => [],
  328. 'choice' => '0',
  329. 'type' => '10',
  330. 'num' => '20',
  331. 'product' => []
  332. ],
  333. ],
  334. 'basic' => [
  335. 'key' => 'basic',
  336. 'describe' => '好物圈',
  337. 'values' => [
  338. // 是否开启
  339. 'status' => 0,
  340. // 是否同步购物车 (商品收藏)
  341. 'is_shopping' => '0',
  342. // 是否同步订单
  343. 'is_order' => '0',
  344. ]
  345. ],
  346. 'homepush' => [
  347. 'key' => 'homepush',
  348. 'describe' => '首页推送',
  349. 'values' => [
  350. // 是否开启
  351. 'is_open' => 0,
  352. ]
  353. ],
  354. 'pointsmall' => [
  355. 'key' => 'pointsmall',
  356. 'describe' => '积分商城',
  357. 'values' => [
  358. // 是否开启
  359. 'is_open' => false,
  360. // 是否使用优惠券
  361. 'is_coupon' => false,
  362. // 是否分销
  363. 'is_agent' => false,
  364. ]
  365. ],
  366. 'bargain' => [
  367. 'key' => 'bargain',
  368. 'describe' => '限时砍价',
  369. 'values' => [
  370. // 是否使用优惠券
  371. 'is_coupon' => false,
  372. // 是否分销
  373. 'is_agent' => false,
  374. // 是否开启积分
  375. 'is_point' => false,
  376. // 规则
  377. 'bargain_rules' => ''
  378. ]
  379. ],
  380. 'sign' => [
  381. 'key' => 'sign',
  382. 'describe' => '签到有礼',
  383. 'values' => [
  384. // 是否开启
  385. 'is_open' => false
  386. ]
  387. ],
  388. 'seckill' => [
  389. 'key' => 'seckill',
  390. 'describe' => '限时秒杀',
  391. 'values' => [
  392. // 是否开启积分
  393. 'is_point' => false,
  394. // 是否开启分销
  395. 'is_agent' => false,
  396. //未付款订单自动关闭时间,分钟
  397. 'order_close' => 10,
  398. // 是否使用优惠券
  399. 'is_coupon' => false,
  400. ]
  401. ],
  402. 'assemble' => [
  403. 'key' => 'assemble',
  404. 'describe' => '限时拼团',
  405. 'values' => [
  406. // 是否开启
  407. 'is_open' => false,
  408. // 是否开启积分
  409. 'is_point' => false,
  410. // 是否开启分销
  411. 'is_agent' => false,
  412. // 是否使用优惠券
  413. 'is_coupon' => false,
  414. ]
  415. ],
  416. 'getPhone' => [
  417. 'key' => 'getPhone',
  418. 'describe' => '获取手机号设置',
  419. 'values' => [
  420. // 显示区域
  421. 'area_type' => [],
  422. // 不再提示天数
  423. 'send_day' => 7
  424. ],
  425. ],
  426. 'live' => [
  427. 'key' => 'live',
  428. 'describe' => '直播设置',
  429. 'values' => [
  430. // 是否开启直播
  431. 'is_open' => '0',
  432. //是否开启审核
  433. 'is_audit' => '1',
  434. //礼物名称
  435. 'gift_name' => '玖币',
  436. // appid
  437. 'sdkappid' => '',
  438. // key
  439. 'key' => '',
  440. // 是否开启录制
  441. 'is_record' => '0',
  442. // 存储设置
  443. 'vendor' => '',
  444. 'region' => '',
  445. 'bucket' => '',
  446. 'accessKey' => '',
  447. 'secretKey' => '',
  448. 'username' => '',
  449. 'password' => '',
  450. 'domain' => ''
  451. ]
  452. ],
  453. 'appshare' => [
  454. 'key' => 'appshare',
  455. 'describe' => 'app分享',
  456. 'values' => [
  457. // 分享类型 1公众号/h5 2小程序 3下载页
  458. 'type' => '1',
  459. // 公众号、h5地址
  460. 'open_site' => '',
  461. // 小程序原始id
  462. 'gh_id' => '',
  463. // 跳转网页
  464. 'web_url' => '',
  465. // 下载页
  466. 'down_url' => '',
  467. // 绑定类型
  468. 'bind_type' => '1'
  469. ]
  470. ],
  471. 'nav' => [
  472. 'key' => 'nav',
  473. 'describe' => '底部导航',
  474. 'values' => [
  475. 'data' => [
  476. "type" => 0,
  477. "backgroundColor" => "#FFFFFF",
  478. "textColor" => "#000000",
  479. "textHoverColor" => "#E2231A",
  480. "bulge" => "true",
  481. "list" => [
  482. ["iconPath" => $url . "image/diy/navbar/home.png", "text" => "首页", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/home-on.png", "link" => ["wap_url" => "/pages/index/index"]],
  483. ["iconPath" => $url . "image/diy/navbar/fl.png", "text" => "分类", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/fl-on.png", "link" => ["wap_url" => "/pages/product/category"]],
  484. ["iconPath" => $url . "image/diy/navbar/store.png", "text" => "店铺", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/store-on.png", "link" => ["wap_url" => "/pages/shop/shop_list"]],
  485. ["iconPath" => $url . "image/diy/navbar/cart.png", "text" => "购物车", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/cart-on.png", "link" => ["wap_url" => "/pages/cart/cart"]],
  486. ["iconPath" => $url . "image/diy/navbar/wode.png", "text" => "我的", "is_show" => "true", "selectedIconPath" => $url . "image/diy/navbar/wode-on.png", "link" => ["wap_url" => "/pages/user/index/index"]]
  487. ]
  488. ]
  489. ]
  490. ],
  491. 'sys_config' => [
  492. 'key' => 'sys_config',
  493. 'describe' => '系统设置',
  494. 'values' => [
  495. 'shop_name' => '商城管理系统',
  496. 'shop_bg_img' => '',
  497. 'supplier_name' => '商城供应商管理系统',
  498. 'supplier_bg_img' => '',
  499. 'url' => 'wss://',
  500. 'service_open' => 0,
  501. ]
  502. ],
  503. 'balance' => [
  504. 'key' => 'balance',
  505. 'describe' => '充值设置',
  506. 'values' => [
  507. // 是否开启
  508. 'is_open' => 0,
  509. // 是否可以自定义
  510. 'is_plan' => 1,
  511. // 最低充值金额
  512. 'min_money' => 1,
  513. // 充值说明
  514. 'describe' => "a) 账户充值仅限在线方式支付,充值金额实时到账;\n" .
  515. "b) 有问题请联系客服;\n",
  516. ]
  517. ],
  518. 'h5Alipay' => [
  519. 'key' => 'h5Alipay',
  520. 'describe' => 'h5支付宝支付',
  521. 'values' => [
  522. // 是否开启
  523. 'is_open' => false,
  524. // 支付宝app_id
  525. 'app_id' => '',
  526. // 支付宝公钥
  527. 'publicKey' => '',
  528. // 应用私钥
  529. 'privateKey' => ''
  530. ]
  531. ],
  532. SettingEnum::BOTTOMNAV => [
  533. 'key' => 'tabbar',
  534. 'describe' => '底部导航',
  535. 'values' => [
  536. // 选中颜色
  537. 'color' => '#E2231A',
  538. // 未选中颜色
  539. 'no_color' => '#999999',
  540. // 菜单
  541. 'menu_type' => 1,//1,店铺,2订单
  542. // 菜单
  543. 'menus' => [
  544. [
  545. 'index' => 0,
  546. 'text' => '首页',
  547. 'iconPath' => self::$base_url . 'image/tabbar/shop.png',
  548. 'selectedIconPath' => self::$base_url . 'image/tabbar/shop_active.png',
  549. ],
  550. [
  551. 'index' => 1,
  552. 'text' => '商品',
  553. 'iconPath' => self::$base_url . 'image/tabbar/goods.png',
  554. 'selectedIconPath' => self::$base_url . 'image/tabbar/goods_active.png',
  555. ],
  556. [
  557. 'index' => 3,
  558. 'text' => '购物车',
  559. 'iconPath' => self::$base_url . 'image/tabbar/cart.png',
  560. 'selectedIconPath' => self::$base_url . 'image/tabbar/cart_active.png',
  561. ],
  562. [
  563. 'index' => 4,
  564. 'text' => '我的',
  565. 'iconPath' => self::$base_url . 'image/tabbar/user.png',
  566. 'selectedIconPath' => self::$base_url . 'image/tabbar/user_active.png',
  567. ],
  568. ],
  569. 'menus1' => [
  570. [
  571. 'index' => 0,
  572. 'text' => '首页',
  573. 'iconPath' => self::$base_url . 'image/tabbar/home.png',
  574. 'selectedIconPath' => self::$base_url . 'image/tabbar/home_active.png',
  575. ],
  576. [
  577. 'index' => 1,
  578. 'text' => '分类',
  579. 'iconPath' => self::$base_url . 'image/tabbar/category.png',
  580. 'selectedIconPath' => self::$base_url . 'image/tabbar/category_active.png',
  581. ],
  582. [
  583. 'index' => 2,
  584. 'text' => '店铺',
  585. 'iconPath' => self::$base_url . 'image/tabbar/shop.png',
  586. 'selectedIconPath' => self::$base_url . 'image/tabbar/shop_active.png',
  587. ],
  588. [
  589. 'index' => 3,
  590. 'text' => '购物车',
  591. 'iconPath' => self::$base_url . 'image/tabbar/cart.png',
  592. 'selectedIconPath' => self::$base_url . 'image/tabbar/cart_active.png',
  593. ],
  594. [
  595. 'index' => 4,
  596. 'text' => '我的',
  597. 'iconPath' => self::$base_url . 'image/tabbar/user.png',
  598. 'selectedIconPath' => self::$base_url . 'image/tabbar/user_active.png',
  599. ],
  600. [
  601. 'index' => 5,
  602. 'text' => '订单',
  603. 'iconPath' => self::$base_url . 'image/tabbar/order.png',
  604. 'selectedIconPath' => self::$base_url . 'image/tabbar/order_active.png',
  605. ],
  606. ]
  607. ]
  608. ],
  609. ];
  610. }
  611. }