Setting.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\common\model;
  10. use think\Cache;
  11. use app\common\enum\DeliveryType as DeliveryTypeEnum;
  12. /**
  13. * 系统设置模型
  14. * Class Setting
  15. * @package app\common\model
  16. */
  17. class Setting extends BaseModel
  18. {
  19. protected $name = 'setting';
  20. protected $createTime = false;
  21. /**
  22. * 获取器: 转义数组格式
  23. * @param $value
  24. * @return mixed
  25. */
  26. public function getValuesAttr($value)
  27. {
  28. return json_decode($value, true);
  29. }
  30. /**
  31. * 修改器: 转义成json格式
  32. * @param $value
  33. * @return string
  34. */
  35. public function setValuesAttr($value)
  36. {
  37. return json_encode($value);
  38. }
  39. /**
  40. * 获取指定项设置
  41. * @param $key
  42. * @param $wxapp_id
  43. * @return array
  44. */
  45. public static function getItem($key, $wxapp_id = null)
  46. {
  47. $data = self::getAll($wxapp_id);
  48. return isset($data[$key]) ? $data[$key]['values'] : [];
  49. }
  50. /**
  51. * 获取设置项信息
  52. * @param $key
  53. * @return null|static
  54. * @throws \think\exception\DbException
  55. */
  56. public static function detail($key)
  57. {
  58. return self::get(compact('key'));
  59. }
  60. /**
  61. * 全局缓存: 系统设置
  62. * @param null $wxapp_id
  63. * @return array|mixed
  64. */
  65. public static function getAll($wxapp_id = null)
  66. {
  67. $static = new static;
  68. is_null($wxapp_id) && $wxapp_id = $static::$wxapp_id;
  69. if (!$data = Cache::get('setting_' . $wxapp_id)) {
  70. $setting = $static::all(compact('wxapp_id'));
  71. $data = empty($setting) ? [] : array_column(collection($setting)->toArray(), null, 'key');
  72. Cache::tag('cache')->set('setting_' . $wxapp_id, $data);
  73. }
  74. return $static->getMergeData($data);
  75. }
  76. /**
  77. * 合并用户设置与默认数据
  78. * @param $userData
  79. * @return array
  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. * @param null|string $storeName
  93. * @return array
  94. */
  95. public function defaultData($storeName = null)
  96. {
  97. return [
  98. 'store' => [
  99. 'key' => 'store',
  100. 'describe' => '商城设置',
  101. 'values' => [
  102. // 商城名称
  103. 'name' => $storeName ?: '点宇小程序商城',
  104. // 配送方式
  105. 'delivery_type' => array_keys(DeliveryTypeEnum::data()),
  106. // 快递100
  107. 'kuaidi100' => [
  108. 'customer' => '',
  109. 'key' => '',
  110. ]
  111. ],
  112. ],
  113. 'trade' => [
  114. 'key' => 'trade',
  115. 'describe' => '交易设置',
  116. 'values' => [
  117. 'order' => [
  118. 'close_days' => '3',
  119. 'receive_days' => '10',
  120. 'refund_days' => '7'
  121. ],
  122. 'freight_rule' => '10',
  123. ]
  124. ],
  125. 'storage' => [
  126. 'key' => 'storage',
  127. 'describe' => '上传设置',
  128. 'values' => [
  129. 'default' => 'local',
  130. 'engine' => [
  131. 'local' => [],
  132. 'qiniu' => [
  133. 'bucket' => '',
  134. 'access_key' => '',
  135. 'secret_key' => '',
  136. 'domain' => 'http://'
  137. ],
  138. 'aliyun' => [
  139. 'bucket' => '',
  140. 'access_key_id' => '',
  141. 'access_key_secret' => '',
  142. 'domain' => 'http://'
  143. ],
  144. 'qcloud' => [
  145. 'bucket' => '',
  146. 'region' => '',
  147. 'secret_id' => '',
  148. 'secret_key' => '',
  149. 'domain' => 'http://'
  150. ],
  151. ]
  152. ],
  153. ],
  154. 'sms' => [
  155. 'key' => 'sms',
  156. 'describe' => '短信通知',
  157. 'values' => [
  158. 'default' => 'aliyun',
  159. 'engine' => [
  160. 'aliyun' => [
  161. 'AccessKeyId' => '',
  162. 'AccessKeySecret' => '',
  163. 'sign' => '点宇科技',
  164. 'order_pay' => [
  165. 'is_enable' => '0',
  166. 'template_code' => '',
  167. 'accept_phone' => '',
  168. ],
  169. ],
  170. ],
  171. ],
  172. ],
  173. 'tplMsg' => [
  174. 'key' => 'tplMsg',
  175. 'describe' => '模板消息',
  176. 'values' => [
  177. 'payment' => [
  178. 'is_enable' => '0',
  179. 'template_id' => '',
  180. ],
  181. 'delivery' => [
  182. 'is_enable' => '0',
  183. 'template_id' => '',
  184. ],
  185. 'refund' => [
  186. 'is_enable' => '0',
  187. 'template_id' => '',
  188. ],
  189. ],
  190. ],
  191. 'printer' => [
  192. 'key' => 'printer',
  193. 'describe' => '小票打印机设置',
  194. 'values' => [
  195. 'is_open' => '0', // 是否开启打印
  196. 'printer_id' => '', // 打印机id
  197. 'order_status' => [], // 订单类型 10下单打印 20付款打印 30确认收货打印
  198. ],
  199. ],
  200. 'full_free' => [
  201. 'key' => 'full_free',
  202. 'describe' => '满额包邮设置',
  203. 'values' => [
  204. 'is_open' => '0', // 是否开启满额包邮
  205. 'money' => '', // 单笔订单额度
  206. 'notin_region' => [ // 不参与包邮的地区
  207. 'province' => [],
  208. 'citys' => [],
  209. 'treeData' => [],
  210. ],
  211. 'notin_goods' => [], // 不参与包邮的商品 (商品id集)
  212. ],
  213. ],
  214. 'recharge' => [
  215. 'key' => 'recharge',
  216. 'describe' => '用户充值设置',
  217. 'values' => [
  218. 'is_entrance' => '1', // 是否允许用户充值
  219. 'is_custom' => '1', // 是否允许自定义金额
  220. 'is_match_plan' => '1', // 自定义金额是否自动匹配合适的套餐
  221. 'describe' => "1. 账户充值仅限微信在线方式支付,充值金额实时到账;\n" .
  222. "2. 账户充值套餐赠送的金额即时到账;\n" .
  223. "3. 账户余额有效期:自充值日起至用完即止;\n" .
  224. "4. 若有其它疑问,可拨打客服电话400-000-1234", // 充值说明
  225. ],
  226. ],
  227. 'points' => [
  228. 'key' => 'points',
  229. 'describe' => '积分设置',
  230. 'values' => [
  231. 'points_name' => '积分', // 积分名称自定义
  232. 'is_shopping_gift' => '0', // 是否开启购物送积分
  233. 'gift_ratio' => '100', // 是否开启购物送积分
  234. 'is_shopping_discount' => '0', // 是否允许下单使用积分抵扣
  235. 'discount' => [ // 积分抵扣
  236. 'discount_ratio' => '0.01', // 积分抵扣比例
  237. 'full_order_price' => '100.00', // 订单满[?]元
  238. 'max_money_ratio' => '10', // 最高可抵扣订单额百分比
  239. ],
  240. // 充值说明
  241. 'describe' => "a) 积分不可兑现、不可转让,仅可在本平台使用;\n" .
  242. "b) 您在本平台参加特定活动也可使用积分,详细使用规则以具体活动时的规则为准;\n" .
  243. "c) 积分的数值精确到个位(小数点后全部舍弃,不进行四舍五入)\n" .
  244. "d) 买家在完成该笔交易(订单状态为“已签收”)后才能得到此笔交易的相应积分,如购买商品参加店铺其他优惠,则优惠的金额部分不享受积分获取;",
  245. ],
  246. ],
  247. ];
  248. }
  249. }