Virtuial.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Virtuial extends Model
  5. {
  6. // 表名
  7. protected $name = 'virtuial';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'add_time_text',
  17. ];
  18. public function getImageAttr($value, $data)
  19. {
  20. return db("goods")->where(['id'=>$data['goods_id']])->value("image");
  21. }
  22. public function getGoodsNameAttr($value, $data)
  23. {
  24. return db("goods")->where(['id'=>$data['goods_id']])->value("goods_name");
  25. }
  26. public function getPriceAttr($value, $data)
  27. {
  28. return db("goods")->where(['id'=>$data['goods_id']])->value("coin_price");
  29. }
  30. public function getAddTimeTextAttr($value, $data)
  31. {
  32. $value = $value ? $value : (isset($data['add_time']) ? $data['add_time'] : '');
  33. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  34. }
  35. protected function setAddTimeAttr($value)
  36. {
  37. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  38. }
  39. }