7 changed files with 497 additions and 44 deletions
@ -0,0 +1,42 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|||
// +---------------------------------------------------------------------- |
|||
// | 官方网址:https://www.niucloud.com |
|||
// +---------------------------------------------------------------------- |
|||
// | niucloud团队 版权所有 开源版本可自由商用 |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: Niucloud Team |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace app\api\controller\apiController; |
|||
|
|||
use app\Request; |
|||
use app\service\api\apiService\CampusService; |
|||
use app\service\api\apiService\CommonService; |
|||
use core\base\BaseApiService; |
|||
|
|||
/** |
|||
* 校区控制器相关接口 |
|||
* Class Personnel |
|||
* @package app\api\controller\apiController |
|||
*/ |
|||
class Campus extends BaseApiService |
|||
{ |
|||
|
|||
//校区-获取员工下的全部校区 |
|||
public function getPersonnelCampus(Request $request){ |
|||
$personnel_id =$request->param('personnel_id',''); |
|||
if(empty($personnel_id)){ |
|||
return fail('缺少参数'); |
|||
} |
|||
$where = [ |
|||
'personnel_id'=>$personnel_id |
|||
]; |
|||
$res = (new CampusService())->getAll($where); |
|||
if(!$res['code']){ |
|||
return fail($res['msg']); |
|||
} |
|||
return success($res['data']); |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|||
// +---------------------------------------------------------------------- |
|||
// | 官方网址:https://www.niucloud.com |
|||
// +---------------------------------------------------------------------- |
|||
// | niucloud团队 版权所有 开源版本可自由商用 |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: Niucloud Team |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace app\api\controller\apiController; |
|||
|
|||
use app\Request; |
|||
use app\service\api\apiService\CommonService; |
|||
use app\service\api\apiService\CommunicationRecordsService; |
|||
use core\base\BaseApiService; |
|||
|
|||
/** |
|||
* 沟通记录相关接口 |
|||
* Class Personnel |
|||
* @package app\api\controller\apiController |
|||
*/ |
|||
class CommunicationRecords extends BaseApiService |
|||
{ |
|||
|
|||
//获取字典 |
|||
public function add(Request $request){ |
|||
|
|||
|
|||
$date = date('Y-m-d H:i:s'); |
|||
$data = [ |
|||
'staff_id' => $request->param('staff_id', ''),// |
|||
'resource_id' => $request->param('resource_id', ''),// |
|||
'resource_type' => $request->param('resource_type', ''),//资源类型(如设备、文件、系统等) |
|||
'communication_type' => $request->param('communication_type', ''),// |
|||
'communication_result' => $request->param('communication_result', ''),//沟通结果: success-成功, failure-失败, pending-待定 |
|||
'communication_time' => $request->param('communication_time', $date),//沟通时间 |
|||
'remarks' => $request->param('remarks', ''),//备注 |
|||
'tag' => $request->param('tag', null),//标签:|默认null high-高, medium-中, low-低 |
|||
]; |
|||
|
|||
$res = (new CommunicationRecordsService())->add($data); |
|||
if(!$res['code']){ |
|||
return fail('操作失败'); |
|||
} |
|||
return success('操作成功'); |
|||
} |
|||
} |
|||
@ -0,0 +1,91 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|||
// +---------------------------------------------------------------------- |
|||
// | 官方网址:https://www.niucloud.com |
|||
// +---------------------------------------------------------------------- |
|||
// | niucloud团队 版权所有 开源版本可自由商用 |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: Niucloud Team |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace app\service\api\apiService; |
|||
|
|||
use app\model\campus\Campus; |
|||
use app\model\campus_person_role\CampusPersonRole; |
|||
use app\model\dict\Dict; |
|||
use core\base\BaseApiService; |
|||
|
|||
/** |
|||
* 校区服务层 |
|||
* Class MemberService |
|||
* @package app\service\api\member |
|||
*/ |
|||
class CampusService extends BaseApiService |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
$this->model = (new Campus()); |
|||
} |
|||
|
|||
//获取全部校区 |
|||
public function getAll(array $where){ |
|||
$res = [ |
|||
'code'=>0, |
|||
'msg'=>'缺少筛选条件', |
|||
'data'=>[] |
|||
]; |
|||
if(!$where){ |
|||
return $res; |
|||
} |
|||
|
|||
$model = $this->model; |
|||
//判断用没有员工id |
|||
if(!empty($where['personnel_id'])){ |
|||
//获取员工归属的校区id |
|||
$campus_id = $this->getPersonnelCamousId($where['personnel_id']); |
|||
if(!$campus_id){ |
|||
$res = [ |
|||
'code'=>0, |
|||
'msg'=>'暂无归属校区', |
|||
'data'=>[] |
|||
]; |
|||
return $res; |
|||
} |
|||
$model = $model->whereIn('id',$campus_id); |
|||
} |
|||
$data = $model->select()->toArray(); |
|||
|
|||
foreach ($data as &$v){ |
|||
$campus_coordinates_arr = json_decode($v['campus_coordinates'],true); |
|||
$v['campus_coordinates_arr'] = [ |
|||
'address'=>$campus_coordinates_arr['address'] ?? '', |
|||
'lat'=>$campus_coordinates_arr['lat'] ?? '', |
|||
'lng'=>$campus_coordinates_arr['lng'] ?? '', |
|||
]; |
|||
} |
|||
|
|||
$res = [ |
|||
'code'=>1, |
|||
'msg'=>'操作成功', |
|||
'data'=>$data |
|||
]; |
|||
return $res; |
|||
} |
|||
|
|||
/** |
|||
* 查询员工归属的校区id |
|||
* @param $personnel_id 员工表id |
|||
*/ |
|||
private function getPersonnelCamousId($personnel_id){ |
|||
//这里要去重 |
|||
$campus_id = CampusPersonRole::where('person_id',$personnel_id) |
|||
->distinct(true) |
|||
->column('campus_id'); |
|||
return $campus_id; |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
<?php |
|||
// +---------------------------------------------------------------------- |
|||
// | Niucloud-admin 企业快速开发的多应用管理平台 |
|||
// +---------------------------------------------------------------------- |
|||
// | 官方网址:https://www.niucloud.com |
|||
// +---------------------------------------------------------------------- |
|||
// | niucloud团队 版权所有 开源版本可自由商用 |
|||
// +---------------------------------------------------------------------- |
|||
// | Author: Niucloud Team |
|||
// +---------------------------------------------------------------------- |
|||
|
|||
namespace app\service\api\apiService; |
|||
|
|||
use app\model\communication_records\CommunicationRecords; |
|||
use app\model\dict\Dict; |
|||
use core\base\BaseApiService; |
|||
|
|||
/** |
|||
* 沟通记录服务层 |
|||
* Class MemberService |
|||
* @package app\service\api\member |
|||
*/ |
|||
class CommunicationRecordsService extends BaseApiService |
|||
{ |
|||
public function __construct() |
|||
{ |
|||
parent::__construct(); |
|||
$this->model = (new CommunicationRecords()); |
|||
} |
|||
|
|||
//添加沟通记录 |
|||
public function add(array $data) |
|||
{ |
|||
$model = $this->model; |
|||
$add = $model->create($data);//员工信息 |
|||
if ($add) { |
|||
$res = [ |
|||
'code' => 1, |
|||
'msg' => '操作成功', |
|||
'data' => [] |
|||
]; |
|||
} else { |
|||
$res = [ |
|||
'code' => 0, |
|||
'msg' => '操作失败', |
|||
'data' => [] |
|||
]; |
|||
} |
|||
return $res; |
|||
} |
|||
|
|||
/** |
|||
* 对比新旧数据改变 |
|||
* @param array $old_data 旧数据 |
|||
* @param array $new_data 新数据 |
|||
* @param array $ignoreFields 忽略验证的字段|默认[] |
|||
* @return array |
|||
*/ |
|||
public function compareData(array $old_data, array $new_data, array $ignoreFields = ['updated_at']) |
|||
{ |
|||
$changedFields = [];//改了那些字段 |
|||
$oldChanges = [];//数据修改前的样子 |
|||
$newChanges = [];//数据修改后的样子 |
|||
|
|||
foreach ($new_data as $key => $value) { |
|||
// 如果字段在忽略列表中,则跳过 |
|||
if (in_array($key, $ignoreFields)) { |
|||
continue; |
|||
} |
|||
|
|||
if (!isset($old_data[$key]) || $old_data[$key] != $value) { |
|||
$changedFields[] = $key; |
|||
$oldChanges[$key] = $old_data[$key] ?? null; |
|||
$newChanges[$key] = $value; |
|||
} |
|||
} |
|||
|
|||
return [ |
|||
'changed_fields' => $changedFields, |
|||
'old_values' => $oldChanges, |
|||
'new_values' => $newChanges, |
|||
|
|||
'changed_fields_json' => json_encode($changedFields, JSON_UNESCAPED_UNICODE), |
|||
'old_values_json' => json_encode($oldChanges, JSON_UNESCAPED_UNICODE), |
|||
'new_values_json' => json_encode($newChanges, JSON_UNESCAPED_UNICODE) |
|||
]; |
|||
} |
|||
|
|||
} |
|||
Loading…
Reference in new issue