<?php
namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;

class MallOrder extends Model
{
	// 设置字段信息
    protected $schema = [
        'id'			=> 'int',
		'userid'		=> 'int',
		'ordersn'		=> 'string',
		
		'goodsid'		=> 'int',
		'title'			=> 'string',
		'tilpic'		=> 'string',
		'gintegral'		=> 'int',
		'gpaymoney'		=> 'float',
		'buynumber'		=> 'int',

		'integral'		=> 'int',
		'paymoney'		=> 'float',
		'payinfo'		=> 'string',
		'status'		=> 'tinyint',
		
		'username'		=> 'string',
		'usermobile'	=> 'string',
		'province'		=> 'string',
		'city'			=> 'string',
		'county'		=> 'string',
		'detailinfo'	=> 'string',
		'remark'		=> 'string',

		'createtime'	=> 'int',
		'deletetime'    => 'int'
    ];
	use SoftDelete;
	protected $deleteTime = 'deletetime';
	protected $defaultSoftDelete = 0;

	// 设置字段自动转换类型 
	protected $type = [
		'payinfo'		=> 'json',
        'createtime'	=> 'timestamp:Y-m-d H:i:s',
        'deletetime'	=> 'timestamp:Y-m-d H:i:s'
    ]; 
	// 设置JSON数据返回数组
	protected $jsonAssoc = true;
	
	public function getStatusTextAttr($value,$data)
	{
		$status = [1=>'已取消', 2=>'已扣分', 3=>'已支付', 4=>'已完成', 5=>'已退单']; 
		return $status[$data['status']];
	}

	// 关联User
	public function user()
	{
	    return $this->hasOne(User::class, "id", "userid");
	}
	
	// 关联MallGoods
	public function mallGoods()
	{
	    return $this->hasOne(MallGoods::class, "id", "goodsid");
	}
	
	
}