Exchange.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\admin\model\shop;
  3. use think\Model;
  4. class Exchange extends Model
  5. {
  6. // 表名
  7. protected $name = 'shop_exchange';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'status_text'
  18. ];
  19. protected static function init()
  20. {
  21. self::afterInsert(function ($row) {
  22. $pk = $row->getPk();
  23. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  24. });
  25. }
  26. public function getTypeList()
  27. {
  28. return ['virtual' => __('Type virtual'), 'reality' => __('Type reality')];
  29. }
  30. public function getStatusList()
  31. {
  32. return ['normal' => __('Normal'), 'hidden' => __('Hidden')];
  33. }
  34. public function getTypeTextAttr($value, $data)
  35. {
  36. $value = $value ?: ($data['type'] ?? '');
  37. $list = $this->getTypeList();
  38. return $list[$value] ?? '';
  39. }
  40. public function getStatusTextAttr($value, $data)
  41. {
  42. $value = $value ?: ($data['status'] ?? '');
  43. $list = $this->getStatusList();
  44. return $list[$value] ?? '';
  45. }
  46. }