statusAfterChanged)) { $this->status = $this->statusAfterChanged; } if(!empty($this->timeField)){ $timeFields = $this->timeField; $this->$timeFields = time(); } return $this->save(); } /** * 操作验证 * @throws AppException */ protected function operationValidate() { if (!empty($this->statusBeforeChange) && !in_array($this->status, $this->statusBeforeChange)) { throw new AppException($this->status_name . '的退款申请,无法执行' . $this->name . '操作'); } } protected function backWay() { if (!isset($this->backWay)) { $this->backWay = RefundBackWayService::getBackWayClass($this->refund_way_type); $this->backWay->setRefundApply($this); } return $this->backWay; } protected function setBackWay() { $this->backWay()->saveRelation(); } /*** * 执行操作操作 * @return bool * @throws AppException */ final public function execute() { $this->operationValidate(); //验证 $this->updateBefore(); //更新表之前 $result = $this->updateTable();//更新表 if (!$result) { throw new AppException('信息更新失败'); } $this->updateAfter();//更新表之后 $this->writeLog(); //写入售后协商记录表 $this->triggerRefundEvent(); //售后事件触发 $this->triggerEventAfter();//事件触发后 $this->sendMessage(); //发送通知 return $result; } /** * 发布监听 */ final protected function triggerRefundEvent() { $eventClass = $this->afterEventClass(); if (is_array($eventClass)) { foreach ($eventClass as $itemEvent) { if (!is_null($itemEvent) && ($itemEvent instanceof Event)) { event($itemEvent); } } } else { if (!is_null($eventClass) && ($eventClass instanceof Event)) { event($eventClass); } } } final public function setParams($request) { $this->params = $request; } final public function getParam($key) { return array_get($this->params, $key, ''); } final public function getParams() { return $this->params; } final public function getRequest() { // if (!isset($this->request)) { // $this->request = request(); // } return request(); } //对应的订单 final public function relatedPluginOrder() { if (!isset($this->refundOrderType)) { $this->refundOrderType = RefundOrderFactory::getInstance()->getRefundOrder($this->order, $this->port_type); } return $this->refundOrderType; } /** * 售后申请记录退款商品 * @param $refundGoods */ protected function createOrderGoodsRefundLog($refundGoods) { $order_goods_ids = array_column($refundGoods, 'id'); OrderGoods::whereIn('id', $order_goods_ids)->update(['refund_id' => $this->id]); foreach ($refundGoods as $goodsItem) { RefundGoodsLog::saveData($this,$goodsItem); } } /** * 更新订单商品表售后状态 */ protected function updateOrderGoodsRefundStatus() { //不是换货售后商品需要标识下退过款 if ($this->refund_type != self::REFUND_TYPE_EXCHANGE_GOODS) { //is_refund 字段现在作用只是标记下该商品售后过 $updateData['is_refund'] = DB::raw('is_refund + 1'); } $updateData['refund_id'] = 0; OrderGoods::where('refund_id', $this->id)->update($updateData); } protected function delRefundOrderGoodsLog() { RefundGoodsLog::where('refund_id', $this->id)->delete(); //更新订单商品表售后字段 OrderGoods::where('refund_id', $this->id)->update(['refund_id'=> 0]); } protected function cancelRefund() { return $this->order->cancelRefund(); } protected function closeOrder() { return $this->order->close(); } /** * @param $eventClass * @param mixed ...$parameter */ protected function afterEvent($eventClass, ...$parameter) { event(new $eventClass(...$parameter)); } }