diff --git a/niucloud/app/api/controller/apiController/Personnel.php b/niucloud/app/api/controller/apiController/Personnel.php index f1e3ad48..1bc57aa2 100644 --- a/niucloud/app/api/controller/apiController/Personnel.php +++ b/niucloud/app/api/controller/apiController/Personnel.php @@ -12,6 +12,7 @@ namespace app\api\controller\apiController; use app\dict\member\MemberLoginTypeDict; +use app\model\reimbursement\Reimbursement; use app\Request; use app\service\api\apiService\PersonnelService; use app\service\api\captcha\CaptchaService; @@ -115,4 +116,29 @@ class Personnel extends BaseApiService } + + public function reimbursement_list(){ + return success((new PersonnelService())->reimbursement_list()); + + } + + public function reimbursement_info(Request $request){ + $data = [ + 'id' => $request->param('id', ''), + ]; + return success((new PersonnelService())->reimbursement_info($data)); + + } + + public function reimbursement_add(Request $request){ + $data = [ + 'id' => $request->param('id', ''), + 'amount' => $request->param('amount', ''), + 'description' => $request->param('description', ''), + 'receipt_url' => $request->param('receipt_url', ''), + ]; + return success((new PersonnelService())->reimbursement_add($data)); + + } + } diff --git a/niucloud/app/api/controller/apiController/Statistics.php b/niucloud/app/api/controller/apiController/Statistics.php index 582c704e..03ef4917 100644 --- a/niucloud/app/api/controller/apiController/Statistics.php +++ b/niucloud/app/api/controller/apiController/Statistics.php @@ -362,6 +362,117 @@ class Statistics extends BaseApiService return success($data); } + public function getStaffStatistics(Request $request){ + $date = $request->param('date',''); + $date = strtotime($date); + $year = date('Y', $date); + + $campus_person_role = new CampusPersonRole(); + $customerResources = new CustomerResources(); + + $dict = new \app\model\dict\Dict(); + $dict_info = $dict->where([['key', '=', 'SourceChannel']])->findOrEmpty()->toArray(); + $channelList = $dict_info['dictionary']; + + + $staff_list = $campus_person_role + ->alias("a") + ->join(['school_personnel' => 'c'],'a.person_id = c.id','left') + ->where([ + ['a.dept_id','in',1] + ]) + ->field("c.id,c.name") + ->select(); + $staff_list = $staff_list->toArray(); // 转换成数组 + $customer_list = $customerResources->select()->toArray(); + + + + $staff_map = []; + foreach($staff_list as &$staff){ + $staff['weekCount'] = 0; + $staff['monthCount'] = 0; + $staff['yearCount'] = 0; + $staff['total'] = 0; + foreach($channelList as $channel){ + $staff['channel'][$channel['value']] = 0; + } + $staff_map[$staff['id']] = &$staff; + } + + foreach ($customer_list as $val){ + $dateTimestamp = strtotime($val['create_date']); + $dateYear = date('Y', $dateTimestamp); + + if(isset($staff_map[$val['consultant']])){ + + if(isDateInThisWeek($val['create_date'])){ + $staff_map[$val['consultant']]['weekCount']++; + } + if($val['create_year_month'] == date("Y-m",$date)){ + $staff_map[$val['consultant']]['monthCount']++; + } + + if($dateYear == $year){ + $staff_map[$val['consultant']]['yearCount']++; + } + } + + } + + + + $campusModel = new \app\model\campus\Campus(); + + $campus = $campusModel->select(); + $campus = $campus->toArray(); + + $channel_list = []; + foreach($channelList as &$channel){ + foreach ($campus as $key=>$val){ + $channel[$val['id']] = 0; + $channel['total'] = 0; +// $channel['staffs'] = $staff_map; + } + + $channel_list[$channel['value']] = &$channel; + } + + $customer_list = $customerResources->where([ + ['create_year_month','=',date("Y-m",$date)], + ])->select()->toArray(); + + foreach ($customer_list as $val){ + // dump($staff_map[$val['consultant']]['channel'][1]);die; + + if(isset($channel_list[$val['source_channel']])){ + $channel_list[$val['source_channel']]['total']++; + if(isset($channel_list[$val['source_channel']][$val['campus']])){ + $channel_list[$val['source_channel']][$val['campus']]++; + } + + + if(isset($staff_map[$val['consultant']])){ + + if(isset($staff_map[$val['consultant']]['channel'][$val['source_channel']])){ + + $staff_map[$val['consultant']]['channel'][$val['source_channel']]++; + } + } + } + } + + + + + return success([ + 'staffData' => $staff_map, + 'schoolList' => $campus, + 'channelList' => $channel_list, + ]); + + } + } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 3714133a..ca9eeb89 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -344,6 +344,16 @@ Route::group(function () { Route::get('per_list_call_up', 'member.Member/list_call_up'); Route::post('per_update_call_up', 'member.Member/update_call_up'); + + + Route::get('statistics/getStaffStatistics', 'apiController.Statistics/getStaffStatistics'); + + //报销 + Route::get('personnel/reimbursement_list', 'apiController.Personnel/reimbursement_list'); + Route::post('personnel/reimbursement_add', 'apiController.Personnel/reimbursement_add'); + Route::get('personnel/reimbursement_info', 'apiController.Personnel/reimbursement_info'); + + })->middleware(ApiChannel::class) ->middleware(ApiPersonnelCheckToken::class, true) ->middleware(ApiLog::class); diff --git a/niucloud/app/service/api/apiService/PersonnelService.php b/niucloud/app/service/api/apiService/PersonnelService.php index 30038471..5f5652a3 100644 --- a/niucloud/app/service/api/apiService/PersonnelService.php +++ b/niucloud/app/service/api/apiService/PersonnelService.php @@ -15,8 +15,10 @@ use app\model\campus_person_role\CampusPersonRole; use app\model\departments\Departments; use app\model\member\Member; use app\model\personnel\Personnel; +use app\model\reimbursement\Reimbursement; use app\model\sys\SysRole; use app\model\sys\SysUser; +use app\Request; use core\base\BaseApiService; use think\facade\Cache; use think\Model; @@ -365,4 +367,50 @@ class PersonnelService extends BaseApiService } return $this->model->where($where)->findOrEmpty(); } + + public function reimbursement_list(){ + $reimbursement = new Reimbursement(); + + $data = $reimbursement->where(['applicant_id' => $this->member_id])->select()->toArray(); + + return $data; + } + + + public function reimbursement_info(array $data){ + $id = $data['id']; + + $reimbursement = new Reimbursement(); + + $info = $reimbursement->where(['id' =>$id ])->find()->toArray(); + + return $info; + + } + + public function reimbursement_add(array $data){ + $reimbursement = new Reimbursement(); + + if($data['id']){ + $reimbursement->where(['id' => $data['id']])->update([ + 'applicant_id' => $this->member_id, + 'amount' => $data['amount'], + 'description' => $data['description'], + 'receipt_url' => $data['receipt_url'] + ]); + }else{ + $reimbursement->insert([ + 'applicant_id' => $this->member_id, + 'amount' => $data['amount'], + 'description' => $data['description'], + 'receipt_url' => $data['receipt_url'] + ]); + } + + + + return true; + + } + }