在我的电子商务中,我已经实现了优惠券,并且可以使用,但是现在我引入了“优惠券第一订单”,但是不知道我是否正在以最好的方式检查它,因为它无法正常工作,我的查询无视此咨询。
如何检查coupon_tp
是否排在第一位,如果为真,如何检查用户是否为第一位?
public function verificaCupom($coupon){
$this->db->select("customer_id, id, value, percent, code, discount_tp, coupon_tp");
//check if is first order (not working)
$this->db->select("IF(ga845_cupons.coupon_tp = 'first', (SELECT customer_id FROM ga845_pedidos_view WHERE NOT EXISTS 'ga845_pedidos_view.customer_id = ga845_cupons.customer_id')) as primeira");
//check if coupon exist
$this->db->where('code', $coupon);
//check valid
$this->db->where('CURDATE() <= valid');
//check if coupon it's enable
$this->db->where('status', 0);
$this->db->limit("1");
$query = $this->db->get('ga845_cupons');
return $query->result();
}
答案 0 :(得分:0)
尝试在select()
函数中将第二个参数设置为false。
$this->db->select()
接受可选的第二个参数。如果将其设置为FALSE,则CodeIgniter不会尝试保护您的字段或表名。如果您需要复合的select语句,其中的字段自动转义可能会破坏它们,这将很有用。
$this->db->select("IF(ga845_cupons.coupon_tp = 'first', (SELECT customer_id FROM ga845_pedidos_view WHERE NOT EXISTS 'ga845_pedidos_view.customer_id = ga845_cupons.customer_id')) as primeira", false);
答案 1 :(得分:0)
我已经将代码调整到此波纹管,并且可以根据需要工作。
$this->db->select("IF(ga845_cupons.coupon_tp = 'first', (SELECT COUNT(`customers_id`) FROM `ga845_pedidos_view` WHERE `ga845_pedidos_view`.`customers_id` = `ga845_cupons`.`customers_id` ), coupon_tp) as first");
$this->db->having('first <= ' , 0);