Setting.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 app\common\model\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, $data)
  36. {
  37. if ($data['key'] == 'brand_culture') {
  38. return htmlspecialchars_decode($value);
  39. }
  40. return helper::jsonDecode($value);
  41. }
  42. /**
  43. * 修改器: 转义成json格式
  44. * @param $value
  45. * @return string
  46. */
  47. public function setValuesAttr($value, $data)
  48. {
  49. if ($data['key'] == 'brand_culture') {
  50. return $value['content'] ?? '';
  51. }
  52. return helper::jsonEncode($value);
  53. }
  54. /**
  55. * 获取指定项设置
  56. * @param string $key
  57. * @param int|null $storeId
  58. * @return array|mixed
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\DbException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. */
  63. public static function getItem(string $key, int $storeId = null)
  64. {
  65. $data = self::getAll($storeId);
  66. return isset($data[$key]) ? $data[$key]['values'] : [];
  67. }
  68. /**
  69. * 获取设置项信息
  70. * @param string $key
  71. * @param int|null $storeId
  72. * @return array|\think\Model|null
  73. * @throws \think\db\exception\DataNotFoundException
  74. * @throws \think\db\exception\DbException
  75. * @throws \think\db\exception\ModelNotFoundException
  76. */
  77. public static function detail(string $key, int $storeId = null)
  78. {
  79. $query = (new static)->getNewQuery();
  80. $storeId > 0 && $query->where('store_id', '=', $storeId);
  81. return $query->where('key', '=', $key)->find();
  82. }
  83. /**
  84. * 全局缓存: 系统设置
  85. * @param int|null $storeId
  86. * @return array
  87. * @throws \think\db\exception\DataNotFoundException
  88. * @throws \think\db\exception\DbException
  89. * @throws \think\db\exception\ModelNotFoundException
  90. */
  91. public static function getAll(int $storeId = null)
  92. {
  93. $model = new static;
  94. is_null($storeId) && $storeId = $model::$storeId;
  95. $setting = $model->getList($storeId);
  96. $data = $setting->isEmpty() ? [] : helper::arrayColumn2Key($setting->toArray(), 'key');
  97. return $model->getMergeData($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. * @param array $actualData
  114. * @return array
  115. */
  116. private function getMergeData(array $actualData)
  117. {
  118. return array_merge_multiple($this->defaultData(), $actualData);
  119. }
  120. /**
  121. * 默认配置
  122. * @return array
  123. */
  124. public function defaultData()
  125. {
  126. return [
  127. // 配送设置
  128. SettingEnum::DELIVERY => [
  129. 'key' => SettingEnum::DELIVERY,
  130. 'describe' => '配送设置',
  131. 'values' => [
  132. // 配送方式
  133. 'delivery_type' => array_keys(DeliveryTypeEnum::data()),
  134. // 快递100
  135. 'kuaidi100' => [
  136. 'customer' => '',
  137. 'key' => '',
  138. ]
  139. ],
  140. ],
  141. // 交易设置
  142. SettingEnum::TRADE => [
  143. 'key' => SettingEnum::TRADE,
  144. 'describe' => '交易设置',
  145. 'values' => [
  146. // 订单流程设置
  147. 'order' => [
  148. 'close_days' => '3',
  149. 'receive_days' => '10',
  150. 'refund_days' => '7'
  151. ],
  152. // 运费组合策略
  153. 'freight_rule' => '10',
  154. ]
  155. ],
  156. // 上传设置
  157. SettingEnum::STORAGE => [
  158. 'key' => SettingEnum::STORAGE,
  159. 'describe' => '上传设置',
  160. 'values' => [
  161. 'default' => StorageEnum::LOCAL,
  162. 'engine' => [
  163. StorageEnum::LOCAL => null,
  164. StorageEnum::QINIU => [
  165. 'bucket' => '',
  166. 'access_key' => '',
  167. 'secret_key' => '',
  168. 'domain' => 'http://'
  169. ],
  170. StorageEnum::ALIYUN => [
  171. 'bucket' => '',
  172. 'access_key_id' => '',
  173. 'access_key_secret' => '',
  174. 'domain' => 'http://'
  175. ],
  176. StorageEnum::QCLOUD => [
  177. 'bucket' => '',
  178. 'region' => '',
  179. 'secret_id' => '',
  180. 'secret_key' => '',
  181. 'domain' => 'http://'
  182. ],
  183. ]
  184. ],
  185. ],
  186. // 短信通知
  187. SettingEnum::SMS => [
  188. 'key' => SettingEnum::SMS,
  189. 'describe' => '短信通知',
  190. 'values' => [
  191. 'default' => 'aliyun',
  192. // 短信服务渠道
  193. 'engine' => [
  194. // 阿里云
  195. 'aliyun' => [
  196. 'AccessKeyId' => '',
  197. 'AccessKeySecret' => '',
  198. 'sign' => '萤火商城' // 短信签名
  199. ]
  200. ],
  201. // 短信通知场景
  202. 'scene' => [
  203. // 短信验证码
  204. SettingSmsSceneEnum::CAPTCHA => [
  205. 'name' => '短信验证码', // 场景名称
  206. 'isEnable' => false, // 是否开启
  207. 'templateCode' => '', // 模板ID
  208. 'content' => '验证码${code},您正在进行身份验证,打死不要告诉别人哦!'
  209. ],
  210. // 新付款订单
  211. SettingSmsSceneEnum::ORDER_PAY => [
  212. 'name' => '新付款订单', // 场景名称
  213. 'isEnable' => false, // 是否开启
  214. 'templateCode' => '', // 模板ID
  215. 'acceptPhone' => '', // 接收手机号
  216. 'content' => '您有一条新订单,订单号为:${order_no},请注意查看'
  217. ]
  218. ]
  219. ],
  220. ],
  221. // 满额包邮设置
  222. SettingEnum::FULL_FREE => [
  223. 'key' => SettingEnum::FULL_FREE,
  224. 'describe' => '满额包邮设置',
  225. 'values' => [
  226. 'is_open' => 0, // 是否开启满额包邮
  227. 'money' => '', // 单笔订单额度
  228. 'excludedRegions' => [ // 不参与包邮的地区
  229. 'cityIds' => [], // 城市ID集
  230. 'selectedText' => '' // 选择的地区(文字)
  231. ],
  232. 'excludedGoodsIds' => [], // 不参与包邮的商品 (ID集)
  233. 'describe' => '' // 满额包邮说明
  234. ],
  235. ],
  236. // 用户充值设置
  237. SettingEnum::RECHARGE => [
  238. 'key' => SettingEnum::RECHARGE,
  239. 'describe' => '用户充值设置',
  240. 'values' => [
  241. 'is_entrance' => 1, // 是否允许用户充值
  242. 'is_custom' => 1, // 是否允许自定义金额
  243. 'is_match_plan' => 1, // 自定义金额是否自动匹配合适的套餐
  244. 'describe' => "1. 账户充值仅限微信在线方式支付,充值金额实时到账;\n" .
  245. "2. 账户充值套餐赠送的金额即时到账;\n" .
  246. "3. 账户余额有效期:自充值日起至用完即止;\n" .
  247. "4. 若有其它疑问,可拨打客服电话400-000-1234", // 充值说明
  248. ],
  249. ],
  250. // 积分设置
  251. SettingEnum::POINTS => [
  252. 'key' => SettingEnum::POINTS,
  253. 'describe' => SettingEnum::data()[SettingEnum::POINTS]['describe'],
  254. 'values' => [
  255. 'points_name' => '积分', // 积分名称自定义
  256. 'is_shopping_gift' => 0, // 是否开启购物送积分
  257. 'gift_ratio' => '100', // 积分赠送比例
  258. 'is_shopping_discount' => 0, // 是否允许下单使用积分抵扣
  259. 'discount' => [ // 积分抵扣
  260. 'discount_ratio' => '0.01', // 积分抵扣比例
  261. 'full_order_price' => '100.00', // 订单满[?]元
  262. 'max_money_ratio' => '10', // 最高可抵扣订单额百分比
  263. ],
  264. // 积分说明
  265. 'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
  266. "b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
  267. "c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
  268. "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
  269. ],
  270. ],
  271. // 分类页模板
  272. SettingEnum::PAGE_CATEGORY_TEMPLATE => [
  273. 'key' => SettingEnum::PAGE_CATEGORY_TEMPLATE,
  274. 'describe' => '分类页模板设置',
  275. 'values' => [
  276. 'style' => PageCategoryStyleEnum::TWO_LEVEL, // 分类页样式
  277. 'shareTitle' => '' // 分享标题
  278. ]
  279. ]
  280. ];
  281. }
  282. /**
  283. * 根据销售额获取阶梯奖励金的比例
  284. * @param $salesVolume
  285. * @return int|mixed
  286. * @throws \think\db\exception\DataNotFoundException
  287. * @throws \think\db\exception\DbException
  288. * @throws \think\db\exception\ModelNotFoundException
  289. */
  290. public static function getBonusRatioBySaleAmount($salesVolume){
  291. $ratios = (self::getItem('distributor_step'))['distributor'];
  292. $len = count($ratios);
  293. for ($i=$len-1;$i>=0;$i--){
  294. if ($salesVolume >= $ratios[$i]['sale_amount']*10000){
  295. return ['bonus_ratio'=>$ratios[$i]['bonus_ratio'],'bonus_ladder'=>$ratios[$i]['ladder']];
  296. }
  297. }
  298. // return 0;
  299. return ['bonus_ratio'=>0,'bonus_ladder'=>0];
  300. }
  301. /**
  302. * 根据分销员等级获取分销员分佣金的比例
  303. * @param $grade
  304. * @return int|mixed
  305. * @throws \think\db\exception\DataNotFoundException
  306. * @throws \think\db\exception\DbException
  307. * @throws \think\db\exception\ModelNotFoundException
  308. */
  309. private function getRatioBySellerGrade($grade){
  310. return (self::getItem('distributor_grade'))['distributor'][$grade-1];
  311. }
  312. }