Setting.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\common\model\store;
  13. use think\facade\Cache;
  14. use app\common\library\helper;
  15. use cores\BaseModel;
  16. use app\common\enum\Setting as SettingEnum;
  17. use app\common\enum\file\Storage as StorageEnum;
  18. use app\common\enum\order\DeliveryType as DeliveryTypeEnum;
  19. use app\common\enum\setting\sms\Scene as SettingSmsSceneEnum;
  20. use app\common\enum\store\page\category\Style as PageCategoryStyleEnum;
  21. /**
  22. * 系统设置模型
  23. * Class Setting
  24. * @package app\common\model
  25. */
  26. class Setting extends BaseModel
  27. {
  28. // 定义表名
  29. protected $name = 'store_setting';
  30. /**
  31. * 获取器: 转义数组格式
  32. * @param $value
  33. * @return mixed
  34. */
  35. public function getValuesAttr($value)
  36. {
  37. return helper::jsonDecode($value);
  38. }
  39. /**
  40. * 修改器: 转义成json格式
  41. * @param $value
  42. * @return string
  43. */
  44. public function setValuesAttr($value): string
  45. {
  46. return helper::jsonEncode($value);
  47. }
  48. /**
  49. * 获取指定项设置
  50. * @param string $key
  51. * @param int|null $storeId
  52. * @return array|mixed
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public static function getItem(string $key, int $storeId = null)
  58. {
  59. $data = self::getAll($storeId);
  60. return isset($data[$key]) ? $data[$key]['values'] : [];
  61. }
  62. /**
  63. * 获取设置项信息
  64. * @param string $key
  65. * @param int|null $storeId
  66. * @return array|\think\Model|null
  67. * @throws \think\db\exception\DataNotFoundException
  68. * @throws \think\db\exception\DbException
  69. * @throws \think\db\exception\ModelNotFoundException
  70. */
  71. public static function detail(string $key, int $storeId = null)
  72. {
  73. $query = (new static)->getNewQuery();
  74. $storeId > 0 && $query->where('store_id', '=', $storeId);
  75. return $query->where('key', '=', $key)->find();
  76. }
  77. /**
  78. * 全局缓存: 系统设置
  79. * @param int|null $storeId
  80. * @return array
  81. * @throws \think\db\exception\DataNotFoundException
  82. * @throws \think\db\exception\DbException
  83. * @throws \think\db\exception\ModelNotFoundException
  84. */
  85. public static function getAll(int $storeId = null): array
  86. {
  87. is_null($storeId) && $storeId = static::$storeId;
  88. $model = new static;
  89. if (!$data = Cache::get("setting_{$storeId}")) {
  90. // 获取商城设置列表
  91. $setting = $model->getList($storeId);
  92. $data = $setting->isEmpty() ? [] : helper::arrayColumn2Key($setting->toArray(), 'key');
  93. // 写入缓存中
  94. Cache::tag('cache')->set("setting_{$storeId}", $data);
  95. }
  96. // 合并默认设置
  97. return array_merge_multiple($model->defaultData(), $data);
  98. }
  99. /**
  100. * 获取商城设置列表
  101. * @param $storeId
  102. * @return \think\Collection
  103. * @throws \think\db\exception\DataNotFoundException
  104. * @throws \think\db\exception\DbException
  105. * @throws \think\db\exception\ModelNotFoundException
  106. */
  107. private function getList(int $storeId)
  108. {
  109. return $this->where('store_id', '=', $storeId)->select();
  110. }
  111. /**
  112. * 默认配置
  113. * @return array
  114. */
  115. public function defaultData(): array
  116. {
  117. return [
  118. // 配送设置
  119. SettingEnum::DELIVERY => [
  120. 'key' => SettingEnum::DELIVERY,
  121. 'describe' => '配送设置',
  122. 'values' => [
  123. // 配送方式
  124. 'delivery_type' => array_keys(DeliveryTypeEnum::data()),
  125. // 快递100
  126. 'kuaidi100' => [
  127. 'customer' => '',
  128. 'key' => '',
  129. ]
  130. ],
  131. ],
  132. // 交易设置
  133. SettingEnum::TRADE => [
  134. 'key' => SettingEnum::TRADE,
  135. 'describe' => '交易设置',
  136. 'values' => [
  137. // 订单流程设置
  138. 'order' => [
  139. 'close_days' => '3',
  140. 'receive_days' => '10',
  141. 'refund_days' => '7'
  142. ],
  143. // 运费组合策略
  144. 'freight_rule' => '10',
  145. ]
  146. ],
  147. // 上传设置
  148. SettingEnum::STORAGE => [
  149. 'key' => SettingEnum::STORAGE,
  150. 'describe' => '上传设置',
  151. 'values' => [
  152. 'default' => StorageEnum::LOCAL,
  153. 'engine' => [
  154. StorageEnum::LOCAL => null,
  155. StorageEnum::QINIU => [
  156. 'bucket' => '',
  157. 'access_key' => '',
  158. 'secret_key' => '',
  159. 'domain' => 'http://'
  160. ],
  161. StorageEnum::ALIYUN => [
  162. 'bucket' => '',
  163. 'access_key_id' => '',
  164. 'access_key_secret' => '',
  165. 'domain' => 'http://'
  166. ],
  167. StorageEnum::QCLOUD => [
  168. 'bucket' => '',
  169. 'region' => '',
  170. 'secret_id' => '',
  171. 'secret_key' => '',
  172. 'domain' => 'http://'
  173. ],
  174. ]
  175. ],
  176. ],
  177. // 短信通知
  178. SettingEnum::SMS => [
  179. 'key' => SettingEnum::SMS,
  180. 'describe' => '短信通知',
  181. 'values' => [
  182. 'default' => 'aliyun',
  183. // 短信服务渠道
  184. 'engine' => [
  185. // 阿里云
  186. 'aliyun' => [
  187. 'name' => '阿里云短信',
  188. 'website' => 'https://dysms.console.aliyun.com/dysms.htm',
  189. 'AccessKeyId' => '',
  190. 'AccessKeySecret' => '',
  191. 'sign' => '萤火商城' // 短信签名
  192. ],
  193. // 腾讯云
  194. 'qcloud' => [
  195. 'name' => '腾讯云短信',
  196. 'website' => 'https://console.cloud.tencent.com/smsv2',
  197. 'SdkAppID' => '',
  198. 'AccessKeyId' => '',
  199. 'AccessKeySecret' => '',
  200. 'sign' => '萤火商城' // 短信签名
  201. ],
  202. // 七牛云
  203. 'qiniu' => [
  204. 'name' => '七牛云短信',
  205. 'website' => 'https://portal.qiniu.com/sms/dashboard',
  206. 'AccessKey' => '',
  207. 'SecretKey' => '',
  208. 'sign' => '萤火商城' // 短信签名
  209. ],
  210. ],
  211. // 短信通知场景
  212. 'scene' => [
  213. // 短信验证码
  214. SettingSmsSceneEnum::CAPTCHA => [
  215. 'name' => '短信验证码', // 场景名称
  216. 'isEnable' => false, // 是否开启
  217. 'templateCode' => '', // 模板ID
  218. 'content' => '验证码${code},您正在进行身份验证,打死不要告诉别人哦!'
  219. ],
  220. // 新付款订单
  221. SettingSmsSceneEnum::ORDER_PAY => [
  222. 'name' => '新付款订单', // 场景名称
  223. 'isEnable' => false, // 是否开启
  224. 'templateCode' => '', // 模板ID
  225. 'acceptPhone' => '', // 接收手机号
  226. 'content' => '您有一条新订单,订单号为:${order_no},请注意查看'
  227. ]
  228. ]
  229. ],
  230. ],
  231. // 满额包邮设置
  232. SettingEnum::FULL_FREE => [
  233. 'key' => SettingEnum::FULL_FREE,
  234. 'describe' => '满额包邮设置',
  235. 'values' => [
  236. 'is_open' => 0, // 是否开启满额包邮
  237. 'money' => '', // 单笔订单额度
  238. 'excludedRegions' => [ // 不参与包邮的地区
  239. 'cityIds' => [], // 城市ID集
  240. 'selectedText' => '' // 选择的地区(文字)
  241. ],
  242. 'excludedGoodsIds' => [], // 不参与包邮的商品 (ID集)
  243. 'describe' => '' // 满额包邮说明
  244. ],
  245. ],
  246. // 用户充值设置
  247. SettingEnum::RECHARGE => [
  248. 'key' => SettingEnum::RECHARGE,
  249. 'describe' => '用户充值设置',
  250. 'values' => [
  251. 'is_entrance' => 1, // 是否允许用户充值
  252. 'is_custom' => 1, // 是否允许自定义金额
  253. 'lowest_money' => 10, // 最低充值金额
  254. 'is_match_plan' => 1, // 自定义金额是否自动匹配合适的套餐
  255. 'describe' => "1. 账户充值仅限微信在线方式支付,充值金额实时到账;\n" .
  256. "2. 账户充值套餐赠送的金额即时到账;\n" .
  257. "3. 账户余额有效期:自充值日起至用完即止;\n" .
  258. "4. 若有其它疑问,可拨打客服电话400-000-1234", // 充值说明
  259. ],
  260. ],
  261. // 积分设置
  262. SettingEnum::POINTS => [
  263. 'key' => SettingEnum::POINTS,
  264. 'describe' => SettingEnum::data()[SettingEnum::POINTS]['describe'],
  265. 'values' => [
  266. 'points_name' => '积分', // 积分名称自定义
  267. 'is_shopping_gift' => 0, // 是否开启购物送积分
  268. 'gift_ratio' => '100', // 积分赠送比例
  269. 'is_shopping_discount' => 0, // 是否允许下单使用积分抵扣
  270. 'discount' => [ // 积分抵扣
  271. 'discount_ratio' => '0.01', // 积分抵扣比例
  272. 'full_order_price' => '100.00', // 订单满[?]元
  273. 'max_money_ratio' => '10', // 最高可抵扣订单额百分比
  274. ],
  275. // 积分说明
  276. 'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
  277. "b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
  278. "c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
  279. "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
  280. ],
  281. ],
  282. // 分类页模板
  283. SettingEnum::PAGE_CATEGORY_TEMPLATE => [
  284. 'key' => SettingEnum::PAGE_CATEGORY_TEMPLATE,
  285. 'describe' => '分类页模板设置',
  286. 'values' => [
  287. 'style' => PageCategoryStyleEnum::TWO_LEVEL, // 分类页样式
  288. 'shareTitle' => '' // 分享标题
  289. ]
  290. ]
  291. ];
  292. }
  293. }