find(['id' => $info['id']], ['col' => 'id,name,pic,cate_id,channel_id,cate_parent_id,type,have_vip']); if (!$source) { Dever::error('资源不存在'); } if ($this->set['id'] != $source['cate_id']) { Dever::error('资源不存在'); } //$detail = Dever::load(\Api\Lib\Sku::class)->getList(['info_id' => $source['id']], $info['sku_id'], 'psource'); $detail = Dever::load(\Api\Lib\Sku::class)->getInfo(['id' => $info['sku_id'], 'info_id' => $source['id']], 'psource'); if (!$detail) { Dever::error('规格不存在'); } $detail = Dever::load(\Psource\Lib\Price::class)->get($detail, $this->set, $info['num']); $have = Dever::load(\Psource\Lib\Price::class)->getHave($source); if ($have['status'] != 1) { Dever::error('专享资源无法购买'); } if (!$detail['pic']) { $source['pic'] = explode(',', $source['pic']); $detail['pic'] = $source['pic'][0]; } $this->detail[] = [ 'uid' => $this->place->uid, 'source_id' => $source['id'], 'source_type' => $source['type'], 'sku_id' => $detail['id'], 'scope' => $detail['scope'], 'name' => $source['name'], 'sku_name' => $detail['name'], 'pic' => $detail['pic'], 'cash' => Dever::number($detail['price']), 'cash_text' => $detail['price_text'], 'total_cash' => $detail['total_price'], 'pay_cash' => $detail['total_price'], 'num' => intval($detail['buy_num']), 'unum' => $detail['unum'], 'stock' => $detail['stock'], 'promotion' => $detail['promotion'], 'promotion_text' => $detail['promotion_text'], ]; if ($source['type'] == 1) { # 实物,如果有快递发货 $this->order['deliver_type'] = 1; # 0是销售渠道配送,1是平台配送 $this->order['method'] = 1; # 1是需要填写地址,2是不需要 $this->order['is_address'] = 1; if ($detail['stock'] && $detail['stock']['list'] && empty($this->order['method_list'])) { # 如果有店铺配送 $this->order['method_list'] = $detail['stock']['list']; $this->order['method'] = $detail['stock']['value']; $this->order['is_address'] = $detail['stock']['address']; if ($this->order['method'] == 0 && $this->order['is_address'] == 2) { # 自提,获取店铺地址 $this->order['sales_address'] = Dever::load(\Psales\Lib\Info::class)->getInfo($this->order['sales_type'], $this->order['sales_id']); } } } if (count($this->detail) < 3) { $this->order['name'][$source['id']] = $source['name']; } $this->order['cash'] += $detail['price'] * $detail['buy_num']; $this->order['num'] += $detail['buy_num']; } # 验证库存 protected function check() { if (isset($this->order['deliver_type']) && $this->order['deliver_type'] == 1 && $this->order['is_address'] == 1 && !$this->order['address_id']) { Dever::error('您还未填写收货地址'); } foreach ($this->detail as $v) { $stock = Dever::load(\Pstock\Lib\Info::class)->yue($v['source_id'], $v['sku_id']); if ($stock['num'] >= 0) { if ($stock['num'] < $v['num']) { Dever::error($v['name'] . '[' . $v['sku_name'] . ']库存不足'); } else { $state = Dever::load(\Pstock\Lib\Info::class)->sell($this->order, $v['source_id'], $v['sku_id'], $v['num'], '订单号:' . $this->order['order_num']); if (!$state) { Dever::error('库存不足'); } } } } if ($this->order['method'] == 0) { $this->order['method'] = 2; if ($this->order['is_address'] == 2) { $this->order['method'] = 3; } } } }