|
@@ -5,6 +5,7 @@ namespace App\Service;
|
|
use App\Model\BasicType;
|
|
use App\Model\BasicType;
|
|
use App\Model\BasicTypeAllUse;
|
|
use App\Model\BasicTypeAllUse;
|
|
use App\Model\Customer;
|
|
use App\Model\Customer;
|
|
|
|
+use App\Model\CustomerPerFormance;
|
|
use App\Model\CustomerReport;
|
|
use App\Model\CustomerReport;
|
|
use App\Model\CustomerReportDepart;
|
|
use App\Model\CustomerReportDepart;
|
|
use App\Model\Depart;
|
|
use App\Model\Depart;
|
|
@@ -15,6 +16,7 @@ use App\Model\InOutRecord;
|
|
use App\Model\InvoiceOrder;
|
|
use App\Model\InvoiceOrder;
|
|
use App\Model\InvoiceOrderInfo;
|
|
use App\Model\InvoiceOrderInfo;
|
|
use App\Model\LastJc;
|
|
use App\Model\LastJc;
|
|
|
|
+use App\Model\MonthlyPerFormance;
|
|
use App\Model\Product;
|
|
use App\Model\Product;
|
|
use App\Model\ProductAdjustment;
|
|
use App\Model\ProductAdjustment;
|
|
use App\Model\ProductCategory;
|
|
use App\Model\ProductCategory;
|
|
@@ -24,6 +26,7 @@ use App\Model\ReturnExchangeOrder;
|
|
use App\Model\ReturnExchangeOrderProductInfo;
|
|
use App\Model\ReturnExchangeOrderProductInfo;
|
|
use App\Model\SalesOrder;
|
|
use App\Model\SalesOrder;
|
|
use App\Model\SalesOrderProductInfo;
|
|
use App\Model\SalesOrderProductInfo;
|
|
|
|
+use App\Model\SalesOrderReport;
|
|
use App\Model\SeeRange;
|
|
use App\Model\SeeRange;
|
|
use App\Model\Setting;
|
|
use App\Model\Setting;
|
|
use Carbon\Carbon;
|
|
use Carbon\Carbon;
|
|
@@ -1899,6 +1902,12 @@ class StatisticsService extends Service
|
|
return $adjustedData;
|
|
return $adjustedData;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private function aboutTime($return){
|
|
|
|
+ $day = $this->returnDays($return);
|
|
|
|
+ if($day > 60) return [false, '查询时间仅支持范围区间在两月(60天)内'];
|
|
|
|
+ return [true ,''];
|
|
|
|
+ }
|
|
|
|
+
|
|
//改装 客户模板 t9改装 不是分配的客户 是所有的 =》 点击省 展示市 只有这个有产品
|
|
//改装 客户模板 t9改装 不是分配的客户 是所有的 =》 点击省 展示市 只有这个有产品
|
|
//分社 客户模板 t9改装 不是分配的客户 是所有的 =》 点击省 展示分社
|
|
//分社 客户模板 t9改装 不是分配的客户 是所有的 =》 点击省 展示分社
|
|
//加盟 客户模板 t9分社 不是分配的客户 是所有的 =》 点击省 展示市
|
|
//加盟 客户模板 t9分社 不是分配的客户 是所有的 =》 点击省 展示市
|
|
@@ -1906,6 +1915,8 @@ class StatisticsService extends Service
|
|
public function customerReportStepOfFirst($data, $user){
|
|
public function customerReportStepOfFirst($data, $user){
|
|
if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
$return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
$return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ list($status, $msg) = $this->aboutTime($return);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
$type = $data['type'];
|
|
$type = $data['type'];
|
|
$result = [];
|
|
$result = [];
|
|
@@ -2253,6 +2264,8 @@ class StatisticsService extends Service
|
|
public function customerReportStepOfSecond($data, $user){
|
|
public function customerReportStepOfSecond($data, $user){
|
|
if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
$return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
$return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ list($status, $msg) = $this->aboutTime($return);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
if(empty($data['value'])) return [false, 'value不能为空'];
|
|
if(empty($data['value'])) return [false, 'value不能为空'];
|
|
$type = $data['type'];
|
|
$type = $data['type'];
|
|
@@ -2564,11 +2577,12 @@ class StatisticsService extends Service
|
|
public function customerReportStepOfThird($data, $user){
|
|
public function customerReportStepOfThird($data, $user){
|
|
if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
$return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
$return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ list($status, $msg) = $this->aboutTime($return);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
if(empty($data['value'])) return [false, 'value不能为空'];
|
|
if(empty($data['value'])) return [false, 'value不能为空'];
|
|
if(empty($data['value2'])) return [false, 'value2不能为空'];
|
|
if(empty($data['value2'])) return [false, 'value2不能为空'];
|
|
$type = $data['type'];
|
|
$type = $data['type'];
|
|
- $result = [];
|
|
|
|
if($type == 1){
|
|
if($type == 1){
|
|
$result = $this->customerReportStepThirdForDetail($return,$data,$type);
|
|
$result = $this->customerReportStepThirdForDetail($return,$data,$type);
|
|
}elseif ($type == 2){
|
|
}elseif ($type == 2){
|
|
@@ -2794,4 +2808,1109 @@ class StatisticsService extends Service
|
|
|
|
|
|
return $customer;
|
|
return $customer;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ //门店零售:统计各个门店所有的订单总金额
|
|
|
|
+ //私域营销:统计T9品牌中心和杭州旗舰店的营销部部门下所有的人员的线下订单成交金额的总计
|
|
|
|
+ //线上销售:来自T9品牌中心所有的线上订单的合同金额总计
|
|
|
|
+ //门店业绩:来自分社采购单转成的订单的合同金额汇总
|
|
|
|
+ //客资业绩:导入的数据
|
|
|
|
+ public function saleReportStepOfFirst($data,$user){
|
|
|
|
+ if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ list($status, $msg) = $this->aboutTime($return);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+ $result = $this->saleReportStepOfFirstStart($return,$user);
|
|
|
|
+
|
|
|
|
+ return [true, ['list' => $result]];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfFirstStart($time,$user){
|
|
|
|
+ $result = $type = [];
|
|
|
|
+ foreach (SalesOrderReport::$all_list as $key => $value){
|
|
|
|
+ $result[] = [
|
|
|
|
+ 'label' => $value,
|
|
|
|
+ 'value' => $key,
|
|
|
|
+ 'all' => ""
|
|
|
|
+ ];
|
|
|
|
+ $type[$key] = 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $setting = Setting::where('setting_name','bt_top_depart_id')->first();
|
|
|
|
+ $bt_top_depart_id = $setting['setting_value'] ?? [];
|
|
|
|
+ $bt_top_depart_id = json_decode($bt_top_depart_id,true);
|
|
|
|
+
|
|
|
|
+ $id = [];
|
|
|
|
+ $depart_list = Depart::where('del_time',0)->select('id','parent_id','title')->get()->toArray();
|
|
|
|
+ foreach ($depart_list as $value){
|
|
|
|
+ if(in_array($value['parent_id'], $bt_top_depart_id) && $value['title'] == "营销部"){
|
|
|
|
+ $id[] = $value['id'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查找所有部门id
|
|
|
|
+ $all_depart_id = [];
|
|
|
|
+ foreach ($id as $value){
|
|
|
|
+ $childIds = $this->findChildIds($value, $depart_list);
|
|
|
|
+ $all_depart_id_tmp = array_merge($childIds, [$value]);
|
|
|
|
+ $all_depart_id = array_merge($all_depart_id, $all_depart_id_tmp);
|
|
|
|
+ }
|
|
|
|
+ // 获取部门下的人
|
|
|
|
+ $employee = EmployeeDepartPermission::whereIn('depart_id', $all_depart_id)
|
|
|
|
+ ->select('employee_id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $employee = array_unique(array_column($employee,'employee_id'));
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
|
+
|
|
|
|
+ foreach ($list as $value){
|
|
|
|
+ //门店零售
|
|
|
|
+ $type[SalesOrderReport::type_one] = bcadd($type[SalesOrderReport::type_one], $value['contract_fee'],2);
|
|
|
|
+ //私域营销
|
|
|
|
+ $bool = in_array($value['top_depart_id'], $bt_top_depart_id);
|
|
|
|
+ if($bool && in_array($value['crt_id'], $employee) && $value['model_type'] == SalesOrder::Model_type_one) $type[SalesOrderReport::type_two] = bcadd($type[SalesOrderReport::type_two], $value['contract_fee'],2);
|
|
|
|
+ //线上销售
|
|
|
|
+ if($value['top_depart_id'] == $head && $value['model_type'] == SalesOrder::Model_type_four) $type[SalesOrderReport::type_three] = bcadd($type[SalesOrderReport::type_three], $value['contract_fee'],2);
|
|
|
|
+ //门店业绩
|
|
|
|
+ if($value['from_top_depart_id'] > 0 && $value['model_type'] == SalesOrder::Model_type_two) $type[SalesOrderReport::type_four] = bcadd($type[SalesOrderReport::type_four], $value['contract_fee'],2);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //客资业绩
|
|
|
|
+ $start_time = strtotime(date("Y-m-01 00:00:00", $start));
|
|
|
|
+ $type_five = CustomerPerFormance::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start_time)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->select(DB::raw('sum(current_month_payment) as current_month_payment'))
|
|
|
|
+ ->first()->toArray();
|
|
|
|
+ $type[SalesOrderReport::type_five] = $type_five['current_month_payment'] ?? 0;
|
|
|
|
+
|
|
|
|
+ foreach ($result as $key => $value){
|
|
|
|
+ if(isset($type[$value['value']])){
|
|
|
|
+ $result[$key]['all'] = $type[$value['value']];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function saleReportStepOfSecond($data, $user){
|
|
|
|
+ if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ list($status, $msg) = $this->aboutTime($return);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+ if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
|
|
+ $type = $data['type'];
|
|
|
|
+ if($type == 1){
|
|
|
|
+ $result = $this->saleReportStepOfSecondTypeOne($return);
|
|
|
|
+ }elseif ($type == 2){
|
|
|
|
+ $result = $this->saleReportStepOfSecondTypeTwo($return);
|
|
|
|
+ }elseif ($type == 3){
|
|
|
|
+ $result = $this->saleReportStepOfSecondTypeThree($return, $user);
|
|
|
|
+ }elseif ($type == 4){
|
|
|
|
+ $result = $this->saleReportStepOfSecondTypeFour($return, $user);
|
|
|
|
+ }elseif ($type == 5){
|
|
|
|
+ $result = $this->saleReportStepOfSecondTypeFive($return);
|
|
|
|
+ }else{
|
|
|
|
+ return [false ,'报表查看类型错误'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ['list' => $result]];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfSecondTypeOne($time){
|
|
|
|
+ //大区
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach (Depart::$area as $key => $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value,
|
|
|
|
+ 'value' => $key,
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $label = "全部";
|
|
|
|
+ $total = [
|
|
|
|
+ 'label' => $label,
|
|
|
|
+ 'value' => "",
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(isset($map[$value['area']])) {
|
|
|
|
+ $tmp = bcadd($value['receipt'], $map[$value['area']]['num_1']);
|
|
|
|
+ $tmp2 = bcadd($value['contract_fee'], $map[$value['area']]['num_2']);
|
|
|
|
+ $map[$value['area']]['num_1'] = $tmp;
|
|
|
|
+ $map[$value['area']]['num_2'] = $tmp2;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['area']] = [
|
|
|
|
+ 'num_1' => $value['receipt'],
|
|
|
|
+ 'num_2' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_t = bcadd($total['receipt'], $value['receipt'],2);
|
|
|
|
+ $tmp_t1 = bcadd($total['all'], $value['contract_fee'],2);
|
|
|
|
+ $total['receipt'] = $tmp_t;
|
|
|
|
+ $total['all'] = $tmp_t1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['receipt'] = $tmp['num_1'];
|
|
|
|
+ $area[$key]['all'] = $tmp['num_2'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ usort($area, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all_num 降序
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果 all_num 相同,再比较 value
|
|
|
|
+ return $a['receipt'] - $b['receipt']; // value 正序
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ array_unshift($area, $total);
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfSecondTypeTwo($time){
|
|
|
|
+ $setting = Setting::where('setting_name','bt_top_depart_id')->first();
|
|
|
|
+ $bt_top_depart_id = $setting['setting_value'] ?? [];
|
|
|
|
+ $bt_top_depart_id = json_decode($bt_top_depart_id,true);
|
|
|
|
+
|
|
|
|
+ $id = [];
|
|
|
|
+ $depart_list = Depart::where('del_time',0)->select('id','parent_id','title')->get()->toArray();
|
|
|
|
+ foreach ($depart_list as $value){
|
|
|
|
+ if(in_array($value['parent_id'], $bt_top_depart_id) && $value['title'] == "营销部"){
|
|
|
|
+ $id[] = $value['id'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // 查找所有部门id
|
|
|
|
+ $all_depart_id = [];
|
|
|
|
+ foreach ($id as $value){
|
|
|
|
+ $childIds = $this->findChildIds($value, $depart_list);
|
|
|
|
+ $all_depart_id_tmp = array_merge($childIds, [$value]);
|
|
|
|
+ $all_depart_id = array_merge($all_depart_id, $all_depart_id_tmp);
|
|
|
|
+ }
|
|
|
|
+ // 获取部门下的人
|
|
|
|
+ $employee = EmployeeDepartPermission::whereIn('depart_id', $all_depart_id)
|
|
|
|
+ ->select('employee_id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $employee = array_unique(array_column($employee,'employee_id'));
|
|
|
|
+
|
|
|
|
+ $empList = Employee::whereIn('id', $employee)
|
|
|
|
+ ->select('id','emp_name as title')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $man = [];
|
|
|
|
+ foreach ($empList as $value){
|
|
|
|
+ $man[] = [
|
|
|
|
+ 'label' => $value['title'],
|
|
|
|
+ 'value' => $value['id'],
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0,
|
|
|
|
+ 'goal' => 0,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->whereIn('top_depart_id', $bt_top_depart_id)
|
|
|
|
+ ->where('model_type',SalesOrder::Model_type_one)
|
|
|
|
+ ->whereIn('crt_id',$employee)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(isset($map[$value['crt_id']])) {
|
|
|
|
+ $tmp = bcadd($value['receipt'], $map[$value['crt_id']]['num_1']);
|
|
|
|
+ $tmp2 = bcadd($value['contract_fee'], $map[$value['crt_id']]['num_2']);
|
|
|
|
+ $map[$value['crt_id']]['num_1'] = $tmp;
|
|
|
|
+ $map[$value['crt_id']]['num_2'] = $tmp2;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['crt_id']] = [
|
|
|
|
+ 'num_1' => $value['receipt'],
|
|
|
|
+ 'num_2' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $start_time = strtotime(date("Y-m-01 00:00:00", $start));
|
|
|
|
+ $month = MonthlyPerFormance::where('del_time',0)
|
|
|
|
+ ->where('crt_time',">=",$start_time)
|
|
|
|
+ ->where('crt_time','<=',$end)
|
|
|
|
+ ->select('employee_id','sales_index')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $month_map = [];
|
|
|
|
+ foreach ($month as $value){
|
|
|
|
+ $month_map[$value['employee_id']] = $value['sales_index'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($man as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $man[$key]['receipt'] = $tmp['num_1'];
|
|
|
|
+ $man[$key]['all'] = $tmp['num_2'];
|
|
|
|
+ }
|
|
|
|
+ $man[$key]['goal'] = $month_map[$value['value']] ?? 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ usort($man, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all_num 降序
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果 all_num 相同,再比较 value
|
|
|
|
+ return $a['receipt'] - $b['receipt']; // value 正序
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return $man;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfSecondTypeThree($time, $user){
|
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
|
+ $list = BasicType::where('del_time',0)
|
|
|
|
+ ->where('type',24)
|
|
|
|
+ ->where('top_depart_id', $head)
|
|
|
|
+ ->select('title')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ //大区
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach ($list as $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value['title'],
|
|
|
|
+ 'value' => $value['title'],
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $label = "无平台来源";
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('model_type', SalesOrder::Model_type_four)
|
|
|
|
+ ->where('top_depart_id', $head)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(empty($value['plat_type_title'])) $value['plat_type_title'] = $label;
|
|
|
|
+ if(isset($map[$value['plat_type_title']])) {
|
|
|
|
+ $tmp = bcadd($value['contract_fee'], $map[$value['plat_type_title']]['num_1']);
|
|
|
|
+ $map[$value['plat_type_title']]['num_1'] = $tmp;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['plat_type_title']] = [
|
|
|
|
+ 'num_1' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(isset($map[$label])){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $label,
|
|
|
|
+ 'value' => $label,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['all'] = $tmp['num_1'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ usort($area, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all_num 降序
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfSecondTypeFour($time, $user){
|
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
|
+
|
|
|
|
+ //大区
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach (Depart::$area as $key => $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value,
|
|
|
|
+ 'value' => $key,
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $label = "全部";
|
|
|
|
+ $total = [
|
|
|
|
+ 'label' => $label,
|
|
|
|
+ 'value' => "",
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('model_type', SalesOrder::Model_type_two)
|
|
|
|
+ ->where('from_top_depart_id', '>', 0)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(isset($map[$value['area']])) {
|
|
|
|
+ $tmp = bcadd($value['receipt'], $map[$value['area']]['num_1']);
|
|
|
|
+ $tmp2 = bcadd($value['contract_fee'], $map[$value['area']]['num_2']);
|
|
|
|
+ $map[$value['area']]['num_1'] = $tmp;
|
|
|
|
+ $map[$value['area']]['num_2'] = $tmp2;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['area']] = [
|
|
|
|
+ 'num_1' => $value['receipt'],
|
|
|
|
+ 'num_2' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_t = bcadd($total['receipt'], $value['receipt'],2);
|
|
|
|
+ $tmp_t1 = bcadd($total['all'], $value['contract_fee'],2);
|
|
|
|
+ $total['receipt'] = $tmp_t;
|
|
|
|
+ $total['all'] = $tmp_t1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['receipt'] = $tmp['num_1'];
|
|
|
|
+ $area[$key]['all'] = $tmp['num_2'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ usort($area, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all_num 降序
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果 all_num 相同,再比较 value
|
|
|
|
+ return $a['receipt'] - $b['receipt']; // value 正序
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ array_unshift($area, $total);
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfSecondTypeFive($time){
|
|
|
|
+ $label = "全部";
|
|
|
|
+ $total = [
|
|
|
|
+ 'label' => $label,
|
|
|
|
+ 'value' => "",
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $start_time = strtotime(date("Y-m-01 00:00:00", $start));
|
|
|
|
+ $list = CustomerPerFormance::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start_time)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(isset($map[$value['area']])) {
|
|
|
|
+ $tmp = bcadd($value['current_month_payment'], $map[$value['area']]['all']);
|
|
|
|
+ $map[$value['area']]['all'] = $tmp;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['area']] = [
|
|
|
|
+ 'label' => $value['area'],
|
|
|
|
+ 'value' => $value['area'],
|
|
|
|
+ 'all' => $value['current_month_payment']
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_t1 = bcadd($total['all'], $value['current_month_payment'],2);
|
|
|
|
+ $total['all'] = $tmp_t1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $map = array_values($map);
|
|
|
|
+
|
|
|
|
+ usort($map, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all_num 降序
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ array_unshift($map, $total);
|
|
|
|
+
|
|
|
|
+ return $map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function saleReportStepOfThird($data, $user){
|
|
|
|
+ if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ list($status, $msg) = $this->aboutTime($return);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+ if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
|
|
+ if(empty($data['value'])) return [false, 'value不能为空'];
|
|
|
|
+ $type = $data['type'];
|
|
|
|
+ if($type == 1){
|
|
|
|
+ $result = $this->saleReportStepOfThirdTypeOne($return, $data);
|
|
|
|
+ }elseif ($type == 2){
|
|
|
|
+ $result = $this->saleReportStepOfThirdTypeTwo($return, $data);
|
|
|
|
+ }elseif ($type == 3){
|
|
|
|
+ $result = $this->saleReportStepOfThirdTypeThree($return, $data, $user);
|
|
|
|
+ }elseif ($type == 4){
|
|
|
|
+ $result = $this->saleReportStepOfThirdTypeFour($return, $data, $user);
|
|
|
|
+ }elseif ($type == 5){
|
|
|
|
+ $result = $this->saleReportStepOfThirdTypeFive($return,$data);
|
|
|
|
+ }else{
|
|
|
|
+ return [false ,'报表查看类型错误'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ['list' => $result]];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfThirdTypeOne($time,$data){
|
|
|
|
+ $area_value = $data['value'];
|
|
|
|
+
|
|
|
|
+ $depart = Depart::where('del_time',0)
|
|
|
|
+ ->where('parent_id',0)
|
|
|
|
+ ->where('area',$area_value)
|
|
|
|
+ ->select('id','title')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ //大区
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach ($depart as $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value['title'],
|
|
|
|
+ 'value' => $value['id'],
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $label = "全部";
|
|
|
|
+ $total = [
|
|
|
|
+ 'label' => $label,
|
|
|
|
+ 'value' => "",
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('area',$area_value)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(isset($map[$value['top_depart_id']])) {
|
|
|
|
+ $tmp = bcadd($value['receipt'], $map[$value['top_depart_id']]['num_1']);
|
|
|
|
+ $tmp2 = bcadd($value['contract_fee'], $map[$value['top_depart_id']]['num_2']);
|
|
|
|
+ $map[$value['top_depart_id']]['num_1'] = $tmp;
|
|
|
|
+ $map[$value['top_depart_id']]['num_2'] = $tmp2;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['top_depart_id']] = [
|
|
|
|
+ 'num_1' => $value['receipt'],
|
|
|
|
+ 'num_2' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_t = bcadd($total['receipt'], $value['receipt'],2);
|
|
|
|
+ $tmp_t1 = bcadd($total['all'], $value['contract_fee'],2);
|
|
|
|
+ $total['receipt'] = $tmp_t;
|
|
|
|
+ $total['all'] = $tmp_t1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['receipt'] = $tmp['num_1'];
|
|
|
|
+ $area[$key]['all'] = $tmp['num_2'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ usort($area, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all_num 降序
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果 all_num 相同,再比较 value
|
|
|
|
+ return $a['receipt'] - $b['receipt']; // value 正序
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ array_unshift($area, $total);
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfThirdTypeTwo($time,$data){
|
|
|
|
+ $man_value = $data['value'];
|
|
|
|
+
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach (SalesOrderReport::$all_state_list as $key => $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value,
|
|
|
|
+ 'value' => $key,
|
|
|
|
+ 'list' => []
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $setting = Setting::where('setting_name','bt_top_depart_id')->first();
|
|
|
|
+ $bt_top_depart_id = $setting['setting_value'] ?? [];
|
|
|
|
+ $bt_top_depart_id = json_decode($bt_top_depart_id,true);
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->whereIn('top_depart_id', $bt_top_depart_id)
|
|
|
|
+ ->where('model_type',SalesOrder::Model_type_one)
|
|
|
|
+ ->where('crt_id', $man_value)
|
|
|
|
+ ->orderBy('crt_time','desc')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ $crt_time = $value['crt_time'] ? date("Y-m-d H:i:s", $value['crt_time']) : "";
|
|
|
|
+ $model_type_title = SalesOrder::$model_type_title[$value['model_type']] ?? "";
|
|
|
|
+ $tmp = [
|
|
|
|
+ 'crt_time' => $crt_time,
|
|
|
|
+ 'model_type_title' => $model_type_title,
|
|
|
|
+ 'customer' => $value['customer_title'],
|
|
|
|
+ 'contact_product' => $value['contact_product'],
|
|
|
|
+ 'fz' => $value['fz_man'],
|
|
|
|
+ 'contract_fee' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ $map[SalesOrderReport::state_zero][] = $tmp;
|
|
|
|
+
|
|
|
|
+ if($value['state'] == 1){
|
|
|
|
+ $map[SalesOrderReport::state_one][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 2){
|
|
|
|
+ $map[SalesOrderReport::state_two][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 3){
|
|
|
|
+ $map[SalesOrderReport::state_three][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 4){
|
|
|
|
+ $map[SalesOrderReport::state_four][] = $tmp;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['list'] = $tmp;
|
|
|
|
+ $area[$key]['count'] = count($tmp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfThirdTypeThree($time,$data, $user){
|
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
|
+ $basic_value = $data['value'];
|
|
|
|
+
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach (SalesOrderReport::$all_state_list as $key => $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value,
|
|
|
|
+ 'value' => $key,
|
|
|
|
+ 'list' => []
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('model_type', SalesOrder::Model_type_four)
|
|
|
|
+ ->where('top_depart_id', $head)
|
|
|
|
+ ->where('plat_type_title', $basic_value)
|
|
|
|
+ ->orderBy('crt_time','desc')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ $crt_time = $value['crt_time'] ? date("Y-m-d H:i:s", $value['crt_time']) : "";
|
|
|
|
+ $model_type_title = SalesOrder::$model_type_title[$value['model_type']] ?? "";
|
|
|
|
+ $tmp = [
|
|
|
|
+ 'crt_time' => $crt_time,
|
|
|
|
+ 'model_type_title' => $model_type_title,
|
|
|
|
+ 'customer' => $value['customer_title'],
|
|
|
|
+ 'contact_product' => $value['contact_product'],
|
|
|
|
+ 'fz' => $value['fz_man'],
|
|
|
|
+ 'contract_fee' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ $map[SalesOrderReport::state_zero][] = $tmp;
|
|
|
|
+
|
|
|
|
+ if($value['state'] == 1){
|
|
|
|
+ $map[SalesOrderReport::state_one][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 2){
|
|
|
|
+ $map[SalesOrderReport::state_two][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 3){
|
|
|
|
+ $map[SalesOrderReport::state_three][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 4){
|
|
|
|
+ $map[SalesOrderReport::state_four][] = $tmp;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['list'] = $tmp;
|
|
|
|
+ $area[$key]['count'] = count($tmp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfThirdTypeFour($time,$data, $user){
|
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
|
+ $area_value = $data['value'];
|
|
|
|
+
|
|
|
|
+ $depart = Depart::where('del_time',0)
|
|
|
|
+ ->where('parent_id',0)
|
|
|
|
+ ->where('area', $area_value)
|
|
|
|
+ ->select('id','title')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ //大区
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach ($depart as $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value['title'],
|
|
|
|
+ 'value' => $value['id'],
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $label = "全部";
|
|
|
|
+ $total = [
|
|
|
|
+ 'label' => $label,
|
|
|
|
+ 'value' => "",
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('area',$area_value)
|
|
|
|
+ ->where('model_type', SalesOrder::Model_type_two)
|
|
|
|
+ ->where('from_top_depart_id', '>',0)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(isset($map[$value['top_depart_id']])) {
|
|
|
|
+ $tmp = bcadd($value['receipt'], $map[$value['top_depart_id']]['num_1']);
|
|
|
|
+ $tmp2 = bcadd($value['contract_fee'], $map[$value['top_depart_id']]['num_2']);
|
|
|
|
+ $map[$value['top_depart_id']]['num_1'] = $tmp;
|
|
|
|
+ $map[$value['top_depart_id']]['num_2'] = $tmp2;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['top_depart_id']] = [
|
|
|
|
+ 'num_1' => $value['receipt'],
|
|
|
|
+ 'num_2' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_t = bcadd($total['receipt'], $value['receipt'],2);
|
|
|
|
+ $tmp_t1 = bcadd($total['all'], $value['contract_fee'],2);
|
|
|
|
+ $total['receipt'] = $tmp_t;
|
|
|
|
+ $total['all'] = $tmp_t1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['receipt'] = $tmp['num_1'];
|
|
|
|
+ $area[$key]['all'] = $tmp['num_2'];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ usort($area, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all_num 降序
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果 all_num 相同,再比较 value
|
|
|
|
+ return $a['receipt'] - $b['receipt']; // value 正序
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ array_unshift($area, $total);
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfThreeTypeFive($time,$data){
|
|
|
|
+ $area_value = $data['value'];
|
|
|
|
+
|
|
|
|
+ $label = "全部";
|
|
|
|
+ $total = [
|
|
|
|
+ 'label' => $label,
|
|
|
|
+ 'value' => "",
|
|
|
|
+ 'all' => 0
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $start_time = strtotime(date("Y-m-01 00:00:00", $start));
|
|
|
|
+ $list = CustomerPerFormance::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start_time)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('area', $area_value)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(isset($map[$value['title']])) {
|
|
|
|
+ $tmp = bcadd($value['current_month_payment'], $map[$value['title']]['all']);
|
|
|
|
+ $map[$value['title']]['all'] = $tmp;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['title']] = [
|
|
|
|
+ 'label' => $value['title'],
|
|
|
|
+ 'value' => $value['title'],
|
|
|
|
+ 'all' => $value['current_month_payment']
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_t1 = bcadd($total['all'], $value['current_month_payment'],2);
|
|
|
|
+ $total['all'] = $tmp_t1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $map = array_values($map);
|
|
|
|
+
|
|
|
|
+ usort($map, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all 降序
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ array_unshift($map, $total);
|
|
|
|
+
|
|
|
|
+ return $map;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function saleReportStepOfFour($data, $user){
|
|
|
|
+ if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ list($status, $msg) = $this->aboutTime($return);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+ if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
|
|
+ if(empty($data['value'])) return [false, 'value不能为空'];
|
|
|
|
+ if(empty($data['value2'])) return [false, 'value2不能为空'];
|
|
|
|
+ $type = $data['type'];
|
|
|
|
+ if($type == 1){
|
|
|
|
+ $result = $this->saleReportStepOfFourTypeOne($return, $data);
|
|
|
|
+ }elseif ($type == 4){
|
|
|
|
+ $result = $this->saleReportStepOfFourTypeFour($return, $data, $user);
|
|
|
|
+ }else{
|
|
|
|
+ return [false ,'报表查看类型错误'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ['list' => $result]];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfFourTypeOne($time,$data){
|
|
|
|
+ $area_value = $data['value'];
|
|
|
|
+ $depart_value = $data['value2'];
|
|
|
|
+
|
|
|
|
+ $depart_list = Depart::where('del_time',0)->select('id','parent_id','title')->get()->toArray();
|
|
|
|
+ // 查找所有部门id
|
|
|
|
+ $childIds = $this->findChildIds($depart_value, $depart_list);
|
|
|
|
+ $all_depart_id = array_merge($childIds, [$depart_value]);
|
|
|
|
+
|
|
|
|
+ // 获取部门下的人
|
|
|
|
+ $employee = EmployeeDepartPermission::whereIn('depart_id', $all_depart_id)
|
|
|
|
+ ->select('employee_id')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $employee = array_unique(array_column($employee,'employee_id'));
|
|
|
|
+
|
|
|
|
+ $empMap = Employee::whereIn('id', $employee)
|
|
|
|
+ ->pluck('emp_name as title','id')
|
|
|
|
+ ->toArray();
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach ($empMap as $key => $value){
|
|
|
|
+ $area[$key] = [
|
|
|
|
+ 'label' => $value,
|
|
|
|
+ 'value' => $key,
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0,
|
|
|
|
+ 'goal' => 0,
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $label = "全部";
|
|
|
|
+ $total = [
|
|
|
|
+ 'label' => $label,
|
|
|
|
+ 'value' => "",
|
|
|
|
+ 'receipt' => 0,
|
|
|
|
+ 'all' => 0,
|
|
|
|
+ 'goal' => 0,
|
|
|
|
+ ];
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('area',$area_value)
|
|
|
|
+ ->where('top_depart_id',$depart_value)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ if(isset($map[$value['crt_id']])) {
|
|
|
|
+ $tmp = bcadd($value['receipt'], $map[$value['crt_id']]['num_1']);
|
|
|
|
+ $tmp2 = bcadd($value['contract_fee'], $map[$value['crt_id']]['num_2']);
|
|
|
|
+ $map[$value['crt_id']]['num_1'] = $tmp;
|
|
|
|
+ $map[$value['crt_id']]['num_2'] = $tmp2;
|
|
|
|
+ }else{
|
|
|
|
+ $map[$value['crt_id']] = [
|
|
|
|
+ 'num_1' => $value['receipt'],
|
|
|
|
+ 'num_2' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $tmp_t = bcadd($total['receipt'], $value['receipt'],2);
|
|
|
|
+ $tmp_t1 = bcadd($total['all'], $value['contract_fee'],2);
|
|
|
|
+ $total['receipt'] = $tmp_t;
|
|
|
|
+ $total['all'] = $tmp_t1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $start_time = strtotime(date("Y-m-01 00:00:00", $start));
|
|
|
|
+ $month = MonthlyPerFormance::where('del_time',0)
|
|
|
|
+ ->where('crt_time',">=",$start_time)
|
|
|
|
+ ->where('crt_time','<=',$end)
|
|
|
|
+ ->select('employee_id','sales_index')
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+ $month_map = [];
|
|
|
|
+ foreach ($month as $value){
|
|
|
|
+ $month_map[$value['employee_id']] = $value['sales_index'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['receipt'] = $tmp['num_1'];
|
|
|
|
+ $area[$key]['all'] = $tmp['num_2'];
|
|
|
|
+ $goal = $month_map[$value['value']] ?? 0;
|
|
|
|
+ $area[$key]['goal'] = $goal;
|
|
|
|
+ $total['goal'] = bcadd($goal, $total['goal'],2);
|
|
|
|
+ }else{
|
|
|
|
+ unset($area[$key]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $area = array_values($area);
|
|
|
|
+
|
|
|
|
+ usort($area, function($a, $b) {
|
|
|
|
+ // 先比较 all_num
|
|
|
|
+ if ($b['all'] !== $a['all']) {
|
|
|
|
+ return $b['all'] - $a['all']; // all_num 降序
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 如果 all_num 相同,再比较 value
|
|
|
|
+ return $a['receipt'] - $b['receipt']; // value 正序
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ array_unshift($area, $total);
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfFourTypeFour($time,$data, $user){
|
|
|
|
+ $head = $user['head']['id'] ?? 0;
|
|
|
|
+ $area_value = $data['value'];
|
|
|
|
+ $depart_value = $data['value2'];
|
|
|
|
+
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach (SalesOrderReport::$all_state_list as $key => $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value,
|
|
|
|
+ 'value' => $key,
|
|
|
|
+ 'list' => []
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('area',$area_value)
|
|
|
|
+ ->where('model_type', SalesOrder::Model_type_two)
|
|
|
|
+ ->where('from_top_depart_id', $depart_value)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ $crt_time = $value['crt_time'] ? date("Y-m-d H:i:s", $value['crt_time']) : "";
|
|
|
|
+ $model_type_title = SalesOrder::$model_type_title[$value['model_type']] ?? "";
|
|
|
|
+ $tmp = [
|
|
|
|
+ 'crt_time' => $crt_time,
|
|
|
|
+ 'model_type_title' => $model_type_title,
|
|
|
|
+ 'customer' => $value['customer_title'],
|
|
|
|
+ 'contact_product' => $value['contact_product'],
|
|
|
|
+ 'fz' => $value['fz_man'],
|
|
|
|
+ 'contract_fee' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ $map[SalesOrderReport::state_zero][] = $tmp;
|
|
|
|
+
|
|
|
|
+ if($value['state'] == 1){
|
|
|
|
+ $map[SalesOrderReport::state_one][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 2){
|
|
|
|
+ $map[SalesOrderReport::state_two][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 3){
|
|
|
|
+ $map[SalesOrderReport::state_three][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 4){
|
|
|
|
+ $map[SalesOrderReport::state_four][] = $tmp;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['list'] = $tmp;
|
|
|
|
+ $area[$key]['count'] = count($tmp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function saleReportStepOfFive($data, $user){
|
|
|
|
+ if(empty($data['enter_time'][0]) || empty($data['enter_time'][1])) return [false, '请选择日期'];
|
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['enter_time']);
|
|
|
|
+ list($status, $msg) = $this->aboutTime($return);
|
|
|
|
+ if(! $status) return [false, $msg];
|
|
|
|
+ if(empty($data['type'])) return [false, '请选择报表查看类型'];
|
|
|
|
+ if(empty($data['value'])) return [false, 'value不能为空'];
|
|
|
|
+ if(empty($data['value2'])) return [false, 'value2不能为空'];
|
|
|
|
+ if(empty($data['value3'])) return [false, 'value3不能为空'];
|
|
|
|
+ $type = $data['type'];
|
|
|
|
+ if($type == 1){
|
|
|
|
+ $result = $this->saleReportStepOfFiveTypeOne($return, $data);
|
|
|
|
+ }else{
|
|
|
|
+ return [false ,'报表查看类型错误'];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return [true, ['list' => $result]];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private function saleReportStepOfFiveTypeOne($time,$data){
|
|
|
|
+ $area_value = $data['value'];
|
|
|
|
+ $depart_value = $data['value2'];
|
|
|
|
+ $man_value = $data['value3'];
|
|
|
|
+
|
|
|
|
+ $area = [];
|
|
|
|
+ foreach (SalesOrderReport::$all_state_list as $key => $value){
|
|
|
|
+ $area[] = [
|
|
|
|
+ 'label' => $value,
|
|
|
|
+ 'value' => $key,
|
|
|
|
+ 'list' => []
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $start = $time[0];
|
|
|
|
+ $end = $time[1];
|
|
|
|
+
|
|
|
|
+ $list = SalesOrderReport::where('del_time',0)
|
|
|
|
+ ->where('crt_time','>=', $start)
|
|
|
|
+ ->where('crt_time','<=', $end)
|
|
|
|
+ ->where('area',$area_value)
|
|
|
|
+ ->where('top_depart_id',$depart_value)
|
|
|
|
+ ->where('crt_id', $man_value)
|
|
|
|
+ ->get()->toArray();
|
|
|
|
+
|
|
|
|
+ $map = [];
|
|
|
|
+ foreach ($list as $value) {
|
|
|
|
+ $crt_time = $value['crt_time'] ? date("Y-m-d H:i:s", $value['crt_time']) : "";
|
|
|
|
+ $model_type_title = SalesOrder::$model_type_title[$value['model_type']] ?? "";
|
|
|
|
+ $tmp = [
|
|
|
|
+ 'crt_time' => $crt_time,
|
|
|
|
+ 'model_type_title' => $model_type_title,
|
|
|
|
+ 'customer' => $value['customer_title'],
|
|
|
|
+ 'contact_product' => $value['contact_product'],
|
|
|
|
+ 'fz' => $value['fz_man'],
|
|
|
|
+ 'contract_fee' => $value['contract_fee'],
|
|
|
|
+ ];
|
|
|
|
+ $map[SalesOrderReport::state_zero][] = $tmp;
|
|
|
|
+
|
|
|
|
+ if($value['state'] == 1){
|
|
|
|
+ $map[SalesOrderReport::state_one][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 2){
|
|
|
|
+ $map[SalesOrderReport::state_two][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 3){
|
|
|
|
+ $map[SalesOrderReport::state_three][] = $tmp;
|
|
|
|
+ }elseif ($value['state'] == 4){
|
|
|
|
+ $map[SalesOrderReport::state_four][] = $tmp;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ foreach ($area as $key => $value){
|
|
|
|
+ if(isset($map[$value['value']])){
|
|
|
|
+ $tmp = $map[$value['value']];
|
|
|
|
+ $area[$key]['list'] = $tmp;
|
|
|
|
+ $area[$key]['count'] = count($tmp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return $area;
|
|
|
|
+ }
|
|
}
|
|
}
|