智慧教务系统
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.
 
 
 
 
 
 

159 lines
4.8 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\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_id = CampusPersonRole::where('person_id',$person_id)
->distinct(true)
->column('campus_id');
//查当前用户校区下的全部员工id
$person_id_arr = CampusPersonRole::whereIn('campus_id',$campus_id)
->distinct(true)
->column('person_id');
$model = $this->model;
if ((!empty($where['shared_by']) || isset($where['shared_by'])) && $where['shared_by'] !== '') {
$model = $model->where('shared_by', $where['shared_by']);
}
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->whereIn('user_id', $person_id_arr);
//分页查询
$res = $model->with([
'customerResource'=>function($query){
$query->append(['initial_intent_name']);
}
])->paginate([
'list_rows' => $limit,
'page' => $page,
])->toArray();
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){},
'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 (!empty($data['customerResource'])) {
$data['customerResource']['cj_count'] = OrderTable::where('resource_id', $data['customerResource']['id'])
->where('order_status', 'paid')
->count();//成交次数
}
if ($data) {
$res['code'] = 1;
$res['msg'] = '操作成功';
$res['data'] = $data->toArray();
} 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;
}
}