getDefaultform($this->mall_id, $this->user_id); $form->attributes = Yii::$app->request->post(); $form['action'] = AppEnum::ACTION_PREVIEW; $info = (new OrderService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->preview($form); return $this->success('操作成功', $info); }catch (\Exception $e){ return $this->error($e->getMessage()); } } /** * 是否强制免运费 * @param $form * @return mixed */ protected function isForceFreeShipping($form) { // 社区团购 是否强制免运费 if (!$form->is_force_free_shipping && MallAddons::isInstall($this->mall_id, AddonsEnum::ADDONS_NAME_COMMUNITY) && (new SettingService())->isForceFreeShipping($this->mall_id)) { // 需要处理 // 判断是否为社区团购订单 // 这种判断仅限于定制创建的时候 if ($form->action == AppEnum::ACTION_CREATE && in_array($form->shipping_type, [ShippingTypeEnum::PICKUP, ShippingTypeEnum::MERCHANT_DISTRIBUTION]) && !empty($form->extra_info)) { $ext = json_decode($form->extra_info, true); if (empty($ext['head_id'])) { return $form; } } // 如果有安装社区团购 并且 $community_res = (new CommunityGoods())->orderPreviewAppendFields(['mall_id' => $this->mall_id, 'user_id' => $this->user_id, 'data' => [], 'params' => array_merge($form->data, ['type' => $form->type])]); $shipping_type = null; if (!empty($community_res['option_list']) && is_array($community_res['option_list'])) { $option_list = array_values(array_filter($community_res['option_list'], function ($val) { return $val['enable'] == StatusEnum::ENABLED; })); $shipping_type = $option_list[0]['key'] ?? null; } $shipping_type = $form->data['shipping_type'] ?? $shipping_type; // 如果前端没有传,那么就取默认第一个 $form->is_force_free_shipping = in_array($shipping_type, [ShippingTypeEnum::PICKUP]); } return $form; } /** * 创建订单 * @Author bing * @DateTime 2021-09-22 09:31:22 * @return void * @copyright: Copyright (c) 2020 广东七件事集团 */ public function actionCreate() { try { $orderFormLogic = new OrderFormLogic(); $form = $orderFormLogic->getDefaultform($this->mall_id, $this->user_id); $form->attributes = Yii::$app->request->post(); $form['action'] = AppEnum::ACTION_CREATE; // 初始化订单数据 $res = (new OrderService(['mall_id' => $this->mall_id, 'user_id' => $this->user_id]))->created($form); return $this->success('操作成功', $res); }catch (\Exception $e){ return $this->error($e->getMessage()); } } }