12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Coupon extends Model
- {
-
-
- // 表名
- protected $name = 'coupon';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'type_text',
- 'purpose_text',
- 'status_text'
- ];
-
- protected static function init()
- {
- self::afterInsert(function ($row) {
- $pk = $row->getPk();
- $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
- });
- }
-
- public function getTypeList()
- {
- return ['1' => __('Type 1'), '2' => __('Type 2')];
- }
- public function getPurposeList()
- {
- return ['0' => __('Purpose 0'), '1' => __('Purpose 1'), '2' => __('Purpose 2'), '3' => __('Purpose 3'), '4' => __('Purpose 4'), '5' => __('Purpose 5')];
- }
- public function getStatusList()
- {
- return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2')];
- }
- public function getTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
- $list = $this->getTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getPurposeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['purpose']) ? $data['purpose'] : '');
- $list = $this->getPurposeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
- $list = $this->getStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- }
|