diff --git a/app/Gdoo/Calendar/config.php b/app/Gdoo/Calendar/config.php index cfeb6fe6..cbeca0d9 100644 --- a/app/Gdoo/Calendar/config.php +++ b/app/Gdoo/Calendar/config.php @@ -28,9 +28,6 @@ return [ ], "delete" => [ "name" => "删除" - ], - "help" => [ - "name" => "帮助" ] ] ], diff --git a/app/Gdoo/Order/Controllers/ReportController.php b/app/Gdoo/Order/Controllers/ReportController.php index 00bb54f8..4b1a23d1 100644 --- a/app/Gdoo/Order/Controllers/ReportController.php +++ b/app/Gdoo/Order/Controllers/ReportController.php @@ -1190,8 +1190,8 @@ class ReportController extends DefaultController ')) ->selectRaw(' m.customer_id, - product_category.code as category_code, - product.code as product_code, + product_category.code category_code, + product.code product_code, customer.name customer_name, product.name product_name, product.spec product_spec, @@ -1224,8 +1224,8 @@ class ReportController extends DefaultController ')) ->selectRaw(' m.customer_id, - product_category.code as category_code, - product.code as product_code, + product_category.code category_code, + product.code product_code, customer.name customer_name, product.name product_name, product.spec product_spec, @@ -1237,7 +1237,7 @@ class ReportController extends DefaultController '.sql_month('m.invoice_dt').' [month] '); // 直营 - $cancel = DB::table('stock_direct_data as d') + $direct = DB::table('stock_direct_data as d') ->leftJoin('stock_direct as m', 'm.id', '=', 'd.direct_id') ->leftJoin('product', 'product.id', '=', 'd.product_id') ->leftJoin('product_category', 'product_category.id', '=', 'product.category_id') @@ -1259,8 +1259,8 @@ class ReportController extends DefaultController ->selectRaw(' m.customer_id, customer.name customer_name, - product_category.code as category_code, - product.code as product_code, + product_category.code category_code, + product.code product_code, product.name product_name, product.spec product_spec, d.product_id, @@ -1273,31 +1273,32 @@ class ReportController extends DefaultController // 客户圈权限 if ($selects['authorise']) { foreach ($selects['whereIn'] as $k => $v) { + $direct->whereIn($k, $v); $cancel->whereIn($k, $v); $delivery->whereIn($k, $v); } } if ($category_id) { + $direct->whereIn('product.category_id', $category); $delivery->whereIn('product.category_id', $category); $cancel->whereIn('product.category_id', $category); } - $rows = $cancel->unionAll($delivery) + $rows = $cancel->unionAll($delivery)->unionAll($direct) ->orderBy('category_code', 'ASC') ->get(); - if ($rows->count()) { - $single = []; - foreach ($rows as $v) { - if ($v['product_id'] > 0) { - $month = $v['month']; - $product_id = $v['product_id']; + $single = []; + foreach ($rows as $v) { + if ($v['product_id'] > 0) { + $month = $v['month']; + $product_id = $v['product_id']; - $single['product'][$product_id] = $v; - $single['category'][$product_id] = $v['category_id']; - $single['customer'][$v['customer_id']] = $v['customer_id']; - $single['all'][$product_id][$v['customer_id']] = $v['customer_id']; - $single['sum'][$product_id][$month][$v['customer_id']] = $v['customer_id']; - } + $single['product'][$product_id] = $v; + $single['category'][$product_id] = $v['category_id']; + $single['customer'][$v['customer_id']] = $v['customer_id']; + $single['all'][$product_id][$v['customer_id']] = $v['customer_id']; + $single['sum'][$product_id][$month][$v['customer_id']] = $v['customer_id']; + $single['sum_money'][$product_id][$month] += $v['money']; } } @@ -1324,80 +1325,173 @@ class ReportController extends DefaultController { $year = Request::get('year'); $product_id = Request::get('product_id'); - $query = select::head1(); + + // 筛选专用函数 + $selects = regionCustomer('customer'); $n = date("n", time()); if ($product_id > 0) { - $rows = DB::table('order_data as i') - ->leftJoin('order_type as t', 't.id', '=', 'i.type') - ->leftJoin('order as o', 'o.id', '=', 'i.order_id') - ->leftJoin('user as c', 'c.id', '=', 'o.client_id') - ->leftJoin('client', 'client.user_id', '=', 'c.id') - ->leftJoin('region as r', 'r.id', '=', 'c.city_id') - ->leftJoin('product as p', 'p.id', '=', 'i.product_id') - ->leftJoin('product_category as pc', 'pc.id', '=', 'p.category_id') - ->where('i.deleted', 0) - ->where('o.add_time', '>', 0) - ->where('p.id', $product_id) - ->whereRaw('FROM_UNIXTIME(o.add_time,"%Y")=?', [$year]) - //->whereRaw($sql, $params) - ->where('t.type', 1) - //->groupBy('month') - ->groupBy('o.client_id') - ->orderBy('pc.lft', 'ASC') - ->orderBy('p.sort', 'ASC') - ->selectRaw('r.name city_name,client.circle_id,o.client_id,c.nickname company_name,p.name product_name,p.spec product_spec,i.product_id,p.category_id,SUM(i.amount * i.price) money,SUM(i.amount) amount,FROM_UNIXTIME(o.add_time,"%Y") year,FROM_UNIXTIME(o.add_time,"%c") month, pc.name category_name'); - - if ($query['whereIn']) { - foreach ($query['whereIn'] as $key => $whereIn) { - if ($whereIn) { - $rows->whereIn($key, $whereIn); - } + // 发货 + $delivery = DB::table('stock_delivery_data as d') + ->leftJoin('stock_delivery as m', 'm.id', '=', 'd.delivery_id') + ->leftJoin('product', 'product.id', '=', 'd.product_id') + ->leftJoin('product_category', 'product_category.id', '=', 'product.category_id') + ->leftJoin('customer', 'customer.id', '=', 'm.customer_id') + ->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1') + ->whereRaw('year(m.invoice_dt)=?', [$year]) + ->groupBy(DB::raw(' + customer.name, + product.name, + product.spec, + product.category_id, + year(m.invoice_dt), + month(m.invoice_dt), + m.customer_id, + d.product_id, + product_category.code, + product.code, + customer.region_id + ')) + ->selectRaw(' + product_category.code category_code, + product.code, + m.customer_id, + customer.name customer_name, + product.name product_name, + product.spec product_spec, + d.product_id, + product.category_id, + sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money, + SUM(d.quantity) quantity, + year(m.invoice_dt) [year], + month(m.invoice_dt) [month], + customer.region_id + '); + // 退货 + $cancel = DB::table('stock_cancel_data as d') + ->leftJoin('stock_cancel as m', 'm.id', '=', 'd.cancel_id') + ->leftJoin('product', 'product.id', '=', 'd.product_id') + ->leftJoin('product_category', 'product_category.id', '=', 'product.category_id') + ->leftJoin('customer', 'customer.id', '=', 'm.customer_id') + ->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1') + ->whereRaw('year(m.invoice_dt)=?', [$year]) + ->groupBy(DB::raw(' + customer.name, + product.name, + product.spec, + product.category_id, + year(m.invoice_dt), + month(m.invoice_dt), + m.customer_id, + d.product_id, + product_category.code, + product.code, + customer.region_id + ')) + ->selectRaw(' + product_category.code category_code, + product.code, + m.customer_id, + customer.name customer_name, + product.name product_name, + product.spec product_spec, + d.product_id, + product.category_id, + sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money, + SUM(d.quantity) quantity, + year(m.invoice_dt) [year], + month(m.invoice_dt) [month], + customer.region_id + '); + // 直营 + $direct = DB::table('stock_direct_data as d') + ->leftJoin('stock_direct as m', 'm.id', '=', 'd.direct_id') + ->leftJoin('product', 'product.id', '=', 'd.product_id') + ->leftJoin('product_category', 'product_category.id', '=', 'product.category_id') + ->leftJoin('customer', 'customer.id', '=', 'm.customer_id') + ->whereRaw('d.product_id <> 20226 and isnull(product.product_type, 0) = 1') + ->whereRaw('year(m.invoice_dt)=?', [$year]) + ->groupBy(DB::raw(' + customer.name, + product.name, + product.spec, + product.category_id, + year(m.invoice_dt), + month(m.invoice_dt), + m.customer_id, + d.product_id, + product_category.code, + product.code, + customer.region_id + ')) + ->selectRaw(' + product_category.code category_code, + product.code, + m.customer_id, + customer.name customer_name, + product.name product_name, + product.spec product_spec, + d.product_id, + product.category_id, + sum(isnull(d.money, 0) - isnull(d.other_money, 0)) money, + SUM(d.quantity) quantity, + year(m.invoice_dt) [year], + month(m.invoice_dt) [month], + customer.region_id + '); + // 客户圈权限 + if ($selects['authorise']) { + foreach ($selects['whereIn'] as $k => $v) { + $delivery->whereIn($k, $v); + $direct->whereIn($k, $v); + $cancel->whereIn($k, $v); } } - $rows = $rows->get(); + $delivery->where('product.id', $product_id); + $cancel->where('product.id', $product_id); + $direct->where('product.id', $product_id); + + $rows = $cancel->unionAll($delivery)->unionAll($direct) + ->orderBy('category_code', 'ASC') + ->get(); - $circles = DB::table('customer_circle')->get()->pluck('name', 'id'); + $regions = DB::table('customer_region')->get()->pluck('name', 'id'); + $customers = []; - $single = array(); - foreach ($rows as $key => $value) { + $single = []; + foreach ($rows as $row) { //如何当前月存在数据 - $client_id = $value['client_id']; + $customer_id = $row['customer_id']; //客户编号公司名称 - $clients[$client_id] = array( - 'client_id' => $value['company_name'], - 'area' => $value['city_name'], - 'circle_name' => $circles[$value['circle_id']], - ); + $customers[$customer_id] = [ + 'customer_id' => $row['customer_name'], + 'region_name' => $regions[$row['region_id']], + ]; - if ($value['money'] > 0) { - $single['all'][$client_id] += $value['money']; - $single['cat'] = $value['category_name']; - $single['name'] = $value['product_name']; - $single['spec'] = $value['product_spec']; + if ($row['money'] > 0) { + $single['all'][$customer_id] += $row['money']; + $single['product_code'] = $row['product_code']; + $single['product_name'] = $row['product_name']; + $single['product_spec'] = $row['product_spec']; } - if ($value['month'] == $n) { + if ($row['month'] == $n) { //筛选本月没有数量的客户 - $notpurchase[$client_id] = $value; + $notpurchase[$customer_id] = $row; } } } arsort($single['all']); - return $this->display(array( + return $this->display([ 'single' => $single, - 'years' => $years, 'year' => $year, - 'year_id' => $year_id, - 'code_id' => $code_id, 'month' => $n, - 'clients' => $clients, + 'customers' => $customers, 'notpurchase'=> $notpurchase, - 'assess' => $assess, - )); + ]); } /** diff --git a/app/Gdoo/Order/views/report/client.blade.php b/app/Gdoo/Order/views/report/client.blade.php index 395f4003..0e040eff 100644 --- a/app/Gdoo/Order/views/report/client.blade.php +++ b/app/Gdoo/Order/views/report/client.blade.php @@ -1,7 +1,7 @@
-
{{$year_id}}年度发生交易客户数[{{count((array)$single['customer'])}}]
+
{{$year}}年单品客户数({{count((array)$single['customer'])}})
@@ -9,22 +9,26 @@
- @if(Auth::user()->role->code != 'c001') - @include('report/select') -   - @endif + @include('report/select') +   +   @@ -34,27 +38,51 @@ - - + + - + + + + @if($months) @foreach($months as $k => $v) @endforeach + @endif + @if($single['sum']) @foreach($single['sum'] as $k => $v) - - - + + + + + + + @if($months) @foreach($months as $v2) @endforeach + @endif + + + + + @if($months) + @foreach($months as $v2) + + @endforeach + @endif + + @endforeach + @endif
品类单品产品编码产品名称总销售家数合计{{$v}}月
{{$single['category'][$k]}}[查] {{$single['product'][$k]['product_name']}} - {{$single['product'][$k]['product_spec']}}{{sizeof($single['all'][$k])}}{{$single['product'][$k]['product_code']}}[查] {{$single['product'][$k]['product_name']}} - {{$single['product'][$k]['product_spec']}}销售客户数{{count((array)$single['all'][$k])}} {{:$sum = count((array)$v[$v2])}} - @if($sum > 0) {{$sum}} @else 0 @endif + @if($sum>0) {{$sum}} @else @endif
销售金额@number(array_sum((array)$single['sum_money'][$k]), 2) + @if($single['sum_money'][$k][$v2] > 0) @number($single['sum_money'][$k][$v2], 2) @else @endif +
\ No newline at end of file diff --git a/app/Gdoo/Order/views/report/clientdata.blade.php b/app/Gdoo/Order/views/report/clientdata.blade.php index 311f4f98..27841e1e 100644 --- a/app/Gdoo/Order/views/report/clientdata.blade.php +++ b/app/Gdoo/Order/views/report/clientdata.blade.php @@ -1,27 +1,25 @@
-
-
{{$single['cat']}} * ({{$single['name']}} - {{$single['spec']}}) - {{$year}}年度({{$month}}月)未进货经销商列表
+
+
{{$single['product_name']}} - {{$single['product_spec']}} - {{$year}}年{{$month}}月无数据的客户列表
- +
- - - + + - + - @if(count($clients)) + @if($customers) - @foreach($clients as $key => $value) + @foreach($customers as $key => $value) @if(empty($notpurchase[$key])) - - - - + + + @endif @@ -33,28 +31,24 @@
-
-
{{$single['cat']}} * ({{$single['name']}} - {{$single['spec']}}) - {{$year}}度年经销商销售分析
+
+
{{$single['product_name']}} - {{$single['product_spec']}} - {{$year}}年客户销售统计
-
序号区域客户圈序号销售组 客户名称单品
{{$i + 1}}{{$value['area']}}{{$value['circle_name']}}{{$value['client_id']}}{{$single['name']}} - {{$single['spec']}}{{$value['region_name']}}{{$value['customer_id']}}
+
- - - + + - - @if(count($single['all'])) + @if($single['all']) @foreach($single['all'] as $key => $value) - - - - + + diff --git a/app/Gdoo/Project/views/project/add.blade.php b/app/Gdoo/Project/views/project/add.blade.php index c817fc6a..3ff0f995 100644 --- a/app/Gdoo/Project/views/project/add.blade.php +++ b/app/Gdoo/Project/views/project/add.blade.php @@ -16,8 +16,8 @@ diff --git a/app/Gdoo/Project/views/project/edit.blade.php b/app/Gdoo/Project/views/project/edit.blade.php index 6e5edbad..7c34ff8b 100644 --- a/app/Gdoo/Project/views/project/edit.blade.php +++ b/app/Gdoo/Project/views/project/edit.blade.php @@ -16,8 +16,8 @@
序号区域客户圈序号销售组 客户名称单品 金额
{{$i + 1}}{{$clients[$key]['area']}}{{$clients[$key]['circle_name']}}{{$clients[$key]['client_id']}}{{$single['name']}} - {{$single['spec']}}{{$customers[$key]['region_name']}}{{$customers[$key]['customer_id']}} {{$value}}
项目权限
项目权限