联系官方销售客服

1835022288

028-61286886

开发框架 版主:迅睿框架研发组
订单支付后,商品库存不减少,修改
类型:迅睿CMS 更新时间:2023-05-11 17:06:34


买了个插件,订单支付后,商品库存不减少,是不是代码有错误呢,有没有大神帮忙修改下。

 // 扣除库存
        list($a, $b, $c, $d, $e, $f) = explode('-', $paylog['mid']);
        $num = intval($d);

        $module = \Phpcmf\Service::L('cache')->get('module-'.$siteid.'-'.$this->mid);
        if (!isset($module['field']['price']) || !$module['field']['price']) {
            return;
        }

        $field = $module['field']['price'];
        if (!in_array($field['fieldtype'], ['Pay', 'Pays'])) {
            return;
        }

        if ($field['fieldtype'] == 'Pays') {
            // 多规格
            $data['price_sku'] = dr_string2array($data['price_sku']);
            if (!$sku && $data['price_sku']) {
                return;
            } elseif (!isset($data['price_sku']['value'][$sku]) || !$data['price_sku']['value'][$sku]) {
                return;
            }

            $data['price_sku']['value'][$sku]['quantity'] = max(0, $data['price_sku']['value'][$sku]['quantity'] - $num);
            $this->db->table($siteid.'_'.$this->mid)->where('id', $id)->update([
                'price_sku' => dr_array2string($data['price_sku']),
                'price_quantity' => max(0, (int)$data['price_quantity'] - $num)
            ]);
        } else {
            // 单规格
            $this->db->table($siteid.'_'.$this->mid)->where('id', $id)->update([
                'price_quantity' => max(0, (int)$data['price_quantity'] - $num)
            ]);

        }