Index.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace app\common\model\pay;
  3. use think\Model;
  4. class Index extends Model
  5. {
  6. // 表名
  7. protected $name = 'shop_pay';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'paid_time_text',
  17. 'status_text'
  18. ];
  19. public function getStatusList()
  20. {
  21. return ['unpaid' => __('Status unpaid'), 'paid' => __('Status paid'), 'refund' => __('Status refund')];
  22. }
  23. public function getPaidTimeTextAttr($value, $data)
  24. {
  25. $value = $value ?: ($data['paid_time'] ?? '');
  26. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  27. }
  28. public function getStatusTextAttr($value, $data)
  29. {
  30. $value = $value ?: ($data['status'] ?? '');
  31. $list = $this->getStatusList();
  32. return $list[$value] ?? '';
  33. }
  34. protected function setPaidTimeAttr($value)
  35. {
  36. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  37. }
  38. }