123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Trylessonorder extends Model
- {
-
-
- // 表名
- protected $table = 'trylesson_order';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'order_status_text',
- 'paytime_text',
- 'starttime_text',
- 'endtime_text',
- 'pay_type_text'
- ];
-
-
- public function getOrderStatusList()
- {
- return ['0' => __('Order_status 0'), '10' => __('Order_status 10'), '20' => __('Order_status 20')];
- }
- public function getPayTypeList()
- {
- return ['1' => __('Pay_type 1'), '2' => __('Pay_type 2')];
- }
- public function getOrderStatusTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['order_status']) ? $data['order_status'] : '');
- $list = $this->getOrderStatusList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getPaytimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['paytime']) ? $data['paytime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getStarttimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['starttime']) ? $data['starttime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getEndtimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['endtime']) ? $data['endtime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getPayTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['pay_type']) ? $data['pay_type'] : '');
- $list = $this->getPayTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- protected function setPaytimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setStarttimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setEndtimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public function user()
- {
- return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function trylesson()
- {
- return $this->belongsTo('Trylesson', 'trylesson_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|