智慧教务系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

205 lines
6.6 KiB

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的多应用管理平台
// +----------------------------------------------------------------------
// | 官方网址:https://www.niucloud.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\service\api\apiService;
use app\model\campus_person_role\CampusPersonRole;
use app\model\customer_resources\CustomerResources;
use app\model\order_table\OrderTable;
use app\model\resource_sharing\ResourceSharing;
use core\base\BaseApiService;
/**
* 资源共享服务层
* Class MemberService
* @package app\service\api\member
*/
class ResourceSharingService extends BaseApiService
{
public function __construct()
{
parent::__construct();
$this->model = (new ResourceSharing());
}
//获取列表
public function getList(array $where)
{
$page_params = $this->getPageParam();//获取请求参数中的页码+分页数
$page = $page_params['page'];
$limit = $page_params['limit'];
$person_id = $this->member_id;//当前登录的员工id
$campus_where = [];
$campus_where[] = ['person_id','=',$person_id];
if (!empty($where['campus_name'])) {
$campus_where[] = ['campus_name','like','%'.$where['campus_name'].'%'];
}
//查当前用户的归属校区
$campus_id = CampusPersonRole::where($campus_where)
->distinct(true)
->column('campus_id');
if ($campus_id) {
//查当前用户校区下的全部员工id
$person_id_arr = CampusPersonRole::whereIn('campus_id', $campus_id)
->distinct(true)
->column('person_id');
}
$resource_id_arr = [];//客户资源表id
//客户资源表名字
if (!empty($where['name'])) {
$resource_id = (new CustomerResources())->where('name', 'like', "%{$where['name']}%")->column('id');
$resource_id_arr = array_merge($resource_id_arr, $resource_id);
}
//客户资源表手机号
if (!empty($where['phone_number'])) {
$resource_id = (new CustomerResources())->where('phone_number', 'like', "%{$where['phone_number']}%")->column('id');
$resource_id_arr = array_merge($resource_id_arr, $resource_id);
}
//去重
$resource_id_arr = array_unique($resource_id_arr);
$model = $this->model;
if ($resource_id_arr) {
$model = $model->whereIn('resource_id', $resource_id_arr);
}
if (!empty($where['shared_at_arr'])) {
$model = $model->where('shared_at', '>=', $where['shared_at_arr'][0])->where('shared_at', '<=', $where['shared_at_arr'][1]);
}
$model = $model->when(!empty($person_id_arr), function ($query) use ($person_id_arr) {
$query->whereIn('user_id', $person_id_arr);
});
if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') {
$model = $model->whereOr('shared_by', $where['shared_by']);
}
//分页查询
$res = $model->with([
'customerResource' => function ($query) {
$query->append(['initial_intent_name']);
}
])
->withJoin(['customerResource'])
->order('customerResource.updated_at', 'desc')
->paginate([
'list_rows' => $limit,
'page' => $page,
])->toArray();
foreach ($res['data'] as &$item){
$item['customerResource']['source_channel'] = get_dict_value('source',$item['customerResource']['source_channel']);
}
return $res;
}
//查询资源共享详情
public function info(array $where, string $field = '*')
{
$res = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
if (!$where) {
$res['msg'] = '缺少查询条件';
return $res;
}
$model = $this->model;
if (!empty($where['id'])) {
$model = $model->where('id', $where['id']);
}
$data = $model->with([
'customerResource' => function ($query) {
$query->with([
'sixSpeed' => function ($query_2) {
$query_2->append([
'purchase_power_name',//购买力
'concept_awareness_name',//认知理念
]);
},
'personnel' => function ($query_2) {
}
])->append([
'source_channel_name',//来源渠道
'source_name',//来源
'gender_name',//性别
'purchasing_power_name',//购买力
'cognitive_idea_name',//认知理念
'initial_intent_name',//客户初步意向度
'status_name',//客户状态
]);
}
])->field($field)->find();
if ($data) {
$data = $data->toArray();
}
if (!empty($data['customerResource'])) {
$data['customerResource']['cj_count'] = OrderTable::where('resource_id', $data['customerResource']['id'])
->where('order_status', 'paid')
->count();//成交次数
}
// dd(123123,$data);
if ($data) {
$res['code'] = 1;
$res['msg'] = '操作成功';
$res['data'] = $data;
} else {
$res['code'] = 0;
$res['msg'] = '未找到数据';
$res['data'] = [];
}
return $res;
}
//更新资源共享表
public function editData(array $where, array $data)
{
$res = [
'code' => 0,
'msg' => '操作失败',
'data' => []
];
if (!$where) {
$res['msg'] = '查询条件不能为空';
return $res;
}
$model = $this->model;
if ($where['id']) {
$model = $model->where('id', $where['id']);
}
$data = $model->update($data);
if ($data) {
$res = [
'code' => 1,
'msg' => '操作成功',
'data' => []
];
}
return $res;
}
}