'date2', 'name' => '日期', 'field' => 'date', 'value' => [$sdate, $edate], 'options' => []], ['form_type' => 'text', 'name' => '订单编号', 'field' => 'm.sn', 'options' => []], ['form_type' => 'text', 'name' => '单据编号', 'field' => 'd.fee_src_sn', 'options' => []], [ 'form_type' =>'dialog', 'field' => 'm.customer_id', 'name' => '所属客户', 'options' => ['url' => 'customer/customer/dialog', 'query' => []] ]/*,[ 'form_type' =>'dialog', 'field' => 'region_id', 'name' => '销售组', 'options' => ['url' => 'customer/region/dialog', 'query' => ['layer' => 3]] ],*/ ], 'model'); if (Request::method() == 'POST') { $fields = []; foreach($search['forms']['field'] as $i => $field) { $fields[$field] = $search['forms']['search'][$i]; } $model = DB::table('customer_order_data as d') ->leftJoin('product', 'product.id', '=', 'd.product_id') ->leftJoin('customer_order as m', 'm.id', '=', 'd.order_id') ->leftJoin('customer as c', 'c.id', '=', 'm.customer_id') ->leftJoin('customer_cost_category as ccc', 'ccc.id', '=', 'd.fee_category_id') ->selectRaw(" m.sn, d.fee_src_sn, d.fee_src_type_id, Sum(d.money) as money, c.code as customer_code, c.name as customer_name, ccc.name as category_name, ".sql_year_month('l.audit_date', 'ts')." as [ym] ") ->whereRaw('d.fee_src_sn is not null') ->groupBy(DB::raw('c.code,c.name,ccc.name,m.sn,d.fee_src_sn,d.fee_src_type_id,'.sql_year_month('l.audit_date', 'ts'))); foreach ($search['where'] as $where) { if ($where['active']) { if ($where['field'] == 'date') { continue; } $model->search($where); } } $rows = $model->orderBy('m.id', 'asc') ->get()->toArray(); foreach($rows as &$row) { $money = abs($row['money']); $row['money'] = $money; } return $this->json($rows, true); } $header = [ 'table' => 'customer_cost', 'master_table' => 'customer_cost', 'buttons' => [], 'search_form' => $search, 'simple_search_form' => 0, ]; $header['left_buttons'] = [ ['name' => '导出', 'color' => 'default', 'icon' => 'fa-mail-forward', 'action' => 'export', 'display' => 1], ]; return $this->display([ 'search' => $search, 'header' => $header, ]); } }