1], [['cart_id_list', 'attr_list', 'goods_id'], 'safe'], ]; return $rules; } public function afterValidate() { $this->address = $this->getAddressData(); } public function search() { if (!$this->validate()){ return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0], ]; } try { // 预生成订单号 $order_no = OrderNo::getOrderNo(OrderNo::ORDER_ALLIANCE_PURCHASE); cache()->set('delivery_order_no_' . get_user_id(), $order_no); } catch(\Exception $e) { return [ 'code' => 1, 'line' => $e->getLine(), 'msg' => $e->getMessage(), 'file' => $e->getFile(), ]; } $cartForm = new CartForm(); $cartForm->cart_id_list = $this->cart_id_list; $cartForm->attr_list = $this->attr_list; $cartForm->goods_id = $this->goods_id; $cartForm->saas_id = get_saas_user_id(); // $cartForm->store_id = get_store_id(); $cartList = $cartForm->search(); $express_price_total = 0; $goods_price_total = 0; $all_price_total = 0; $cloud_order_id = 0; foreach ($cartList['data'] as $_i => $_v){ $cartList['data'][$_i]['supplier_express_price_total'] = 0; foreach($_v['goods_list'] as $i => $v){ $supplier_id = $v['goods']['supplier_id']; foreach ($v['cart'] as $_c) { $in_rule = 0; $cartList['data'][$_i]['in_rule'] = $in_rule; } } if($this->address){ $form = new MerchantForm(); $form->setSaasStoreCloudId(); $form->order_id = 0; $form->type = 0; $form->is_pay = $this->is_pay; try{ $pre = $form->purchasePrePurchaseOrder($_v, $this->address); // var_dump($pre);die; if ((int)$pre['code'] !== 0) { throw new \Exception($pre['msg']); } } catch (\Exception $e){ return [ 'code' => 1, 'msg' => $e->getMessage(), ]; } if($pre && $pre['code'] == 0){ foreach ($pre['data'] as $gi => $gv) { $cloud_order_id = $gv['cloud_order_id']; foreach ($gv['goods_info'] as $goods_) { foreach ($goods_['attr'] as $attr_) { $attr_id = array_column($attr_['attr'], 'attr_id'); sort($attr_id); foreach ($cartList['data'] as $_i => &$_v){ foreach($_v['goods_list'] as $i => &$v){ foreach ($v['cart'] as $cartI => &$_c) { $cart_attr = json_decode($_c['attr'], true); sort($cart_attr); if (!array_diff($cart_attr, $attr_id)) { $_c['cart_price'] = sprintf("%.2f", ($attr_['price'] / $attr_['num'])); $_c['price'] = $attr_['price']; } } } } // } } $express_price_total += $gv['express_price']; $goods_price_total += $gv['goods_price']; $all_price_total += $gv['all_price']; $cartList['data'][$_i]['supplier_express_price_total'] += $gv['express_price']; } } } $cartList['data'][$_i]['pre'] = $pre; } return [ 'code' => 0, 'msg' => 'OOKK', 'data' => [ 'address' => $this->address, 'goods_list' => $cartList['data'], 'express_price_total' => sprintf('%.2f', $express_price_total), 'price_total' => $goods_price_total, 'pay_price' => $all_price_total, 'cloud_order_id' => $cloud_order_id ], ]; } }