Setting.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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 think\Model;
  8. /**
  9. * 系统设置模型
  10. */
  11. class Setting extends BaseModel
  12. {
  13. protected $name = 'setting';
  14. protected $createTime = false;
  15. /**
  16. * 获取器: 转义数组格式
  17. */
  18. public function getValuesAttr($value)
  19. {
  20. return json_decode($value, true);
  21. }
  22. /**
  23. * 修改器: 转义成json格式
  24. */
  25. public function setValuesAttr($value)
  26. {
  27. return json_encode($value);
  28. }
  29. /**
  30. * 获取指定项设置
  31. */
  32. public static function getItem($key, $app_id = null)
  33. {
  34. $data = self::getAll($app_id);
  35. $data_key = $data[$key];
  36. if(isset($data_key)){
  37. $data_key = $data[$key]['values'];
  38. jsonRecursive($data_key);
  39. }else{
  40. $data_key = [];
  41. }
  42. return $data_key;
  43. }
  44. /**
  45. * 获取设置项信息
  46. */
  47. public static function detail($key)
  48. {
  49. return (new static())->where('key', '=', $key)->find();
  50. }
  51. /**
  52. * 全局缓存: 系统设置
  53. */
  54. public static function getAll($app_id = null)
  55. {
  56. $static = new static;
  57. is_null($app_id) && $app_id = $static::$app_id;
  58. Cache::delete('setting_' . $app_id);
  59. if (!$data = Cache::get('setting_' . $app_id)) {
  60. $setting = $static->where(compact('app_id'))->select();
  61. $data = empty($setting) ? [] : array_column($static->collection($setting)->toArray(), null, 'key');
  62. Cache::tag('cache')->set('setting_' . $app_id, $data);
  63. }
  64. return $static->getMergeData($data);
  65. }
  66. /**
  67. * 数组转换为数据集对象
  68. */
  69. public function collection($resultSet)
  70. {
  71. $item = current($resultSet);
  72. if ($item instanceof Model) {
  73. return \think\model\Collection::make($resultSet);
  74. } else {
  75. return \think\Collection::make($resultSet);
  76. }
  77. }
  78. /**
  79. * 合并用户设置与默认数据
  80. */
  81. private function getMergeData($userData)
  82. {
  83. $defaultData = $this->defaultData();
  84. // 商城设置:配送方式
  85. if (isset($userData['store']['values']['delivery_type'])) {
  86. unset($defaultData['store']['values']['delivery_type']);
  87. }
  88. return array_merge_multiple($defaultData, $userData);
  89. }
  90. /**
  91. * 默认配置
  92. */
  93. public function defaultData($storeName = null)
  94. {
  95. return [
  96. SettingEnum::STORE => [
  97. 'key' => 'store',
  98. 'describe' => '商城设置',
  99. 'values' => [
  100. // 商城名称
  101. 'name' => $storeName ?: '玖玖珈商城',
  102. // 配送方式
  103. 'delivery_type' => array_keys(DeliveryTypeEnum::data()),
  104. // 快递100
  105. 'kuaidi100' => [
  106. 'customer' => '',
  107. 'key' => '',
  108. ],
  109. // 是否记录日志
  110. 'is_get_log' => true,
  111. // 政策隐私
  112. 'policy' => [
  113. 'service' => self::$base_url .'service.html',
  114. 'privacy' => self::$base_url .'privacy.html',
  115. ],
  116. ],
  117. ],
  118. SettingEnum::MP_SERVICE => [
  119. 'key' => 'mp_service',
  120. 'describe' => '公众号客服设置',
  121. 'values' => [
  122. // qq
  123. 'qq' => '',
  124. // 微信
  125. 'wechat' => '',
  126. // 微信公众号图片
  127. 'mp_image' => '',
  128. ],
  129. ],
  130. SettingEnum::TRADE => [
  131. 'key' => 'trade',
  132. 'describe' => '交易设置',
  133. 'values' => [
  134. 'order' => [
  135. 'close_days' => '3',
  136. 'receive_days' => '10',
  137. 'refund_days' => '7'
  138. ],
  139. 'freight_rule' => '10',
  140. ]
  141. ],
  142. SettingEnum::STORAGE => [
  143. 'key' => 'storage',
  144. 'describe' => '上传设置',
  145. 'values' => [
  146. 'default' => 'local',
  147. 'engine' => [
  148. 'local' => [],
  149. 'qiniu' => [
  150. 'bucket' => '',
  151. 'access_key' => '',
  152. 'secret_key' => '',
  153. 'domain' => 'http://'
  154. ],
  155. 'aliyun' => [
  156. 'bucket' => '',
  157. 'access_key_id' => '',
  158. 'access_key_secret' => '',
  159. 'domain' => 'http://'
  160. ],
  161. 'qcloud' => [
  162. 'bucket' => '',
  163. 'region' => '',
  164. 'secret_id' => '',
  165. 'secret_key' => '',
  166. 'domain' => 'http://'
  167. ],
  168. ]
  169. ],
  170. ],
  171. SettingEnum::SMS => [
  172. 'key' => 'sms',
  173. 'describe' => '短信通知',
  174. 'values' => [
  175. 'default' => 'aliyun',
  176. 'engine' => [
  177. 'aliyun' => [
  178. 'AccessKeyId' => '',
  179. 'AccessKeySecret' => '',
  180. 'sign' => '三勾商城',
  181. 'accept_phone' => '',
  182. 'template_code' => ''
  183. ],
  184. ],
  185. ],
  186. ],
  187. SettingEnum::TPL_MSG => [
  188. 'key' => 'tplMsg',
  189. 'describe' => '模板消息',
  190. 'values' => [
  191. 'payment' => [
  192. 'is_enable' => '0',
  193. 'template_id' => '',
  194. ],
  195. 'delivery' => [
  196. 'is_enable' => '0',
  197. 'template_id' => '',
  198. ],
  199. 'refund' => [
  200. 'is_enable' => '0',
  201. 'template_id' => '',
  202. ],
  203. ],
  204. ],
  205. SettingEnum::PRINTER => [
  206. 'key' => 'printer',
  207. 'describe' => '小票打印机设置',
  208. 'values' => [
  209. 'is_open' => '0', // 是否开启打印
  210. 'printer_id' => '', // 打印机id
  211. 'order_status' => [], // 订单类型 10下单打印 20付款打印 30确认收货打印
  212. ],
  213. ],
  214. SettingEnum::FULL_FREE => [
  215. 'key' => 'full_free',
  216. 'describe' => '满额包邮设置',
  217. 'values' => [
  218. 'is_open' => '0', // 是否开启满额包邮
  219. 'money' => '', // 单笔订单额度
  220. ],
  221. ],
  222. SettingEnum::POINTS => [
  223. 'key' => 'points',
  224. 'describe' => '积分设置',
  225. 'values' => [
  226. 'points_name' => '积分', // 积分名称自定义
  227. 'is_shopping_gift' => '0', // 是否开启购物送积分
  228. 'gift_ratio' => '100', // 是否开启购物送积分
  229. 'is_shopping_discount' => '0', // 是否允许下单使用积分抵扣
  230. 'discount' => [ // 积分抵扣
  231. 'discount_ratio' => '0.01', // 积分抵扣比例
  232. 'full_order_price' => '100.00', // 订单满[?]元
  233. 'max_money_ratio' => '10', // 最高可抵扣订单额百分比
  234. ],
  235. // 充值说明
  236. 'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
  237. "b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
  238. "c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
  239. "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
  240. ],
  241. ],
  242. SettingEnum::OFFICIA => [
  243. 'key' => 'officia',
  244. 'describe' => '公众号关注',
  245. 'values' => [
  246. 'status' => 0
  247. ],
  248. ],
  249. SettingEnum::COLLECTION => [
  250. 'key' => 'collection',
  251. 'describe' => '引导收藏',
  252. 'values' => [
  253. 'status' => 0
  254. ],
  255. ],
  256. SettingEnum::RECOMMEND => [
  257. 'key' => 'recommend',
  258. 'describe' => '商品推荐',
  259. 'values' => [
  260. 'is_recommend' => '0',
  261. 'location' => [],
  262. 'choice' => '0',
  263. 'type' => '10',
  264. 'num' => '20',
  265. 'product' => []
  266. ],
  267. ],
  268. SettingEnum::HOMEPUSH => [
  269. 'key' => 'homepush',
  270. 'describe' => '首页推送',
  271. 'values' => [
  272. // 是否开启
  273. 'is_open' => 0,
  274. ]
  275. ],
  276. SettingEnum::POINTSMALL => [
  277. 'key' => 'pointsmall',
  278. 'describe' => '积分商城',
  279. 'values' => [
  280. // 是否开启
  281. 'is_open' => false,
  282. // 是否使用优惠券
  283. 'is_coupon' => false,
  284. // 是否分销
  285. 'is_agent' => false,
  286. ]
  287. ],
  288. SettingEnum::BARGAIN => [
  289. 'key' => 'bargain',
  290. 'describe' => '限时砍价',
  291. 'values' => [
  292. // 是否使用优惠券
  293. 'is_coupon' => false,
  294. // 是否分销
  295. 'is_agent' => false,
  296. // 是否开启积分
  297. 'is_point' => false,
  298. // 规则
  299. 'bargain_rules' => ''
  300. ]
  301. ],
  302. SettingEnum::SIGN => [
  303. 'key' => 'sign',
  304. 'describe' => '签到有礼',
  305. 'values' => [
  306. // 是否开启
  307. 'is_open' => false
  308. ]
  309. ],
  310. SettingEnum::SECKILL => [
  311. 'key' => 'seckill',
  312. 'describe' => '限时秒杀',
  313. 'values' => [
  314. // 是否开启积分
  315. 'is_point' => false,
  316. // 是否开启分销
  317. 'is_agent' => false,
  318. //未付款订单自动关闭时间,分钟
  319. 'order_close' => 10,
  320. // 是否开启优惠券
  321. 'is_coupon' => false,
  322. ]
  323. ],
  324. SettingEnum::ASSEMBLE => [
  325. 'key' => 'assemble',
  326. 'describe' => '限时拼团',
  327. 'values' => [
  328. // 是否开启
  329. 'is_open' => false,
  330. // 是否开启积分
  331. 'is_point' => false,
  332. // 是否开启分销
  333. 'is_agent' => false,
  334. // 是否使用优惠券
  335. 'is_coupon' => false,
  336. ]
  337. ],
  338. SettingEnum::GETPHOME => [
  339. 'key' => 'getPhone',
  340. 'describe' => '获取手机号设置',
  341. 'values' => [
  342. // 显示区域
  343. 'area_type' => [],
  344. // 不再提示天数
  345. 'send_day' => 7
  346. ],
  347. ],
  348. SettingEnum::BALANCE => [
  349. 'key' => 'balance',
  350. 'describe' => '充值设置',
  351. 'values' => [
  352. // 是否开启
  353. 'is_open' => 0,
  354. // 是否可以自定义
  355. 'is_plan' => 1,
  356. // 最低充值金额
  357. 'min_money' => 1,
  358. // 充值说明
  359. 'describe' => "a) 账户充值仅限在线方式支付,充值金额实时到账;\n" .
  360. "b) 有问题请联系客服;\n" ,
  361. ]
  362. ],
  363. SettingEnum::INVITATION => [
  364. 'key' => 'invitation',
  365. 'describe' => '邀请好友',
  366. 'values' => [
  367. // 是否开启
  368. 'is_open' => false,
  369. ]
  370. ],
  371. SettingEnum::APPSHARE => [
  372. 'key' => 'appshare',
  373. 'describe' => 'app分享',
  374. 'values' => [
  375. // 分享类型 1公众号/h5 2小程序 3下载页
  376. 'type' => 1,
  377. // 公众号、h5地址
  378. 'open_site' => '',
  379. // 小程序原始id
  380. 'gh_id' => '',
  381. // 跳转网页
  382. 'web_url' => '',
  383. // 下载页
  384. 'down_url' => '',
  385. // 绑定类型
  386. 'bind_type' => 1
  387. ]
  388. ],
  389. SettingEnum::H5ALIPAY => [
  390. 'key' => 'h5Alipay',
  391. 'describe' => 'h5支付宝支付',
  392. 'values' => [
  393. // 是否开启
  394. 'is_open' => false,
  395. // 支付宝app_id
  396. 'app_id' => '',
  397. // 支付宝公钥
  398. 'publicKey' => '',
  399. // 应用私钥
  400. 'privateKey' => ''
  401. ]
  402. ],
  403. SettingEnum::TABBAR => [
  404. 'key' => 'tabbar',
  405. 'describe' => '底部导航',
  406. 'values' => [
  407. // 选中颜色
  408. 'color' => '#E2231A',
  409. // 未选中颜色
  410. 'no_color' => '#999999',
  411. // 菜单
  412. 'menus' => [
  413. [
  414. 'index' => 0,
  415. 'text' => '首页',
  416. 'iconPath' => self::$base_url .'image/tabbar/home.png',
  417. 'selectedIconPath' => self::$base_url .'image/tabbar/home_active.png',
  418. ],
  419. [
  420. 'index' => 1,
  421. 'text' => '分类',
  422. 'iconPath' => self::$base_url .'image/tabbar/category.png',
  423. 'selectedIconPath' => self::$base_url .'image/tabbar/category_active.png',
  424. ],
  425. [
  426. 'index' => 2,
  427. 'text' => '购物车',
  428. 'iconPath' => self::$base_url .'image/tabbar/cart.png',
  429. 'selectedIconPath' => self::$base_url .'image/tabbar/cart_active.png',
  430. ],
  431. [
  432. 'index' => 3,
  433. 'text' => '我的',
  434. 'iconPath' => self::$base_url .'image/tabbar/user.png',
  435. 'selectedIconPath' => self::$base_url .'image/tabbar/user_active.png',
  436. ],
  437. ]
  438. ]
  439. ],
  440. SettingEnum::LIVE => [
  441. 'key' => 'live',
  442. 'describe' => '直播设置',
  443. 'values' => [
  444. // 自动同步
  445. 'auto_syn' => false,
  446. ],
  447. ],
  448. ];
  449. }
  450. }