客户债务报告laravel 5.3

时间:2017-03-24 18:54:05

标签: laravel

我有带有优惠券表的laravel项目 这是代金券表的结构

      Schema::create('vouchers', function (Blueprint $table) {
        $table->increments('id');
        $table->string('voucher_number',25)->unique();
        $table->integer('voucher_dealer');
        $table->date('voucher_date');
        $table->integer('voucher_customer_id');
        $table->double('voucher_amount');
        $table->text('voucher_note');
        $table->integer('voucher_type');
        $table->integer('voucher_inserter');
        $table->timestamps();
        $table->softDeletes();   
    });

模型名称是凭证

现在,当我需要获得客户凭证时,我会使用这种关系

public function CustomerReportGet(Request $request) 
{
    $full = Voucher::where('voucher_customer_id','=',$request->customer_id)->sum('voucher_amount');
    if($request->from_date == '' and $request->to_date == '')
        $data = Voucher::where('voucher_customer_id','=',$request->customer_id)->get();
    elseif($request->from_date <> '' or $request->to_date <> '')
    {
        $data = Voucher::where('voucher_customer_id','=',$request->customer_id)->
                whereBetween('created_at',array($request->from_date,$request->to_date));
    }
    return array($full,$data);
}

我将它们作为刀片页面中的ajax请求 现在我的问题是,当我创建报告时 它应该是这样的.. 顾客ID 优惠券日期 凭证金额 客户余额直到凭证日期 我怎么能让laravel总是将voucher_amount加到刀片中的每个voucher_date中 谢谢

1 个答案:

答案 0 :(得分:1)

尝试以下方法:

public function CustomerReportGet(Request $request) 
{
    $full = Voucher::where('voucher_customer_id','=',$request->customer_id);
    if($request->from_date == '' and $request->to_date == '')
        $full->sum('voucher_amount')->get();
    elseif($request->from_date <> '' or $request->to_date <> '')
    {
                $full->whereBetween('created_at',array($request->from_date,$request->to_date))->sum('voucher_amount')->get();
    }


    return array($full,$data);
}