CoinSetting.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\common\model;
  3. use think\Cache;
  4. /**
  5. * 平台币发放规则设置表
  6. * @author Administrator
  7. */
  8. class CoinSetting extends \think\Model
  9. {
  10. protected $pk = 'id';
  11. protected $table = 'nw_coin_setting';
  12. protected $dateFormat = false; //时间戳格式不自动转换
  13. protected static function init()
  14. {
  15. self::afterInsert(function () {
  16. //删除缓存
  17. Cache::rm('clearable_coinsetting');
  18. });
  19. self::afterUpdate(function () {
  20. //删除缓存
  21. Cache::rm('clearable_coinsetting');
  22. });
  23. self::afterWrite(function () {
  24. //删除缓存
  25. Cache::rm('clearable_coinsetting');
  26. });
  27. }
  28. /**
  29. * 更新数据
  30. *
  31. * @param $data: 需要更新的数据
  32. * @param $where:查询条件
  33. */
  34. public function updateData($data, $where)
  35. {
  36. $info = $this->where($where)->find();
  37. if (!$info) {
  38. return $this->save($data); //insert
  39. } else {
  40. $this->save($data, $where); //update
  41. return true;
  42. }
  43. }
  44. }