RwaExchangeRecordModel.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\common\model;
  3. use Exception;
  4. use fast\Action;
  5. use fast\Asset;
  6. use fast\RechargeOrderType;
  7. use fast\RechargeStatus;
  8. use think\Db;
  9. use think\Model;
  10. class RwaExchangeRecordModel extends Model
  11. {
  12. protected $name = "rwa_exchange_record";
  13. // 自动写入时间戳字段
  14. protected $autoWriteTimestamp = 'int';
  15. // 定义时间戳字段名
  16. protected $createTime = 'create_time';
  17. protected $deleteTime = false;
  18. // 追加属性
  19. protected $append = [
  20. 'create_time_text',
  21. ];
  22. public function userInfo()
  23. {
  24. return $this->hasOne(UserModel::class, 'id', 'user_id');
  25. }
  26. //用户 user_id
  27. public function users()
  28. {
  29. return $this->hasOne('UserModel', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
  30. }
  31. //产品
  32. public function products()
  33. {
  34. return $this->hasOne('ProductLists', 'id', 'product_id', [], 'LEFT')->setEagerlyType(0);
  35. }
  36. public function getCreateTimeTextAttr($value, $data)
  37. {
  38. $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
  39. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  40. }
  41. protected function setCreateTimeAttr($value)
  42. {
  43. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  44. }
  45. }