| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace app\admin\model\order;
- use think\Model;
- class Order extends Model
- {
- // 表名
- protected $name = 'order';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'trip_type_text',
- 'payment_type_text',
- 'status_text',
- 'pay_time_text',
- 'cancel_time_text'
- ];
- public function getTripTypeList()
- {
- return ['bus' => __('Bus'), 'taxi' => __('Taxi')];
- }
- public function getPaymentTypeList()
- {
- return ['ali' => __('Ali'), 'wechat' => __('Wechat'), 'balance' => __('Balance')];
- }
- public function getStatusList()
- {
- return [
- 'default' => __('Default'),
- 'purchase' => __('Purchase'),
- 'proceed' => __('Proceed'),
- 'finish' => __('Finish'),
- 'wait_feedback' => __('Wait_feedback'),
- 'cancel' => __('Cancel'),
- 'reject' => __('Reject'),
- 'admin_cancel' => __('Admin_cancel'),
- 'auto_cancel' => __('Auto_cancel'),
- ];
- }
- public function getTripTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['trip_type']) ? $data['trip_type'] : '');
- $list = $this->getTripTypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getPaymentTypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['payment_type']) ? $data['payment_type'] : '');
- $list = $this->getPaymentTypeList();
- 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] : '';
- }
- public function getPayTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['pay_time']) ? $data['pay_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getCancelTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setPayTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setCancelTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public function user()
- {
- return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function store()
- {
- return $this->belongsTo('app\admin\model\Store', 'store_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function massager()
- {
- return $this->belongsTo('app\admin\model\Massager', 'massager_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|