getDefaultform($this->mall_id, $this->user_id); $form->attributes = Yii::$app->request->post(); $form['action'] = AppEnum::ACTION_PREVIEW; !empty($form->shipping_type) && $form->shipping_type = ShippingTypeEnum::LOGISTICS; // 初始化订单数据 $orderInitDataLogic = new OrderInitDataLogic(); $form = $orderInitDataLogic->execute($form, $form->type); if ($form === false) { return $this->error($orderInitDataLogic->getError()); } // 购买限制验证 $orderLimitLogic = new OrderLimitLogic(); $form = $orderLimitLogic->run($form); if ($form === false) { return $this->error($orderLimitLogic->getError()); } // 获取收货地址 $address_info = UserAddress::getUserAddress($this->user_id, $form->address_id); $form->address_id = $address_info['id'] ?? 0; // 营销减免活动 $orderMarketingLogic = new OrderMarketingLogic(); $form = $orderMarketingLogic->run($form); if ($form === false) { return $this->error($orderMarketingLogic->getError()); } // 聚合供应链处理 $service = new ChainOrderService(['mall_id' => $this->mall_id]); try { $form = $service->createBeforeCheck($form); } catch (Exception $e) { return $this->error($e->getMessage()); } $group_order_goods = array_values($form['group_order_goods']); $marketing = $form['marketing']; $pay_type_list = Yii::$app->services->pay->getEnablePayment($this->mall_id, $this->platform); $shipping_type_list = ShippingTypeEnum::getMap(); $info = compact('group_order_goods', 'marketing', 'address_info', 'pay_type_list', 'shipping_type_list'); $info['total_pay_money'] = '¥' . $form['total_pay_money']; $info['is_address'] = $form['is_address'] ?? 0; return $this->success('操作成功', $info); } /** * 创建订单 * * @return string */ public function actionCreate() { $orderFormLogic = new OrderFormLogic(); $form = $orderFormLogic->getDefaultform($this->mall_id, $this->user_id); $form->attributes = Yii::$app->request->post(); $form['action'] = AppEnum::ACTION_CREATE; // 初始化订单数据 $orderInitDataLogic = new OrderInitDataLogic(); $form = $orderInitDataLogic->execute($form, $form->type); if ($form === false) { return $this->error($orderInitDataLogic->getError()); } // 购买限制验证 $orderLimitLogic = new OrderLimitLogic(); $form = $orderLimitLogic->run($form); if ($form === false) { return $this->error($orderLimitLogic->getError()); } // 营销减免活动 $orderMarketingLogic = new OrderMarketingLogic(); $form = $orderMarketingLogic->run($form, true); if ($form === false) { return $this->error($orderMarketingLogic->getError()); } // 聚合供应链处理 $service = new ChainOrderService(['mall_id' => $this->mall_id]); try { $form = $service->createBeforeCheck($form, true); } catch (Exception $e) { return $this->error($e->getMessage()); } $res = Order::createOrder($form); if ($res === false) { return $this->error(Order::getStaticError()); } return $this->success('操作成功', $res); } /** * 加载提交售后订单数据 * * @return string */ public function actionToRefundSubmit() { $params = $this->request->get(); $res = Yii::$app->services->validate->validate($params, [ [['order_detail_id'], 'required'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $select = 'id,order_id,goods_name,sign_id,goods_id,goods_attr_name,goods_attr_id,price,num,pic_url,goods_price,order_status,marketing_type,extra_info,adjust_money'; $order_detail = OrderDetail::getOne([['id' => $params['order_detail_id']], 'user_id' => $this->user_id, 'mall_id' => $this->mall_id], 1, [], false, $select); if (empty($order_detail)) return $this->error('订单不存在'); $order = MallOrder::find()->where(['id' => $order_detail['order_id']])->select('id, order_no, shipping_money, order_source')->one(); if ($order->order_source != StarChainEnum::PLUGIN_SIGN) return $this->error('该订单不是聚合供应链订单'); // 公共调用 $order_detail = GlobalInvoke::exec(GlobalInvoke::ORDER_REFUND_SUBMIT, $this->mall_id, [ 'order_detail' => $order_detail, 'mall_id' => $this->mall_id, ]) ?: $order_detail; // 价格等于商品价格加上修改价格 $order_detail['goods_price'] = round($order_detail['goods_price'] + $order_detail['adjust_money'], 2); $data['goods_info'] = $order_detail; $feedback_type = RefundTypeEnum::getRefundMap(); $data['feedback_type'] = []; if (in_array($order_detail['order_status'], [OrderStatusEnum::PAY])) { // 待发货 $data['feedback_type'][] = $feedback_type[RefundTypeEnum::MONEY]; } if (in_array($order_detail['order_status'], [OrderStatusEnum::SHIPMENTS,OrderStatusEnum::SING])) { // 已发货,已收货 // $data['feedback_type'][] = $feedback_type[RefundTypeEnum::ONLY_MONEY]; $data['feedback_type'][] = $feedback_type[RefundTypeEnum::MONEY_AND_PRODUCT]; $data['feedback_type'][] = $feedback_type[RefundTypeEnum::EXCHANGE_GOODS]; $data['feedback_type'][] = $feedback_type[RefundTypeEnum::ONLY_MONEY]; } // 待发货添加邮费 if ($order_detail['order_status'] == OrderStatusEnum::PAY) { $data['goods_info']['goods_price'] = bcadd($order_detail['goods_price'], $order->shipping_money, 2); } $data['order_status'] = $order_detail['order_status']; return $this->success('操作成功', $data); } /** * 提交售后数据 * * @return string */ public function actionDoRefundSubmit() { $params = $this->request->post(); $res = Yii::$app->services->validate->validate($params, [ [['order_detail_id', 'reason_id', 'type', 'remark'], 'required'], [['shipping_status', 'pic_list', 'reason', 'refund_price', 'remark', 'type'], 'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $pic_list = Json::decode($params['pic_list']); if (count($pic_list) > 4) return $this->error('上传图片不能超过4张'); $params['user_id'] = $this->user_id; $params['mall_id'] = $this->mall_id; $where = [ ['=', 'order_detail_id', $params['order_detail_id']], ['=', 'user_id', $this->user_id], ['=', 'mall_id', $this->mall_id], ['>', 'step_status', 0], ['<>', 'refund_status', RefundStatusEnum::REVOKE] ]; $order_refund_model = OrderRefund::getOne($where, true); if ($order_refund_model) return $this->error('该订单商品已经申请过售后'); $refund_service = new RefundService(['mall_id' => $this->mall_id]); $res = $refund_service->doRefund($params); if ($res === false) return $this->error($refund_service->error); return $this->success('操作成功', ['id' => $res->id]); } /** * 聚合供应链售后上传售后截图 * * @return void */ public function actionUpload() { // 走主商城 return $this->error('功能开发中'); } /** * 填写物流单号 * * @return void */ public function actionRefundSend() { // 走主商城 return $this->error('功能开发中'); } /** * 物流编号 * * @return void */ public function actionExpressList() { // 走主商城 return $this->error('功能开发中'); } }