Setting.php 8.9 KB

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