87 lines
2.2 KiB
PHP
Executable File
87 lines
2.2 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* 订单模型
|
|
*/
|
|
|
|
namespace app\common\model;
|
|
|
|
use think\model\concern\SoftDelete;
|
|
use think\db;
|
|
class Order extends Model
|
|
{
|
|
use SoftDelete;
|
|
public $softDelete = true;
|
|
protected $name = 'order';
|
|
protected $autoWriteTimestamp = true;
|
|
|
|
//可搜索字段
|
|
protected $searchField = [];
|
|
|
|
//发货时间获取器
|
|
public function getShippingTimeAttr($value)
|
|
{
|
|
return date('Y-m-d H:i:s',$value);
|
|
}
|
|
|
|
//订单状态
|
|
public function getOrderStatusTextAttr($value, $data)
|
|
{
|
|
return self::ORDER_TEXT[$data['order_status']];
|
|
}
|
|
|
|
//订单关联商品
|
|
public function orderGoods()
|
|
{
|
|
return $this->hasMany(OrderGoods::class, 'order_id', 'id');
|
|
}
|
|
|
|
//订单用户
|
|
public function user()
|
|
{
|
|
return $this->hasOne('user', 'id', 'user_id')
|
|
->field('id,sn,nickname,avatar,mobile,create_time');
|
|
}
|
|
|
|
//收货地址
|
|
public function getDeliveryAddressAttr($value, $data)
|
|
{
|
|
$region = Db::name('dev_region')
|
|
->where('id', 'IN', [$data['province'], $data['city'], $data['district']])
|
|
->order('level asc')
|
|
->column('name');
|
|
|
|
$region_desc = implode('', $region);
|
|
return $region_desc . $data['address'];
|
|
}
|
|
|
|
|
|
/**
|
|
* Notes: 发货操作
|
|
* @param $data
|
|
*/
|
|
public static function delivery_handle($data)
|
|
{
|
|
$order_id = $data['order_id'];
|
|
$order = Order::get(['id' => $order_id], ['order_goods']);
|
|
if ($order['invoice_no']){
|
|
return true;
|
|
}
|
|
//更新订单下商品的发货状态
|
|
$order->update_time = time();
|
|
$order->shipping_time = time();
|
|
$order->order_status = 2;
|
|
$order->invoice_name = $data['invoice_name'];
|
|
$order->invoice_no = $data['invoice_no'];
|
|
$order->save();
|
|
$data_info=[
|
|
'user_id' => $order['user_id'],
|
|
'order_id' => $order['id'],
|
|
'scene' =>101,
|
|
'shipping_name' => $data['invoice_name'],
|
|
'invoice_no' => $data['invoice_no'],
|
|
'time' => date('Y-m-d H:i:s')
|
|
];
|
|
Notice::noticeByScene($order['user_id'],$data_info);
|
|
}
|
|
}
|