123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Order extends Model
- {
-
-
- // 表名
- protected $name = 'order';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'integer';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = false;
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'ordertype_text',
- 'server_time_text',
- 'package_endtime_text',
- 'status_text',
- 'pay_time_text',
- 'paytype_text',
- 'hexiao_time_text',
- 'cancel_time_text',
- 'finish_time_text'
- ];
-
-
- public function getOrdertypeList()
- {
- return ['1' => __('Ordertype 1'), '2' => __('Ordertype 2'), '3' => __('Ordertype 3')];
- }
- public function getStatusList()
- {
- return ['1' => __('Status 1'),'2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4')];
- }
- public function getPaytypeList()
- {
- return ['1' => __('Paytype 1'), '2' => __('Paytype 2'), '3' => __('Paytype 3')];
- }
- public function getOrdertypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['ordertype']) ? $data['ordertype'] : '');
- $list = $this->getOrdertypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getServerTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['server_time']) ? $data['server_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getPackageEndtimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['package_endtime']) ? $data['package_endtime'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $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 getPaytypeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['paytype']) ? $data['paytype'] : '');
- $list = $this->getPaytypeList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getHexiaoTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['hexiao_time']) ? $data['hexiao_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;
- }
- public function getFinishTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['finish_time']) ? $data['finish_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setServerTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setPackageEndtimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setPayTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setHexiaoTimeAttr($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);
- }
- protected function setFinishTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- public function company()
- {
- return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function staff()
- {
- return $this->belongsTo('app\admin\model\CompanyStaff', 'staff_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function user()
- {
- return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function preorder()
- {
- return $this->belongsTo('app\admin\model\Preorder', 'pre_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function servicetype()
- {
- return $this->belongsTo('Servicetype', 'servicetype_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|