Setting.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 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 cores\BaseModel;
  14. use think\facade\Cache;
  15. use app\common\library\helper;
  16. use app\common\enum\{
  17. Client as ClientEnum,
  18. Setting as SettingEnum,
  19. file\Storage as StorageEnum,
  20. payment\Method as PaymentMethodEnum,
  21. order\DeliveryType as DeliveryTypeEnum,
  22. setting\sms\Scene as SettingSmsSceneEnum,
  23. store\page\category\Style as PageCategoryStyleEnum
  24. };
  25. /**
  26. * 系统设置模型
  27. * Class Setting
  28. * @package app\common\model
  29. */
  30. class Setting extends BaseModel
  31. {
  32. // 定义表名
  33. protected $name = 'store_setting';
  34. protected $createTime = false;
  35. /**
  36. * 获取器: 转义数组格式
  37. * @param $value
  38. * @return mixed
  39. */
  40. public function getValuesAttr($value)
  41. {
  42. return helper::jsonDecode($value);
  43. }
  44. /**
  45. * 修改器: 转义成json格式
  46. * @param $value
  47. * @return string
  48. */
  49. public function setValuesAttr($value): string
  50. {
  51. return helper::jsonEncode($value);
  52. }
  53. /**
  54. * 获取指定项设置
  55. * @param string $key
  56. * @param int|null $storeId
  57. * @return array|mixed
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public static function getItem(string $key, int $storeId = null)
  63. {
  64. $data = self::getAll($storeId);
  65. return isset($data[$key]) ? $data[$key]['values'] : [];
  66. }
  67. /**
  68. * 获取设置项信息
  69. * @param string $key
  70. * @param int|null $storeId
  71. * @return static|array|null
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\DbException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. */
  76. public static function detail(string $key, int $storeId = null)
  77. {
  78. $query = (new static)->getNewQuery();
  79. $storeId > 0 && $query->where('store_id', '=', $storeId);
  80. return $query->where('key', '=', $key)->find();
  81. }
  82. /**
  83. * 全局缓存: 系统设置
  84. * @param int|null $storeId
  85. * @return array
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\DbException
  88. * @throws \think\db\exception\ModelNotFoundException
  89. */
  90. public static function getAll(int $storeId = null): array
  91. {
  92. $model = new static;
  93. is_null($storeId) && $storeId = $model::$storeId;
  94. if (!$data = Cache::get("setting_{$storeId}")) {
  95. // 获取商城设置列表
  96. $setting = $model->getList($storeId);
  97. $data = $setting->isEmpty() ? [] : helper::arrayColumn2Key($setting->toArray(), 'key');
  98. // 写入缓存中
  99. Cache::tag('cache')->set("setting_{$storeId}", $data);
  100. }
  101. return \resetOptions($model->defaultData(), $data);
  102. }
  103. /**
  104. * 获取商城设置列表
  105. * @param int $storeId
  106. * @return \think\Collection
  107. * @throws \think\db\exception\DataNotFoundException
  108. * @throws \think\db\exception\DbException
  109. * @throws \think\db\exception\ModelNotFoundException
  110. */
  111. private function getList(int $storeId): \think\Collection
  112. {
  113. return $this->where('store_id', '=', $storeId)->select();
  114. }
  115. /**
  116. * 默认配置
  117. * @return array
  118. */
  119. public function defaultData(): array
  120. {
  121. return [
  122. // 配送设置
  123. SettingEnum::DELIVERY => [
  124. 'key' => SettingEnum::DELIVERY,
  125. 'describe' => '配送设置',
  126. 'values' => [
  127. // 配送方式
  128. 'delivery_type' => [DeliveryTypeEnum::EXPRESS],
  129. // 物流查询API
  130. 'traces' => [
  131. 'enable' => 0, // 是否启用物流查询服务
  132. 'default' => 'kd100', // 默认的服务网关
  133. 'providerConfig' => [
  134. 'kd100' => ['customer' => '', 'key' => ''],
  135. 'aliyun' => ['appCode' => '']
  136. ]
  137. ]
  138. ],
  139. ],
  140. // 交易设置
  141. SettingEnum::TRADE => [
  142. 'key' => SettingEnum::TRADE,
  143. 'describe' => '交易设置',
  144. 'values' => [
  145. // 订单流程设置
  146. 'order' => [
  147. 'closeHours' => 3 * 24, // 未支付订单自动关闭期限(单位:小时)
  148. 'receive_days' => '10', // 订单自动确认收货时间期限(单位:天)
  149. 'refund_days' => '7' // 订单允许申请售后的时间期限(单位:天)
  150. ],
  151. // 运费组合策略
  152. 'freight_rule' => '10',
  153. ]
  154. ],
  155. // 上传设置
  156. SettingEnum::STORAGE => [
  157. 'key' => SettingEnum::STORAGE,
  158. 'describe' => '上传设置',
  159. 'values' => [
  160. 'default' => StorageEnum::LOCAL,
  161. 'engine' => [
  162. StorageEnum::LOCAL => null,
  163. StorageEnum::QINIU => [
  164. 'bucket' => '',
  165. 'access_key' => '',
  166. 'secret_key' => '',
  167. 'domain' => 'http://'
  168. ],
  169. StorageEnum::ALIYUN => [
  170. 'bucket' => '',
  171. 'access_key_id' => '',
  172. 'access_key_secret' => '',
  173. 'domain' => 'http://'
  174. ],
  175. StorageEnum::QCLOUD => [
  176. 'bucket' => '',
  177. 'region' => '',
  178. 'secret_id' => '',
  179. 'secret_key' => '',
  180. 'domain' => 'http://'
  181. ],
  182. ]
  183. ],
  184. ],
  185. // 短信通知
  186. SettingEnum::SMS => [
  187. 'key' => SettingEnum::SMS,
  188. 'describe' => '短信通知',
  189. 'values' => [
  190. 'default' => 'aliyun',
  191. // 短信服务渠道
  192. 'engine' => [
  193. // 阿里云
  194. 'aliyun' => [
  195. 'name' => '阿里云短信',
  196. 'website' => 'https://dysms.console.aliyun.com/dysms.htm',
  197. 'AccessKeyId' => '',
  198. 'AccessKeySecret' => '',
  199. 'sign' => '萤火商城' // 短信签名
  200. ],
  201. // 腾讯云
  202. 'qcloud' => [
  203. 'name' => '腾讯云短信',
  204. 'website' => 'https://console.cloud.tencent.com/smsv2',
  205. 'SdkAppID' => '',
  206. 'AccessKeyId' => '',
  207. 'AccessKeySecret' => '',
  208. 'sign' => '萤火商城' // 短信签名
  209. ],
  210. // 七牛云
  211. 'qiniu' => [
  212. 'name' => '七牛云短信',
  213. 'website' => 'https://portal.qiniu.com/sms/dashboard',
  214. 'AccessKey' => '',
  215. 'SecretKey' => '',
  216. ],
  217. ],
  218. // 短信通知场景
  219. 'scene' => [
  220. // 短信验证码
  221. SettingSmsSceneEnum::CAPTCHA => [
  222. 'name' => '短信验证码 (通知用户)', // 场景名称
  223. 'isEnable' => false, // 是否开启
  224. 'templateCode' => '', // 模板ID
  225. 'content' => '验证码%s,您正在进行身份验证,若非本人操作,请勿泄露。',
  226. 'variables' => [
  227. 'aliyun' => ['${code}'],
  228. 'qiniu' => ['${code}'],
  229. 'qcloud' => ['{1}'],
  230. ]
  231. ],
  232. // 新付款订单
  233. SettingSmsSceneEnum::ORDER_PAY => [
  234. 'name' => '新付款订单 (通知商家)', // 场景名称
  235. 'isEnable' => false, // 是否开启
  236. 'templateCode' => '', // 模板ID
  237. 'acceptPhone' => '', // 接收手机号
  238. 'content' => '您有一条新订单,订单号为:%s,请注意查看',
  239. 'variables' => [
  240. 'aliyun' => ['${order_no}'],
  241. 'qiniu' => ['${order_no}'],
  242. 'qcloud' => ['{1}'],
  243. ]
  244. ],
  245. ]
  246. ],
  247. ],
  248. // 小票打印机设置
  249. SettingEnum::PRINTER => [
  250. 'key' => SettingEnum::PRINTER,
  251. 'describe' => '小票打印机设置',
  252. 'values' => [
  253. 'is_open' => 0, // 是否开启打印
  254. 'printer_id' => 0, // 打印机id
  255. 'order_status' => [20], // 订单类型 10下单打印 20付款打印 30确认收货打印
  256. ],
  257. ],
  258. // 满额包邮设置
  259. SettingEnum::FULL_FREE => [
  260. 'key' => SettingEnum::FULL_FREE,
  261. 'describe' => '满额包邮设置',
  262. 'values' => [
  263. 'is_open' => 0, // 是否开启满额包邮
  264. 'money' => '', // 单笔订单额度
  265. 'excludedRegions' => [ // 不参与包邮的地区
  266. 'cityIds' => [], // 城市ID集
  267. 'selectedText' => '' // 选择的地区(文字)
  268. ],
  269. 'excludedGoodsIds' => [], // 不参与包邮的商品 (ID集)
  270. 'describe' => '' // 满额包邮说明
  271. ],
  272. ],
  273. // 账户注册设置
  274. SettingEnum::REGISTER => [
  275. 'key' => SettingEnum::REGISTER,
  276. 'describe' => '账户注册设置',
  277. 'values' => [
  278. 'registerMethod' => 10, // 默认注册方式: 10=>手机号+短信验证码
  279. 'isManualBind' => 1, // 个人中心页显示手动绑定手机号
  280. 'isOauthMpweixin' => 1, // 是否开启微信小程序一键授权登录
  281. 'isPersonalMpweixin' => 0, // 微信小程序一键授权登录时填写用户昵称和头像
  282. 'isOauthMobileMpweixin' => 1, // 是否开启微信小程序一键授权手机号(2023年8月26日起该接口收费)
  283. 'isForceBindMpweixin' => 1, // 是否强制绑定手机号(微信小程序)
  284. ],
  285. ],
  286. // 用户充值设置
  287. SettingEnum::RECHARGE => [
  288. 'key' => SettingEnum::RECHARGE,
  289. 'describe' => '用户充值设置',
  290. 'values' => [
  291. 'is_entrance' => 1, // 是否允许用户充值
  292. 'is_custom' => 1, // 是否允许自定义金额
  293. 'lowest_money' => 10, // 最低充值金额
  294. 'is_match_plan' => 1, // 自定义金额是否自动匹配合适的套餐
  295. 'describe' => "1. 账户充值仅限微信在线方式支付,充值金额实时到账;\n" .
  296. "2. 账户充值套餐赠送的金额即时到账;\n" .
  297. "3. 账户余额有效期:自充值日起至用完即止;\n" .
  298. "4. 若有其它疑问,可拨打客服电话400-000-1234", // 充值说明
  299. ],
  300. ],
  301. // 积分设置
  302. SettingEnum::POINTS => [
  303. 'key' => SettingEnum::POINTS,
  304. 'describe' => SettingEnum::data()[SettingEnum::POINTS]['describe'],
  305. 'values' => [
  306. 'points_name' => '积分', // 积分名称自定义
  307. 'is_shopping_gift' => 0, // 是否开启购物送积分
  308. 'gift_ratio' => '100', // 积分赠送比例
  309. 'is_shopping_discount' => 0, // 是否允许下单使用积分抵扣
  310. 'discount' => [ // 积分抵扣
  311. 'discount_ratio' => '0.01', // 积分抵扣比例
  312. 'full_order_price' => '100.00', // 订单满[?]元
  313. 'max_money_ratio' => '10', // 最高可抵扣订单额百分比
  314. ],
  315. // 积分说明
  316. 'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
  317. "b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
  318. "c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
  319. "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
  320. ],
  321. ],
  322. // 店铺页面风格设置
  323. SettingEnum::APP_THEME => [
  324. 'key' => SettingEnum::APP_THEME,
  325. 'describe' => '店铺页面风格设置',
  326. 'values' => [
  327. 'mode' => 10, // 10系统推荐 20自定义
  328. 'themeTemplateIdx' => 0,
  329. 'data' => [
  330. 'gradualChange' => 1, // 是否开启按钮渐变色
  331. 'mainBg' => '#fa2209', // 主背景颜色
  332. 'mainBg2' => '#ff6335', // 主背景颜色 (渐变值)
  333. 'mainText' => '#ffffff', // 主文字颜色
  334. 'viceBg' => '#ffb100', // 副背景颜色
  335. 'viceBg2' => '#ffb900', // 副背景颜色 (渐变值)
  336. 'viceText' => '#ffffff', // 副文字颜色
  337. ]
  338. ]
  339. ],
  340. // 分类页模板
  341. SettingEnum::PAGE_CATEGORY_TEMPLATE => [
  342. 'key' => SettingEnum::PAGE_CATEGORY_TEMPLATE,
  343. 'describe' => '分类页模板设置',
  344. 'values' => [
  345. 'style' => PageCategoryStyleEnum::COMMODITY, // 分类页样式
  346. 'shareTitle' => '全部分类', // 分享标题
  347. 'showAddCart' => true, // 是否显示购物车按钮
  348. 'cartStyle' => 1, // 购物车按钮样式 1-3
  349. ]
  350. ],
  351. // 商城客服设置
  352. SettingEnum::CUSTOMER => [
  353. 'key' => SettingEnum::CUSTOMER,
  354. 'describe' => '商城客服设置',
  355. 'values' => [
  356. 'enabled' => 1, // 是否启用在线客服
  357. 'provider' => 'mpwxkf', // 当前使用的客服方式
  358. 'config' => [
  359. // 微信小程序客服
  360. 'mpwxkf' => [],
  361. ]
  362. ]
  363. ]
  364. ];
  365. }
  366. }