Browse Source

修改bug

master
王泽彦 9 months ago
parent
commit
226a1afdab
  1. 26
      niucloud/app/model/resource_sharing/ResourceSharing.php
  2. 2
      niucloud/app/service/api/apiService/CommonService.php
  3. 32
      niucloud/app/service/api/apiService/ResourceSharingService.php

26
niucloud/app/model/resource_sharing/ResourceSharing.php

@ -12,6 +12,7 @@
namespace app\model\resource_sharing; namespace app\model\resource_sharing;
use app\model\customer_resources\CustomerResources; use app\model\customer_resources\CustomerResources;
use app\model\six_speed\SixSpeed;
use core\base\BaseModel; use core\base\BaseModel;
use think\model\concern\SoftDelete; use think\model\concern\SoftDelete;
use think\model\relation\HasMany; use think\model\relation\HasMany;
@ -25,7 +26,7 @@ use think\model\relation\HasOne;
class ResourceSharing extends BaseModel class ResourceSharing extends BaseModel
{ {
/** /**
* 数据表主键 * 数据表主键
@ -39,9 +40,9 @@ class ResourceSharing extends BaseModel
*/ */
protected $name = 'resource_sharing'; protected $name = 'resource_sharing';
/** /**
* 搜索器:资源共享共享记录编号 * 搜索器:资源共享共享记录编号
@ -54,7 +55,7 @@ class ResourceSharing extends BaseModel
$query->where("id", $value); $query->where("id", $value);
} }
} }
/** /**
* 搜索器:资源共享资源ID * 搜索器:资源共享资源ID
* @param $value * @param $value
@ -66,7 +67,7 @@ class ResourceSharing extends BaseModel
$query->where("resource_id", $value); $query->where("resource_id", $value);
} }
} }
/** /**
* 搜索器:资源共享用户ID(可为空) * 搜索器:资源共享用户ID(可为空)
* @param $value * @param $value
@ -78,7 +79,7 @@ class ResourceSharing extends BaseModel
$query->where("user_id", $value); $query->where("user_id", $value);
} }
} }
/** /**
* 搜索器:资源共享角色ID(可为空) * 搜索器:资源共享角色ID(可为空)
* @param $value * @param $value
@ -90,7 +91,7 @@ class ResourceSharing extends BaseModel
$query->where("role_id", $value); $query->where("role_id", $value);
} }
} }
/** /**
* 搜索器:资源共享共享人ID * 搜索器:资源共享共享人ID
* @param $value * @param $value
@ -102,7 +103,7 @@ class ResourceSharing extends BaseModel
$query->where("shared_by", $value); $query->where("shared_by", $value);
} }
} }
/** /**
* 搜索器:资源共享共享时间 * 搜索器:资源共享共享时间
* @param $value * @param $value
@ -125,6 +126,11 @@ class ResourceSharing extends BaseModel
{ {
return $this->hasOne(CustomerResources::class, 'id', 'resource_id'); return $this->hasOne(CustomerResources::class, 'id', 'resource_id');
} }
/**
* 关联six_speed表(一对一)
*/
public function sixSpeed(): HasOne
{
return $this->hasOne(SixSpeed::class, 'resource_id', 'resource_id');
}
} }

2
niucloud/app/service/api/apiService/CommonService.php

@ -40,7 +40,7 @@ class CommonService extends BaseApiService
$res = $model->field($field)->find();//员工信息 $res = $model->field($field)->find();//员工信息
if($res){ if($res){
$res = $res->toArray(); $res = $res->toArray()['dictionary'];
}else{ }else{
$res = []; $res = [];
} }

32
niucloud/app/service/api/apiService/ResourceSharingService.php

@ -13,6 +13,7 @@ namespace app\service\api\apiService;
use app\model\campus\Campus; use app\model\campus\Campus;
use app\model\campus_person_role\CampusPersonRole; use app\model\campus_person_role\CampusPersonRole;
use app\model\communication_records\CommunicationRecords;
use app\model\customer_resources\CustomerResources; use app\model\customer_resources\CustomerResources;
use app\model\order_table\OrderTable; use app\model\order_table\OrderTable;
use app\model\resource_sharing\ResourceSharing; use app\model\resource_sharing\ResourceSharing;
@ -90,23 +91,36 @@ class ResourceSharingService extends BaseApiService
$model = $model->whereOr('shared_by', $where['shared_by']); $model = $model->whereOr('shared_by', $where['shared_by']);
} }
//分页查询 //分页查询
$res = $model->with([ $res = $model->with(['customerResource','sixSpeed'])
'customerResource' => function ($query) { ->withJoin(['customerResource','sixSpeed'])
$query->append(['initial_intent_name']);
}
])
->withJoin(['customerResource'])
->order('customerResource.updated_at', 'desc') ->order('customerResource.updated_at', 'desc')
->paginate([ ->paginate([
'list_rows' => $limit, 'list_rows' => $limit,
'page' => $page, 'page' => $page,
])->toArray(); ])->toArray();
// 获取列表中的campus_ids
$campus_ids = array_unique(array_column(array_column($res['data'],'customerResource'), 'campus'));
$campus = new Campus(); $campus = new Campus();
$campus_name = $campus->whereIn('id', $campus_ids)->column('campus_name', 'id');
// 获取客户资源沟通记录
$customer_resource_ids = array_unique(array_column($res['data'], 'resource_id'));
// 2. 构建子查询:获取每个 resource_id 的最大 communication_time
$subQuery = CommunicationRecords::field('resource_id, max(communication_time) as max_time')
->whereIn('resource_id', $customer_resource_ids) // 只查询指定的 resource_id
->group('resource_id')
->select()
->toArray();
dd($campus_name,$campus_ids);
$resultdata = [];
foreach ($subQuery as $item) {
$resultdata[$item['resource_id']] = $item['max_time'];
}
foreach ($res['data'] as &$item){ foreach ($res['data'] as &$item){
$item['customerResource']['source_channel'] = get_dict_value('source',$item['customerResource']['source_channel']); $item['customerResource']['source_channel'] = get_dict_value('source',$item['customerResource']['source_channel']);
$item['customerResource']['campus_name'] = $campus->where(['id' =>$item['customerResource']['campus']])->value("campus_name"); $item['customerResource']['campus_name'] = $campus_name[$item['customerResource']['campus']] ?? '';
$item['customerResource']['communication_time'] = $resultdata[$item['resource_id']] ?? '';
} }
return $res; return $res;

Loading…
Cancel
Save