Setting.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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. $data = (new static())->getItem(SettingEnum::BOTTOMNAV);
  128. return $data['menu_type'] == 1;
  129. }
  130. /**
  131. * 默认配置
  132. */
  133. public function defaultData($storeName = null)
  134. {
  135. $url = base_url();
  136. return [
  137. 'store' => [
  138. 'key' => 'store',
  139. 'describe' => '商城设置',
  140. 'values' => [
  141. // 商城名称
  142. 'name' => $storeName ?: '玖玖珈商城',
  143. // 配送方式
  144. 'delivery_type' => array_keys(DeliveryTypeEnum::data()),
  145. // 快递100
  146. 'kuaidi100' => [
  147. 'customer' => '',
  148. 'key' => '',
  149. ],
  150. // 押金
  151. 'supplier_cash' => '0',
  152. // 抽成比例
  153. 'commission_rate' => '5',
  154. // 模式类型,B2B B2B2C
  155. 'operate_type' => OperateTypeEnum::B2B,
  156. // 新商品是否需要审核
  157. 'add_audit' => '1',
  158. // 审核通过后再修改是否需要审核
  159. 'edit_audit' => '1',
  160. // 供应商入驻图片
  161. 'supplier_image' => 'http://wx-cdn.jiujiuyunhui.com/202011091623282f83a8213.png',
  162. // 是否开启短信
  163. 'sms_open' => '1',
  164. // 是否记录日志
  165. 'is_get_log' => true
  166. ],
  167. ],
  168. 'mp_service' => [
  169. 'key' => 'mp_service',
  170. 'describe' => '公众号客服设置',
  171. 'values' => [
  172. // qq
  173. 'qq' => '',
  174. // 微信
  175. 'wechat' => '',
  176. // 微信公众号图片
  177. 'mp_image' => '',
  178. ],
  179. ],
  180. 'trade' => [
  181. 'key' => 'trade',
  182. 'describe' => '交易设置',
  183. 'values' => [
  184. 'order' => [
  185. 'close_days' => '3',
  186. 'receive_days' => '10',
  187. 'refund_days' => '7'
  188. ],
  189. 'freight_rule' => '10',
  190. ]
  191. ],
  192. 'storage' => [
  193. 'key' => 'storage',
  194. 'describe' => '上传设置',
  195. 'values' => [
  196. 'default' => 'local',
  197. 'engine' => [
  198. 'local' => [],
  199. 'qiniu' => [
  200. 'bucket' => '',
  201. 'access_key' => '',
  202. 'secret_key' => '',
  203. 'domain' => 'http://'
  204. ],
  205. 'aliyun' => [
  206. 'bucket' => '',
  207. 'access_key_id' => '',
  208. 'access_key_secret' => '',
  209. 'domain' => 'http://'
  210. ],
  211. 'qcloud' => [
  212. 'bucket' => '',
  213. 'region' => '',
  214. 'secret_id' => '',
  215. 'secret_key' => '',
  216. 'domain' => 'http://'
  217. ],
  218. ]
  219. ],
  220. ],
  221. 'sms' => [
  222. 'key' => 'sms',
  223. 'describe' => '短信通知',
  224. 'values' => [
  225. 'default' => 'aliyun',
  226. 'engine' => [
  227. 'aliyun' => [
  228. 'AccessKeyId' => '',
  229. 'AccessKeySecret' => '',
  230. 'sign' => '三勾商城',
  231. 'login_template' => '',
  232. 'apply_template' => '',
  233. 'supplier_reject_code' => '',
  234. 'supplier_pass_code' => ''
  235. ],
  236. ],
  237. ],
  238. ],
  239. 'tplMsg' => [
  240. 'key' => 'tplMsg',
  241. 'describe' => '模板消息',
  242. 'values' => [
  243. 'payment' => [
  244. 'is_enable' => '0',
  245. 'template_id' => '',
  246. ],
  247. 'delivery' => [
  248. 'is_enable' => '0',
  249. 'template_id' => '',
  250. ],
  251. 'refund' => [
  252. 'is_enable' => '0',
  253. 'template_id' => '',
  254. ],
  255. ],
  256. ],
  257. 'printer' => [
  258. 'key' => 'printer',
  259. 'describe' => '小票打印机设置',
  260. 'values' => [
  261. 'is_open' => '0', // 是否开启打印
  262. 'printer_id' => '', // 打印机id
  263. 'order_status' => [], // 订单类型 10下单打印 20付款打印 30确认收货打印
  264. ],
  265. ],
  266. 'full_free' => [
  267. 'key' => 'full_free',
  268. 'describe' => '满额包邮设置',
  269. 'values' => [
  270. 'is_open' => '0', // 是否开启满额包邮
  271. 'money' => '', // 单笔订单额度
  272. ],
  273. ],
  274. 'recharge' => [
  275. 'key' => 'recharge',
  276. 'describe' => '用户充值设置',
  277. 'values' => [
  278. 'is_entrance' => '1', // 是否允许用户充值
  279. 'is_custom' => '1', // 是否允许自定义金额
  280. 'is_match_plan' => '1', // 自定义金额是否自动匹配合适的套餐
  281. 'describe' => "1. 账户充值仅限微信在线方式支付,充值金额实时到账;\n" .
  282. "2. 账户充值套餐赠送的金额即时到账;\n" .
  283. "3. 账户余额有效期:自充值日起至用完即止;\n" .
  284. "4. 若有其它疑问,可拨打客服电话400-000-1234", // 充值说明
  285. ],
  286. ],
  287. 'points' => [
  288. 'key' => 'points',
  289. 'describe' => '积分设置',
  290. 'values' => [
  291. 'points_name' => '积分', // 积分名称自定义
  292. 'is_shopping_gift' => '0', // 是否开启购物送积分
  293. 'gift_ratio' => '100', // 是否开启购物送积分
  294. 'is_shopping_discount' => '0', // 是否允许下单使用积分抵扣
  295. 'discount' => [ // 积分抵扣
  296. 'discount_ratio' => '0.01', // 积分抵扣比例
  297. 'full_order_price' => '100.00', // 订单满[?]元
  298. 'max_money_ratio' => '10', // 最高可抵扣订单额百分比
  299. ],
  300. // 充值说明
  301. 'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
  302. "b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
  303. "c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
  304. "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
  305. ],
  306. ],
  307. 'officia' => [
  308. 'key' => 'officia',
  309. 'describe' => '公众号关注',
  310. 'values' => [
  311. 'status' => 0
  312. ],
  313. ],
  314. 'collection' => [
  315. 'key' => 'collection',
  316. 'describe' => '引导收藏',
  317. 'values' => [
  318. 'status' => 0
  319. ],
  320. ],
  321. 'recommend' => [
  322. 'key' => 'recommend',
  323. 'describe' => '商品推荐',
  324. 'values' => [
  325. 'is_recommend' => '0',
  326. 'location' => [],
  327. 'choice' => '0',
  328. 'type' => '10',
  329. 'num' => '20',
  330. 'product' => []
  331. ],
  332. ],
  333. 'basic' => [
  334. 'key' => 'basic',
  335. 'describe' => '好物圈',
  336. 'values' => [
  337. // 是否开启
  338. 'status' => 0,
  339. // 是否同步购物车 (商品收藏)
  340. 'is_shopping' => '0',
  341. // 是否同步订单
  342. 'is_order' => '0',
  343. ]
  344. ],
  345. 'homepush' => [
  346. 'key' => 'homepush',
  347. 'describe' => '首页推送',
  348. 'values' => [
  349. // 是否开启
  350. 'is_open' => 0,
  351. ]
  352. ],
  353. 'pointsmall' => [
  354. 'key' => 'pointsmall',
  355. 'describe' => '积分商城',
  356. 'values' => [
  357. // 是否开启
  358. 'is_open' => false,
  359. // 是否使用优惠券
  360. 'is_coupon' => false,
  361. // 是否分销
  362. 'is_agent' => false,
  363. ]
  364. ],
  365. 'bargain' => [
  366. 'key' => 'bargain',
  367. 'describe' => '限时砍价',
  368. 'values' => [
  369. // 是否使用优惠券
  370. 'is_coupon' => false,
  371. // 是否分销
  372. 'is_agent' => false,
  373. // 是否开启积分
  374. 'is_point' => false,
  375. // 规则
  376. 'bargain_rules' => ''
  377. ]
  378. ],
  379. 'sign' => [
  380. 'key' => 'sign',
  381. 'describe' => '签到有礼',
  382. 'values' => [
  383. // 是否开启
  384. 'is_open' => false
  385. ]
  386. ],
  387. 'seckill' => [
  388. 'key' => 'seckill',
  389. 'describe' => '限时秒杀',
  390. 'values' => [
  391. // 是否开启积分
  392. 'is_point' => false,
  393. // 是否开启分销
  394. 'is_agent' => false,
  395. //未付款订单自动关闭时间,分钟
  396. 'order_close' => 10,
  397. // 是否使用优惠券
  398. 'is_coupon' => false,
  399. ]
  400. ],
  401. 'assemble' => [
  402. 'key' => 'assemble',
  403. 'describe' => '限时拼团',
  404. 'values' => [
  405. // 是否开启
  406. 'is_open' => false,
  407. // 是否开启积分
  408. 'is_point' => false,
  409. // 是否开启分销
  410. 'is_agent' => false,
  411. // 是否使用优惠券
  412. 'is_coupon' => false,
  413. ]
  414. ],
  415. 'getPhone' => [
  416. 'key' => 'getPhone',
  417. 'describe' => '获取手机号设置',
  418. 'values' => [
  419. // 显示区域
  420. 'area_type' => [],
  421. // 不再提示天数
  422. 'send_day' => 7
  423. ],
  424. ],
  425. 'live' => [
  426. 'key' => 'live',
  427. 'describe' => '直播设置',
  428. 'values' => [
  429. // 是否开启直播
  430. 'is_open' => '0',
  431. //是否开启审核
  432. 'is_audit' => '1',
  433. //礼物名称
  434. 'gift_name'=>'玖币',
  435. // appid
  436. 'sdkappid' => '',
  437. // key
  438. 'key' => '',
  439. // 是否开启录制
  440. 'is_record' => '0',
  441. // 存储设置
  442. 'vendor' => '',
  443. 'region' => '',
  444. 'bucket' => '',
  445. 'accessKey' => '',
  446. 'secretKey' => '',
  447. 'username' => '',
  448. 'password' => '',
  449. 'domain' => ''
  450. ]
  451. ],
  452. 'appshare' => [
  453. 'key' => 'appshare',
  454. 'describe' => 'app分享',
  455. 'values' => [
  456. // 分享类型 1公众号/h5 2小程序 3下载页
  457. 'type' => '1',
  458. // 公众号、h5地址
  459. 'open_site' => '',
  460. // 小程序原始id
  461. 'gh_id' => '',
  462. // 跳转网页
  463. 'web_url' => '',
  464. // 下载页
  465. 'down_url' => '',
  466. // 绑定类型
  467. 'bind_type' => '1'
  468. ]
  469. ],
  470. 'nav' => [
  471. 'key' => 'nav',
  472. 'describe' => '底部导航',
  473. 'values' => [
  474. 'data'=>[
  475. "type"=>0,
  476. "backgroundColor"=>"#FFFFFF",
  477. "textColor"=>"#000000",
  478. "textHoverColor"=>"#E2231A",
  479. "bulge"=>"true",
  480. "list"=>[
  481. ["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"]],
  482. ["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"]],
  483. ["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"]],
  484. ["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"]],
  485. ["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"]]
  486. ]
  487. ]
  488. ]
  489. ],
  490. 'sys_config' => [
  491. 'key' => 'sys_config',
  492. 'describe' => '系统设置',
  493. 'values' => [
  494. 'shop_name' => '三勾商城管理系统',
  495. 'shop_bg_img' => '',
  496. 'supplier_name' => '三勾商城供应商管理系统',
  497. 'supplier_bg_img' => '',
  498. 'url' => 'wss://',
  499. 'service_open' => 0,
  500. ]
  501. ],
  502. 'balance' => [
  503. 'key' => 'balance',
  504. 'describe' => '充值设置',
  505. 'values' => [
  506. // 是否开启
  507. 'is_open' => 0,
  508. // 是否可以自定义
  509. 'is_plan' => 1,
  510. // 最低充值金额
  511. 'min_money' => 1,
  512. // 充值说明
  513. 'describe' => "a) 账户充值仅限在线方式支付,充值金额实时到账;\n" .
  514. "b) 有问题请联系客服;\n" ,
  515. ]
  516. ],
  517. 'h5Alipay' => [
  518. 'key' => 'h5Alipay',
  519. 'describe' => 'h5支付宝支付',
  520. 'values' => [
  521. // 是否开启
  522. 'is_open' => false,
  523. // 支付宝app_id
  524. 'app_id' => '',
  525. // 支付宝公钥
  526. 'publicKey' => '',
  527. // 应用私钥
  528. 'privateKey' => ''
  529. ]
  530. ],
  531. SettingEnum::BOTTOMNAV => [
  532. 'key' => 'tabbar',
  533. 'describe' => '底部导航',
  534. 'values' => [
  535. // 选中颜色
  536. 'color' => '#E2231A',
  537. // 未选中颜色
  538. 'no_color' => '#999999',
  539. // 菜单
  540. 'menu_type' => 1,//1,店铺,2订单
  541. // 菜单
  542. 'menus' => [
  543. [
  544. 'index' => 0,
  545. 'text' => '首页',
  546. 'iconPath' => self::$base_url .'image/tabbar/home.png',
  547. 'selectedIconPath' => self::$base_url .'image/tabbar/home_active.png',
  548. ],
  549. [
  550. 'index' => 1,
  551. 'text' => '分类',
  552. 'iconPath' => self::$base_url .'image/tabbar/category.png',
  553. 'selectedIconPath' => self::$base_url .'image/tabbar/category_active.png',
  554. ],
  555. [
  556. 'index' => 2,
  557. 'text' => '店铺',
  558. 'iconPath' => self::$base_url .'image/tabbar/shop.png',
  559. 'selectedIconPath' => self::$base_url .'image/tabbar/shop_active.png',
  560. ],
  561. [
  562. 'index' => 3,
  563. 'text' => '购物车',
  564. 'iconPath' => self::$base_url .'image/tabbar/cart.png',
  565. 'selectedIconPath' => self::$base_url .'image/tabbar/cart_active.png',
  566. ],
  567. [
  568. 'index' => 4,
  569. 'text' => '我的',
  570. 'iconPath' => self::$base_url .'image/tabbar/user.png',
  571. 'selectedIconPath' => self::$base_url .'image/tabbar/user_active.png',
  572. ],
  573. [
  574. 'index' => 5,
  575. 'text' => '订单',
  576. 'iconPath' => self::$base_url .'image/tabbar/order.png',
  577. 'selectedIconPath' => self::$base_url .'image/tabbar/order_active.png',
  578. ],
  579. ]
  580. ]
  581. ],
  582. ];
  583. }
  584. }