Setting.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace app\admin\model\setting;
  3. use think\Model;
  4. class Setting extends Model
  5. {
  6. // 表名
  7. protected $name = 'setting';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = 'update_time';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'update_time_text'
  17. ];
  18. public function getUpdateTimeTextAttr($value, $data)
  19. {
  20. $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
  21. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  22. }
  23. protected function setUpdateTimeAttr($value)
  24. {
  25. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  26. }
  27. /**
  28. * RMB兑换金币
  29. * @param float $rmb
  30. * @return false|float
  31. * @author fuyelk <fuyelk@fuyelk.com>
  32. * @date 2021/07/09 15:12
  33. */
  34. public static function getCoinFromRmb(float $rmb)
  35. {
  36. if (empty($rmb)) return 0;
  37. $rate = self::where('id', 1)->value('one_rmb_to_coin_num');
  38. return round(floatval($rmb) * $rate, 5);
  39. }
  40. /**
  41. * 金币兑换RMB
  42. * @param float $coin
  43. * @return false|float
  44. * @author fuyelk <fuyelk@fuyelk.com>
  45. * @date 2021/07/09 15:13
  46. */
  47. public static function getRmbFromCoin(float $coin)
  48. {
  49. if (empty($coin)) return 0;
  50. $rate = self::where('id', 1)->value('one_rmb_to_coin_num');
  51. return round(floatval($coin) / $rate, 5);
  52. }
  53. }