'快递公司', 'express_no' => '快递单号', ]; } public function save() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; } $send_type = intval($this->send_type); $query = OrderRefund::find(); $order_refund = $query->where([ 'id' => $this->order_refund_id, 'user_id' => $this->user_id, ])->one(); if (!$order_refund) { return [ 'code' => 1, 'msg' => '售后订单不存在。', ]; } $order = Order::findOne($order_refund->order_id); $md_id = 0; if ($order) { $md_id = $order->md_id; } $agentFrontBind = AgentFrontBind::findOne(['md_id' => $md_id, 'is_delete' => 0]); $goods_list = OrderDetail::find()->where(['order_id' => $order_refund->order_id])->andWhere(['in', 'id', Json::decode($order_refund->order_detail_id)]) ->select('attr, goods_info, num')->asArray()->all(); $is_front_centralize = 0; $centralize_goods_id_arr = []; $goods_num_info = []; foreach ($goods_list as &$goods) { $goods_info = json_decode($goods['goods_info'], true); // if (intval($goods_info['is_front_centralize']) && $send_type) { // // } if (intval($goods_info['is_front_centralize'])) { $is_front_centralize = 1; if (!$send_type) { return [ 'code' => 1, 'msg' => '部分商品售后发货仅支持退回门店以及上门取送。', ]; } $detail_attr = json_decode($goods['attr'], true) ?? []; $detail_attr_id = array_column($detail_attr, 'attr_id'); // var_dump($goods['attr']);die; sort($detail_attr_id); $goods_attr = json_decode($goods_info['attr'], true); $goods_no = ''; foreach ($goods_attr as $goods_attr_item) { $goods_attr_id = array_column($goods_attr_item['attr_list'], 'attr_id'); sort($goods_attr_id); if (!array_diff($goods_attr_id, $detail_attr_id)) { $goods_no = $goods_attr_item['no']; } } $agentFrontCentralizeGoods = AgentFrontCentralizeGoods::findOne([ 'front_admin_id' => $agentFrontBind->front_agent_admin_id, 'goods_no' => $goods_no, 'is_delete' => 0 ]); if ($agentFrontCentralizeGoods) { $goods_num_info[] = [ 'num' => $goods['num'], 'centralize_goods_id' => $agentFrontCentralizeGoods->id, ]; array_push($centralize_goods_id_arr, $agentFrontCentralizeGoods->id); } } if (in_array($send_type, [1, 2]) && !intval($goods_info['is_front_centralize'])) { return [ 'code' => 1, 'msg' => '部分商品售后发货仅支持快递。', ]; } } if ($is_front_centralize) { $goodsRefundLog = AgentFrontCentralizeGoodsRefundLog::findOne(['refund_id' => $order_refund->id]) ?: new AgentFrontCentralizeGoodsRefundLog(); $goodsRefundLog->refund_type = $send_type; $goodsRefundLog->centralize_goods_id = implode(',', $centralize_goods_id_arr ?? []); $goodsRefundLog->md_id = $md_id; $goodsRefundLog->store_id = $order->store_id; $goodsRefundLog->refund_id = $order_refund->id; $goodsRefundLog->goods_num_info = json_encode($goods_num_info); if ($send_type == AgentFrontCentralizeGoodsRefundLog::REFUND_TYPE_VISIT) { if (empty($this->name) || empty($this->mobile) || empty($this->province_id) || empty($this->city_id) || empty($this->district_id) || empty($this->address) // || empty($this->latitude) || empty($this->longitude) ) { return [ 'code' => 1, 'msg' => '上门取货请填写寄件人信息。', ]; } $goodsRefundLog->latitude = $this->latitude ?? 0; $goodsRefundLog->longitude = $this->longitude ?? 0; $goodsRefundLog->name = $this->name; $goodsRefundLog->mobile = $this->mobile; $goodsRefundLog->province_id = $this->province_id; $goodsRefundLog->city_id = $this->city_id; $goodsRefundLog->district_id = $this->district_id; $goodsRefundLog->address = $this->address; $this->express = "仓库集采-上门取货"; $this->express_no = "-"; } if ($send_type == AgentFrontCentralizeGoodsRefundLog::REFUND_TYPE_BACK_MD) { // if (empty($this->back_md_pic)) { // return [ // 'code' => 1, // 'msg' => '退回门店请上传 送回门店照片。', // ]; // } $goodsRefundLog->back_md_pic = $this->back_md_pic; $this->express = "仓库集采-退回门店"; $this->express_no = "-"; } if (!$goodsRefundLog->save()) { return [ 'code' => 1, 'msg' => implode(';', array_values($order->firstErrors)) ]; }; } $order_refund->is_user_send = 1; $order_refund->user_send_express = $this->express; $order_refund->user_send_express_no = $this->express_no; $orderTransit = OrderTransit::findOne(['order_id' => $order_refund->order_id, 'is_delete' => 0, 'cancel_examine' => 1]); if ($orderTransit) { $cloud_order_id = $orderTransit->cloud_order_id; $merchant = new MerchantForm(); $merchant->order_id = $cloud_order_id; $merchant->user_send_express = $this->express; $merchant->user_send_express_no = $this->express_no; $merchant->order_type = 0; $merchant->pic_list = []; $r = $merchant->mchOrderRefundSend($order_refund->order_detail_id); if ($r['code']) { return $r; } } if ($order_refund->save()) { return [ 'code' => 0, 'msg' => '发货成功。', ]; } else { return [ 'code' => 1, 'msg' => $order_refund->errors[0] ]; } } }