hasOne(Orders::class,"id","order_id"); } public function approvalItems() { return $this->hasMany(ApprovalItems::class); } public function generateExpireTime() { //todo:change expire rule to be better return date("Y-m-d") . " 23:59:59"; } public function pass() { DB::beginTransaction(); try { foreach ($this->approvalItems as $approvalItem) { $updates = json_decode($approvalItem->updates, true); $belongs_type = "\\" . $approvalItem->belongs_type; $model = new $belongs_type(); if ($approvalItem->belongs_id) { $model->find($approvalItem->belongs_id)->update($updates); } else { $model->create($updates); } } if ($this->id) { $this->update([ "status" => self::STATUS_PASSED ]); } if ($this->type == Approval::TYPE_CHECKOUT) { //处理剩余款项的退款 //todo:实现退款流程 } if ($this->type == Approval::TYPE_ASSIGN) { $order = (new Orders())->find($this->order_id); event(new OrderAssigned($order)); } DB::commit(); return [ "status" => true ]; } catch (\Exception $exception) { DB::rollBack(); return [ "status" => false, "errorcode" => $exception->getCode(), "errormsg" => $exception->getMessage() ]; } } }