|
@@ -2,6 +2,8 @@
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
+use App\Model\BasicType;
|
|
|
+use App\Model\Customer;
|
|
|
use App\Model\Depart;
|
|
|
use App\Model\DepartIndex;
|
|
|
use App\Model\InOutRecord;
|
|
@@ -21,6 +23,84 @@ use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class StatisticsService extends Service
|
|
|
{
|
|
|
+ public function statisticsCustomer($data,$user){
|
|
|
+ if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false, '请选择客资创建时间区间'];
|
|
|
+
|
|
|
+ $model = Customer::Clear($user,$data);
|
|
|
+ $model = $model->where('del_time',0)
|
|
|
+ ->select('id','model_type','customer_from','top_depart_id','fp_top_depart_id')
|
|
|
+ ->orderby('id', 'desc');
|
|
|
+
|
|
|
+ if(! empty($data['crt_time'][0]) && ! empty($data['crt_time'][1])) {
|
|
|
+ $return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
|
+ $model->where('crt_time','>=',$return[0]);
|
|
|
+ $model->where('crt_time','<=',$return[1]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $list = $model->get()->toArray();
|
|
|
+ $list1 = $this->fillStatisticsCustomer($list);
|
|
|
+ $list2 = $this->fillStatisticsCustomer2($list);
|
|
|
+
|
|
|
+ return [true, ['bt' => $list1, 'zz' => $list2]];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillStatisticsCustomer($data){
|
|
|
+ if(empty($data)) return $data;
|
|
|
+
|
|
|
+ $customer_from = array_unique(array_column($data,'customer_from'));
|
|
|
+ $basic_type = BasicType::where('del_time',0)
|
|
|
+ ->whereIn('id',$customer_from)
|
|
|
+ ->where('type',2)
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ $return = [];
|
|
|
+ foreach ($data as $value){
|
|
|
+ $tmp = $basic_type[$value['customer_from']] ?? "";
|
|
|
+ if(! $tmp) continue;
|
|
|
+ if(isset($return[$tmp])){
|
|
|
+ $return[$tmp]['total'] += 1;
|
|
|
+ }else{
|
|
|
+ $return[$tmp] = [
|
|
|
+ 'total' => 1,
|
|
|
+ 'title' => $tmp
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return array_values($return);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function fillStatisticsCustomer2($data){
|
|
|
+ if(empty($data)) return $data;
|
|
|
+
|
|
|
+ $depart = Depart::where('del_time',0)
|
|
|
+ ->where('parent_id',0)
|
|
|
+ ->where('is_main',0)
|
|
|
+ ->pluck('title','id')
|
|
|
+ ->toArray();
|
|
|
+ $return = [];
|
|
|
+ foreach ($depart as $key => $value){
|
|
|
+ $return[$key] = [
|
|
|
+ 'title' => $value,
|
|
|
+ 'total' => 0
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($data as $value){
|
|
|
+ if($value['fp_top_depart_id'] > 0){
|
|
|
+ if(isset($return[$value['fp_top_depart_id']])) $return[$value['fp_top_depart_id']]['total'] += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $return = array_values($return);
|
|
|
+ usort($return, function($a, $b) {
|
|
|
+ return $b['total'] - $a['total'];
|
|
|
+ });
|
|
|
+
|
|
|
+ return $return;
|
|
|
+ }
|
|
|
+
|
|
|
//销售统计饼图 根据合同类型区分(例如线上合同、线下合同)
|
|
|
public function statisticsBt($data,$user){
|
|
|
if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false, '请选择销售订单时间区间'];
|