Setting.php 16 KB

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