在 laravel 查询生成器中使用 OR

use OR in laravel query builder

我的table定义如下

**PURCHASE_PYAMENTS**

SELLER      MASTER_PAYMENT      BILL        COUNT_VB        PAYMENT_STATUS      REMAIN_PARTIAL_AMOUNT

abc         15000               0           0               1                   0   
xyz         14000               1           1               1                   14000
abc         15000               0           0               0                   5000

我需要 master_payment 列的 sum 用于特定 seller 两种情况:

  1. payment_status = 1count_vb = 0
  2. payment_status = 0remain_partial_amount > 0

如果上述任何条件成立,那么 master_payment 应该添加 sum 那么,我如何使用单个查询来实现它?。

我自己试了一下,结果只有一种情况,我的查询如下:

  $total_count_vb = DB::table('purchase_payments')
        ->where('seller',$seller_list)
        ->where('count_vb',0)
        ->where('payment_status',1)
        ->SUM('master_payment');

parameter grouping 使用 where()orWhere() 闭包:

Payment::where('seller', 'abc')->
       ->where(function ($q) {
           $q->where(function ($q) {
               $q->where('payment_status', 1)->where('count_vb', 0);
           })
           ->orWhere(function ($q) {
               $q->where('payment_status', 0)->where('remain_partial_amount', '>', 0);
           });
       });
       ->sum('master_payment');