| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace app\common\model;
- use think\Model;
- class Order extends Model
- {
- // 表名
- protected $name = 'order';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'create_time';
- protected $updateTime = 'update_time';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'create_time_text',
- 'update_time_text'
- ];
- //订单状态
- const Default = 0;
- const Pending = 100;
- const Freeze = 101;
- const Success = 200;
- const Fail = 400;
- const Cancel = 500;
- /*
- * 订单状态
- * 0未支付 1完成 2冻结 3取消
- */
- public function getStatusNames($type = -1){
- $status_names = [
- '-1' => __('全部状态'),
- self::Default => __('待支付'),
- self::Pending => __('待完成'),
- self::Freeze => __('冻结中'),
- self::Success => __('完成'),
- self::Fail => __('失败'),
- self::Cancel => __('取消'),
- ];
- if($type == -1){
- return $status_names;
- }
- if(isset($status_names[$type])){
- return $status_names[$type];
- }
- return __('未定义');
- }
- //users
- public function users()
- {
- return $this->hasOne('Users','id','user_id',[],'LEFT')->setEagerlyType(0);
- }
- //操作列表
- public function getstatusList()
- {
- return [self::Success => __('Finish'), 2 => __('Freeze'), 3 => __('Cancel')];
- }
- public function getCreateTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getUpdateTimeTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['update_time']) ? $data['update_time'] : '');
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setCreateTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- protected function setUpdateTimeAttr($value)
- {
- return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
- }
- }
|