2024-11-07 18:11:08 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\common\model\school\classes\order;
|
|
|
|
|
2024-11-11 18:42:55 +08:00
|
|
|
use app\common\model\BaseModel;
|
2024-11-07 18:11:08 +08:00
|
|
|
use think\Model;
|
|
|
|
|
|
|
|
|
2024-11-11 18:42:55 +08:00
|
|
|
class OrderLog extends BaseModel
|
2024-11-07 18:11:08 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 表名
|
|
|
|
protected $name = 'school_classes_order_log';
|
|
|
|
|
|
|
|
// 自动写入时间戳字段
|
|
|
|
protected $autoWriteTimestamp = 'integer';
|
|
|
|
|
|
|
|
// 定义时间戳字段名
|
|
|
|
protected $createTime = 'createtime';
|
|
|
|
protected $updateTime = false;
|
|
|
|
protected $deleteTime = false;
|
|
|
|
|
|
|
|
// 追加属性
|
|
|
|
protected $append = [
|
|
|
|
'status_text',
|
|
|
|
'before_status_text',
|
|
|
|
'server_status_text',
|
|
|
|
'result_status_text'
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function getStatusList()
|
|
|
|
{
|
|
|
|
return ['-3' => __('Status -3'), '0' => __('Status 0'), '3' => __('Status 3'), '6' => __('Status 6'), '9' => __('Status 9')];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBeforeStatusList()
|
|
|
|
{
|
|
|
|
return ['-3' => __('Before_status -3'), '0' => __('Before_status 0'), '3' => __('Before_status 3'), '6' => __('Before_status 6'), '9' => __('Before_status 9')];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getServerStatusList()
|
|
|
|
{
|
|
|
|
return ['0' => __('Server_status 0'), '3' => __('Server_status 3'), '6' => __('Server_status 6')];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getResultStatusList()
|
|
|
|
{
|
|
|
|
return ['0' => __('Result_status 0'), '3' => __('Result_status 3'), '6' => __('Result_status 6')];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getStatusTextAttr($value, $data)
|
|
|
|
{
|
|
|
|
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
|
|
|
|
$list = $this->getStatusList();
|
|
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getBeforeStatusTextAttr($value, $data)
|
|
|
|
{
|
|
|
|
$value = $value ? $value : (isset($data['before_status']) ? $data['before_status'] : '');
|
|
|
|
$list = $this->getBeforeStatusList();
|
|
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getServerStatusTextAttr($value, $data)
|
|
|
|
{
|
|
|
|
$value = $value ? $value : (isset($data['server_status']) ? $data['server_status'] : '');
|
|
|
|
$list = $this->getServerStatusList();
|
|
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getResultStatusTextAttr($value, $data)
|
|
|
|
{
|
|
|
|
$value = $value ? $value : (isset($data['result_status']) ? $data['result_status'] : '');
|
|
|
|
$list = $this->getResultStatusList();
|
|
|
|
return isset($list[$value]) ? $list[$value] : '';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function order()
|
|
|
|
{
|
2024-11-11 18:42:55 +08:00
|
|
|
return $this->belongsTo(Order::class, 'classes_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
|
2024-11-07 18:11:08 +08:00
|
|
|
}
|
2024-11-08 18:18:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**记录订单日志
|
|
|
|
* @param $params
|
|
|
|
* @param bool $trans
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
|
|
|
public static function log($order,$mark='更新订单状态',$oper_type='user',$oper_id = 0,$trans=false){
|
|
|
|
if(is_numeric($order))$order = Order::where('order_no|id|pay_no',$order)->find();
|
|
|
|
if(!$order)throw new \Exception("找不到订单");
|
|
|
|
//操作人信息(可扩展)
|
|
|
|
$data = [
|
|
|
|
'oper_type'=>$oper_type ?: 'user',
|
|
|
|
'oper_id'=>$oper_id ?: $order['user_id'],
|
|
|
|
'remark'=>$mark,
|
|
|
|
];
|
|
|
|
//判断逻辑
|
|
|
|
if($trans){
|
|
|
|
self::beginTrans();
|
|
|
|
}
|
|
|
|
$res = true;
|
|
|
|
try{
|
|
|
|
//事务逻辑
|
|
|
|
$log_data = $order->toArray();
|
|
|
|
$log_data["classes_order_id"] = $order['id'];
|
|
|
|
unset($log_data['id']);
|
|
|
|
unset($log_data['createtime']);
|
|
|
|
if($mark)$log_data['log_text'] = $mark;
|
|
|
|
$log = (new self);
|
|
|
|
$log->allowField(true)->save($log_data);
|
|
|
|
if($trans){
|
|
|
|
self::commitTrans();
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
if($trans){
|
|
|
|
self::rollbackTrans();
|
|
|
|
}
|
|
|
|
throw new \Exception($e->getMessage());
|
|
|
|
}
|
|
|
|
return $log;
|
|
|
|
}
|
|
|
|
|
2024-11-07 18:11:08 +08:00
|
|
|
}
|