Yii2 AR 查询数据,复杂点的where条件如何写呢?比如这个


SELECT * FROM `sdb_b2c_orders` WHERE 

    (pay_status='1' AND ship_status='0') 

 OR 

    (pay_status='0' AND payment='-1' AND ship_status='0')

    

Yii2的model 如果写出这样的过滤规则呢??
orWhere() andWhere()方法也无法在OR () 括号里面 像上面嵌套and

偶然的你
浏览 1633回答 2
2回答

慕森王

$orders = Orders::find()->filterWhere([    'pay_status' => 1,    'ship_status' => 0])->orFilterWhere([    'pay_status' => 0,    'payment' => 1,    'ship_status' => 0])->all();

人到中年有点甜

$orders = Orders::find()->where([    'AND',    ['pay_status' => 1],    ['ship_status' => 0]])->orWhere([    'AND',    ['pay_status' => 0],    ['payment' => 1],    ['ship_status' => 0]])->all();
打开App,查看更多内容
随时随地看视频慕课网APP