Setting.php 12 KB

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