hasMany(InvoiceOrder::class,"itemId","id")->whereIn('status', [1, 2]); } public static function getNumAttr($val){ return strval(floatval($val)); } public static function setNumAttr($val){ return floatval($val); } public static function onAfterUpdate(Model $model){ $code=$model->invoiceCode; $orderType=$model->order_type; $change = $model->getChangedData(); Log::info("InvoiceItem修改发票明细:onAfterUpdate:".json_encode($change,JSON_UNESCAPED_UNICODE)); Log::info("InvoiceItem数据:onAfterUpdate:".json_encode($model->toArray(),JSON_UNESCAPED_UNICODE)); if(isset($change['status'])&&in_array($change["status"],[0,1,2])){ Log::info('InvoiceItem数据:onAfterUpdate:'.json_encode($model->toArray(),JSON_UNESCAPED_UNICODE)); $num = self::where(['invoiceCode'=>$code,'order_type'=>$orderType,'status'=>0])->count(); if($orderType==2 && $num==0){ $info= PayInvoice::where(['hpNo'=>$code,"status"=>11])->findOrEmpty(); Log::info('InvoiceItem数据:onAfterUpdate:'.json_encode( $info->toArray(),JSON_UNESCAPED_UNICODE)); if(!$info->isEmpty()){ $info->status=12; $info->save(); } } } } //流程结束 public static function rmInvoice($code,$orderType=2){ $items = self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->select(); if(!empty($items)){ $orderItems=InvoiceOrder::whereIn('itemId',$items->column('id'))->select(); if(!empty($orderItems)){ foreach ($orderItems as $key=>$val){ $val->save(['status'=>3]); } } self::where(['invoiceCode'=>$code,'order_type'=>$orderType])->save(["status"=>3]); } } //退票申请 public static function refund($invNo){ $info = self::where(['invoiceCode'=>$invNo,'order_type'=>2])->select(); Log::info("退票申请:".json_encode($info->toArray(),JSON_UNESCAPED_UNICODE)); if(!$info->isEmpty()){ $orderItems=InvoiceOrder::whereIn('itemId',$info->column('id'))->where(["status"=>[1,2]])->select(); Log::info("退票申请:".json_encode($orderItems->toArray(),JSON_UNESCAPED_UNICODE)); if(!$orderItems->isEmpty()){ foreach ($orderItems as $key=>$val){ $val->save(["status"=>4]); } Log::info("caigou:".InvoiceOrder::getLastSql()); } self::where(['invoiceCode'=>$invNo,'order_type'=>2])->save(["status"=>3]); } } }