group_order_goods as $item) { // 判断这件商品是否为企叮咚的商品 $attr = QiShangTongGoodsAttr::findOne(['goods_attr_id' => $form['data']['attr_id']]); if (!empty($attr)) { // 判断件数 $qGoods = QiShangTongGoods::findOne(['goods_id' => $attr->goods_id]); $specs = array_column($qGoods->content['goods']['spec'], 'qidingliang', 'spec_id'); if ($specs[$attr->third_spec_id] > $form['data']['num']) throw new \Exception("起订量 {$specs[$attr->third_spec_id]} 件起"); } } } /** * @param $params * @return array|void * @throws \Exception */ public function validBuyNum($params) { $return = [ 'status' => true, 'msg' => 'success' ]; $attrs = $params['attrs'] ?? []; if(empty($attrs)) return $return; try { $goods = []; foreach ($attrs as $attr_id => $num) { $attr = QiShangTongGoodsAttr::findOne(['goods_attr_id' => $attr_id]); if (!empty($attr)) { // 判断件数 $qGoods = QiShangTongGoods::findOne(['goods_id' => $attr->goods_id]); if (!empty($qGoods)) { if (empty($qGoods->can_sale) || (!empty($qGoods->content['goods']['can_sale']) && $qGoods->content['goods']['can_sale'] != 1)) throw new \Exception("当前商品不可售"); $specs = array_column($qGoods->content['goods']['spec'], 'qidingliang', 'spec_id'); if ($specs[$attr->third_spec_id] > $num) throw new \Exception("起订量 {$specs[$attr->third_spec_id]} 件起"); $tGoods = new OrderConfirmGoodsItemModel(); $tGoods->goods_id = $attr->third_goods_id; $tGoods->spec_id = $attr->third_spec_id; $tGoods->num = $num; $goods[] = $tGoods; } } } if (!empty($goods)) { // 企商通预览订单 $addr = UserAddress::getUserAddress($params['user_id'], $params['address_id'] ?? 0); if (!empty($addr)) { $is_d = true; $region = QiShangTongRegion::findOne(['local_id' => $addr['district_id']]); if (empty($region)) { $is_d = false; $region = QiShangTongRegion::findOne(['local_id' => $addr['city_id']]); } $contentModel = new OrderConfirmModel(); $contentModel->phone_mob = $addr['mobile']; $contentModel->region_name = "{$addr['province']}{$addr['city']}{$addr['district']}"; $contentModel->address = $addr['detail']; $contentModel->province = $region->province_id; // ID要相通 $contentModel->city = $region->city_id; // 直辖市可以传0,但是 区县/省市不能传0 $contentModel->area = $is_d ? $region->id : $region->district_id; $contentModel->consignee = $addr['name']; $contentModel->details = $goods; // 商品信息 $res = RequestHelper::send(new OrderConfirmRequest(), $contentModel, $params['mall_id']); if (is_string($res)) throw new \Exception($res); $return['extra'][$attr->goods_id]['shipping_fee'] = $res['shipping_fee']; } } } catch (\Exception $e) { $return = [ 'status' => false, 'msg' => $e->getMessage() ]; } return $return; } }