PayWarningRule.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\common\model;
  3. use think\Cache;
  4. use think\Db;
  5. /**
  6. * 充值预警规则表
  7. * @author Administrator
  8. */
  9. class PayWarningRule extends \think\Model
  10. {
  11. protected $pk = 'id';
  12. protected $table = 'nw_pay_warning_rule';
  13. protected $dateFormat = false; //时间戳格式不自动转换
  14. const CACHE_KEY = "clearable_pay_warning_rule";
  15. protected static function init()
  16. {
  17. PaySetting::afterInsert(function () {
  18. Cache::rm(self::CACHE_KEY);
  19. });
  20. PaySetting::afterUpdate(function () {
  21. Cache::rm(self::CACHE_KEY);
  22. });
  23. PaySetting::afterWrite(function () {
  24. Cache::rm(self::CACHE_KEY);
  25. });
  26. }
  27. /**
  28. * 获取配置信息
  29. * @return boolean|unknown
  30. */
  31. public function getPaySetting()
  32. {
  33. $list = Cache::get(self::CACHE_KEY);
  34. if (empty($list)) {
  35. $list = Db::table($this->table)->field('id,warning_time,order_count,min_amount,max_amount,is_six')->select();
  36. if (!empty($list)) {
  37. Cache::set(self::CACHE_KEY, $list, 3600 * 24 * 10);
  38. }
  39. }
  40. return $list;
  41. }
  42. }