Coupon.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Coupon extends Model
  5. {
  6. // 表名
  7. protected $name = 'coupon';
  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. 'purpose_text',
  18. 'status_text'
  19. ];
  20. protected static function init()
  21. {
  22. self::afterInsert(function ($row) {
  23. $pk = $row->getPk();
  24. $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
  25. });
  26. }
  27. public function getTypeList()
  28. {
  29. return ['1' => __('Type 1'), '2' => __('Type 2')];
  30. }
  31. public function getPurposeList()
  32. {
  33. return ['0' => __('Purpose 0'), '1' => __('Purpose 1'), '2' => __('Purpose 2'), '3' => __('Purpose 3'), '4' => __('Purpose 4'), '5' => __('Purpose 5')];
  34. }
  35. public function getStatusList()
  36. {
  37. return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
  38. }
  39. public function getTypeTextAttr($value, $data)
  40. {
  41. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  42. $list = $this->getTypeList();
  43. return isset($list[$value]) ? $list[$value] : '';
  44. }
  45. public function getPurposeTextAttr($value, $data)
  46. {
  47. $value = $value ? $value : (isset($data['purpose']) ? $data['purpose'] : '');
  48. $list = $this->getPurposeList();
  49. return isset($list[$value]) ? $list[$value] : '';
  50. }
  51. public function getStatusTextAttr($value, $data)
  52. {
  53. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  54. $list = $this->getStatusList();
  55. return isset($list[$value]) ? $list[$value] : '';
  56. }
  57. }