PayApply.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. /**
  5. * PayApply
  6. */
  7. class PayApply extends Model
  8. {
  9. // 表名
  10. protected $name = 'pay_apply';
  11. // 自动写入时间戳字段
  12. protected $autoWriteTimestamp = true;
  13. protected static function onBeforeInsert($model)
  14. {
  15. $pk = $model->getPk();
  16. $model->$pk = \app\common\library\SnowFlake::generateParticle();
  17. }
  18. public function getIdAttr($value): string
  19. {
  20. return (string)$value;
  21. }
  22. public function getPayAmountAttr($value): float
  23. {
  24. return (float)$value;
  25. }
  26. public function getImagesAttr($value): array
  27. {
  28. if ($value === '' || $value === null) return [];
  29. if (!is_array($value)) {
  30. return explode(',', $value);
  31. }
  32. return $value;
  33. }
  34. public function setImagesAttr($value): string
  35. {
  36. return is_array($value) ? implode(',', $value) : $value;
  37. }
  38. public function reqOrder()
  39. {
  40. return $this->belongsTo(\app\admin\model\ReqOrder::class, 'req_id', 'id');
  41. }
  42. }