0 AND isnull(d.use_close, 0) = 0"; } /** * 获取为使用的促销id * */ public static function getSaleOrderSelectDetailSql() { return " SELECT isnull(temp.wf_num, 0) * isnull(temp.weight, 0) AS total_weight, temp.* FROM ( SELECT isnull(d.delivery_quantity, 0) AS quantity, isnull(sdd.quantity, 0) AS yf_num, isnull(sdd.bs, 0) AS yf_bs, isnull(d.delivery_quantity, 0) - isnull(sdd.quantity, 0) AS wf_num, isnull(e.ky_num, 0) AS ky_num, d.product_id, d.sale_id, d.sale_data_id, d.type_id, d.type_id_name, d.other_money, d.price, d.money, m.sn AS sale_sn, CASE WHEN (isnull(d.type_id, 0) = 2) THEN '1' ELSE '0' END AS is_gift, d.batch_sn, d.batch_date, d.fee_data_id, d.fee_src_id, d.fee_src_type_id, d.fee_src_sn, d.fee_category_id, d.fee_category_id_name, d.promotion_sn, d.promotion_data_id, d.product_name, d.product_spec, d.product_code, d.product_unit, d.product_barcode, d.material_type, d.weight FROM (".static::getSaleOrderDataSql().") d LEFT JOIN customer_order m ON d.order_id = m.id LEFT JOIN (SELECT sum(isnull(quantity, 0)) AS quantity, count(*) AS bs, product_id, sale_data_id FROM stock_delivery_data GROUP BY sale_data_id, product_id ) sdd ON d.sale_data_id = sdd.sale_data_id LEFT JOIN (SELECT product_id, sum(isnull(ky_num, 0)) AS ky_num FROM (".StockService::getStockSelectSql().") ss WHERE (warehouse_name like '%成品%' OR warehouse_code = '07') AND warehouse_code <> '25' GROUP BY product_id ) e ON d.product_id = e.product_id WHERE isnull(d.use_close, 0) = 0 AND (isnull(d.is_allocate, 0) = 0 OR (isnull(d.is_allocate, 0) = 1 AND isnull(d.material_type, 0) > 0)) ) temp WHERE isnull(temp.wf_num, 0) > 0 OR (isnull(temp.yf_bs, 0) = 0 AND temp.product_code like '99%')"; } /** * 获取为使用的促销id * */ public static function getSaleOrderSelectDetailReqSql() { return " SELECT isnull(temp.wf_num, 0) * isnull(temp.weight, 0) AS total_weight, temp.quantity, temp.yf_num, temp.yf_bs, temp.wf_num, temp.ky_num, temp.product_id, temp.sale_id, temp.sale_data_id, temp.type_id, temp.type_id_name, temp.other_money, temp.price, temp.money, temp.sale_sn, temp.is_gift, temp.batch_sn, temp.batch_date, temp.fee_data_id, temp.fee_src_id, temp.fee_src_type_id, temp.fee_src_sn, temp.fee_category_id, temp.fee_category_id_name, temp.promotion_sn, temp.promotion_data_id, temp.product_name, temp.product_spec, temp.product_code, temp.product_unit, temp.product_barcode, temp.product_type, temp.material_type, temp.weight FROM (SELECT isnull(d.delivery_quantity, 0) AS quantity, isnull(sdd.quantity, 0) AS yf_num, isnull(sdd.bs, 0) AS yf_bs, isnull(d.delivery_quantity, 0) - isnull(sdd.quantity, 0) AS wf_num, isnull(e.ky_num, 0) AS ky_num, d.product_id, d.sale_id, d.sale_data_id, d.type_id, d.type_id_name, d.other_money, d.price, d.money, m.sn AS sale_sn, CASE WHEN (isnull(d.type_id, 0) = 2) THEN '1' ELSE '0' END AS is_gift, d.batch_sn, d.batch_date, d.fee_data_id, d.fee_src_id, d.fee_src_type_id, d.fee_src_sn, d.fee_category_id, d.fee_category_id_name, d.promotion_sn, d.promotion_data_id, d.product_name, d.product_spec, d.product_code, d.product_unit, d.product_barcode, d.product_type, d.material_type, d.weight FROM (".static::getSaleOrderDataSql().") d LEFT JOIN customer_order m ON d.order_id = m.id LEFT JOIN (SELECT sum(isnull(quantity, 0)) AS quantity, count(*) AS bs, product_id, sale_data_id FROM stock_allocation_data GROUP BY sale_data_id, product_id ) sdd ON d.sale_data_id = sdd.sale_data_id LEFT JOIN (SELECT product_id, sum(isnull(ky_num, (0)::numeric)) AS ky_num FROM (".StockService::getStockSelectSql().") ss WHERE (warehouse_name like '%成品%') AND warehouse_code <> '25' GROUP BY product_id ) e ON d.product_id = e.product_id WHERE isnull(d.use_close, 0) = 0 AND isnull(d.is_allocate, 0) = 1 ) temp WHERE isnull(temp.wf_num, 0) > 0"; } /** * 获取为使用的促销id * */ public static function getSampleSelectDetailSql() { return " SELECT temp.quantity, temp.yc_num, temp.wc_num, temp.ky_num, temp.product_id, temp.sample_id, temp.sample_data_id, temp.price, temp.money, temp.sample_sn, temp.use_close, isnull(p.weight, 0) AS weight, p.name AS product_name, p.code AS product_code, pc.code AS category_code, p.spec AS product_spec, pu.name AS product_unit, isnull(temp.wc_num, 0) * isnull(p.weight, 0) AS total_weight FROM (SELECT isnull(d.quantity, 0) AS quantity, isnull(srd.quantity, 0) AS yc_num, isnull(d.quantity, 0) - isnull(srd.quantity, 0) AS wc_num, isnull(e.ky_num, 0) AS ky_num, d.product_id, d.sample_id, d.id AS sample_data_id, d.price, d.money, m.sn AS sample_sn, d.use_close FROM sample_apply_data d LEFT JOIN sample_apply m ON m.id = d.sample_id LEFT JOIN (SELECT sum(isnull(quantity, 0)) AS quantity,product_id,sample_data_id FROM stock_record09_data WHERE sample_data_id <> 0 GROUP BY sample_data_id, product_id ) srd ON d.id = srd.sample_data_id LEFT JOIN (SELECT product_id,sum(isnull(ky_num, 0)) AS ky_num FROM (".StockService::getStockSelectSql().") ss GROUP BY product_id ) e ON d.product_id = e.product_id WHERE m.status = 1 ) temp LEFT JOIN product p ON temp.product_id = p.id LEFT JOIN product_unit pu ON p.unit_id = pu.id LEFT JOIN product_category pc ON pc.id = p.category_id WHERE isnull(temp.wc_num, 0) > 0"; } }