<?php
namespace app\common\model\shops;


use app\common\enum\PayEnum;
use app\common\enum\RefundEnum;
use app\common\model\BaseModel;
use app\common\model\master_worker\MasterWorker;
use think\model\concern\SoftDelete;


/**
 * ShopOrders模型
 * Class ShopOrders
 * @package app\common\model\shops
 */
class ShopOrders extends BaseModel
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $name = 'shop_orders';
    protected $type = [
        'address_json'=> 'array'
    ];
    public function worker()
    {
        return $this->belongsTo(MasterWorker::class, 'worker_id', 'id');
    }

    public function orderGoods()
    {
        return $this->hasMany(ShopOrderGoods::class, 'sn', 'sn');
    }

    public function getPayWayTextAttr($value, $data)
    {
        return PayEnum::getPayDesc($data['paw_way']);
    }

    public function getPayStatusTextAttr($value, $data)
    {
        $status = [
            0 => '未支付',
            1 => '已支付',
            2 => '已取消'
        ];
        return $status[$data['pay_status']] ?? '';
    }

    public function getRefundStatusTextAttr($value,$data)
    {
        $status = [
            0 => '未退款',
            1 => '已退款',
            2 => '退款失败'
        ];
        return $status[$data['refund_status']] ?? '';
    }

    public function orderlogistic()
    {
        return $this->hasMany(ShopOrderLogistic::class, 'order_id', 'id');
    }
}