75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace app\common\model\order;
|
|
|
|
use think\Model;
|
|
|
|
|
|
class Item extends Model
|
|
{
|
|
|
|
|
|
// 表名
|
|
protected $name = 'order_item';
|
|
|
|
// 自动写入时间戳字段
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
// 定义时间戳字段名
|
|
protected $createTime = 'createtime';
|
|
protected $updateTime = false;
|
|
protected $deleteTime = false;
|
|
|
|
// 追加属性
|
|
protected $append = [
|
|
'refund_time_text'
|
|
];
|
|
|
|
|
|
/**
|
|
* 获取订单商品列表
|
|
* @param $orderNo
|
|
* @return array
|
|
*/
|
|
public static function getItemList($orderNo){
|
|
$data = self::where([
|
|
'order_no'=>$orderNo
|
|
])->select();
|
|
|
|
if(!$data){
|
|
return [];
|
|
}
|
|
|
|
foreach ($data as &$item){
|
|
$item['snapshoot'] = json_decode($item['snapshoot'],true);
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
|
|
|
|
public function getRefundTimeTextAttr($value, $data)
|
|
{
|
|
$value = $value ? $value : (isset($data['refund_time']) ? $data['refund_time'] : '');
|
|
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
|
|
}
|
|
|
|
protected function setRefundTimeAttr($value)
|
|
{
|
|
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
|
|
}
|
|
|
|
|
|
public function detail()
|
|
{
|
|
return $this->belongsTo('app\admin\model\Course', 'item_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
|
}
|
|
|
|
// 定义订单商品与订单的关联关系
|
|
public function order()
|
|
{
|
|
return $this->belongsTo('\app\api\model\order\Order', 'order_no');
|
|
}
|
|
}
|