__('Status -3'),'-1' => __('Status -1'), '0' => __('Status 0'), '3' => __('Status 3')]; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : (isset($data['status']) ? $data['status'] : ''); $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } public function order() { return $this->belongsTo(Order::class, 'classes_hour_order_id', 'id', [], 'LEFT')->setEagerlyType(0); } /**记录订单日志 * @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',$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_hour_order_id"] = $order['id']; unset($log_data['id']); unset($log_data['createtime']); if($mark)$log_data['log_text'] = $mark; $log_data = array_merge($log_data,$data); $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; } }