于宏哲PHP 9 months ago
parent
commit
b1118c1cd3
  1. 38
      niucloud/app/api/controller/apiController/Course.php
  2. 11
      niucloud/app/api/controller/apiController/CustomerResources.php
  3. 59
      niucloud/app/api/controller/apiController/Statistics.php
  4. 10
      niucloud/app/api/route/route.php
  5. 8
      niucloud/app/common.php
  6. 96
      niucloud/app/service/api/apiService/CourseService.php
  7. 2
      niucloud/app/service/api/apiService/CustomerResourcesService.php

38
niucloud/app/api/controller/apiController/Course.php

@ -27,6 +27,7 @@ class Course extends BaseApiService
//课程列表
public function courseList(Request $request){
$id = $this->member_id;
$data = $this->request->params([
["schedule_date",0]
]);
@ -77,4 +78,41 @@ class Course extends BaseApiService
return success('SUCCESS',(new CourseService())->delStudentCourse($data));
}
public function get_date(){
$data = $this->request->params([
["date",''],
['day','']
]);
return success(( new CourseService() )->getDate($data));
}
public function courseAllList(Request $request){
$data = $this->request->params([
["schedule_date",0]
]);
return success((new CourseService())->listAll($data));
}
public function addSchedule(Request $request){
$data = $this->request->params([
["resources_id",''],
["person_type",''],
["schedule_id",''],
["course_date",''],
["time_slot",'']
]);
return (new CourseService())->addSchedule($data);
}
public function schedule_list(Request $request){
$data = $this->request->params([
["schedule_id",'']
]);
return success((new CourseService())->schedule_list($data));
}
}

11
niucloud/app/api/controller/apiController/CustomerResources.php

@ -175,12 +175,18 @@ class CustomerResources extends BaseApiService
"communication" => $request->param('communication', ''),//沟通备注
"staff_id" => $request->param('staff_id', ''),//人员ID//如果没有就是当前登录人的员工id
"first_visit_status" => $request->param('first_visit_status', null),//一访情况
"second_visit_status" => $request->param('second_visit_status', null),//二访情况
"efficacious" => $request->param('efficacious', 1),
"first_visit_time" => $request->param('first_visit_time', ''),
"first_visit_status" => $request->param('first_visit_status', ''),
"second_visit_time" => $request->param('second_visit_time', ''),
"second_visit_status" => $request->param('second_visit_status', ''),
"chasing_orders" => $request->param('chasing_orders', ''),
"is_bm" => $request->param('is_bm', 1),
"consultation_remark" => $request->param('consultation_remark', ''),
];
if (strlen($customer_resources_data['phone_number']) > 12) {
return fail("联系电话不能超过12位");
}
@ -197,7 +203,6 @@ class CustomerResources extends BaseApiService
}
}
$res = (new CustomerResourcesService())->editData($where, $customer_resources_data, $six_speed_data);
if (!$res['code']) {
return fail($res['msg']);

59
niucloud/app/api/controller/apiController/Statistics.php

@ -11,6 +11,7 @@
namespace app\api\controller\apiController;
use app\model\campus_person_role\CampusPersonRole;
use app\model\market_performance\MarketPerformance;
use app\model\order_table\OrderTable;
use app\model\personnel\PersonnelSummary;
@ -252,6 +253,7 @@ class Statistics extends BaseApiService
{
$resourceSharing = new ResourceSharing();
$customerResources = new CustomerResources();
$campus_person_role = new CampusPersonRole();
$personnel_id = $request->param('personnel_id','');//员工表id
$role_key_arr = $request->param('role_key_arr','');//array 角色key
$role_key_arr = explode(',',$role_key_arr);
@ -264,18 +266,25 @@ class Statistics extends BaseApiService
$assigned = 0;
$unassigned = 0;
$lastWeekNewTotal = 0;
$resource_list = $resourceSharing->where(['shared_by' => $personnel_id])->select();
foreach($resource_list as $item){
$sharedAt = strtotime($item['shared_at']);
$date = date("Y-m-d",$sharedAt);
if(isDateInThisWeek($date)){
$assigned++;
}
}
// $resource_list = $resourceSharing->where(['shared_by' => $personnel_id])->select();
// foreach($resource_list as $item){
// $sharedAt = strtotime($item['shared_at']);
// $date = date("Y-m-d",$sharedAt);
// if(isDateInThisWeek($date)){
// $assigned++;
// }
//
// }
$customer_list = $customerResources->where(['consultant' => $personnel_id])->select();
foreach($customer_list as $item){
if($resourceSharing->where(['resource_id' => $item['id']])->find()){
if(isDateInThisWeek($item['create_date'])){
$assigned++;
}
}
if(!$resourceSharing->where(['resource_id' => $item['id']])->find()){
if(isDateInThisWeek($item['create_date'])){
$unassigned++;
@ -287,18 +296,34 @@ class Statistics extends BaseApiService
}
$staff_list = [];
$personnel_summary = new PersonnelSummary();
$staff_list = $personnel_summary
->alias('a')
->join(['school_campus_person_role' => 'b'],'a.campus_person_role_id = b.id','left')
->join(['school_personnel' => 'c'],'b.person_id = c.id','left')
->field("c.name,a.task_num as goal,a.complete_num as wx_yj")
$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();
if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){
$staff_list = $staff_list->toArray(); // 转换成数组
$customer_list = $customerResources->select();
$goal = count($customer_list);
$staff_map = [];
foreach($staff_list as &$staff){
$staff['goal'] = $goal;
$staff['wx_yj'] = 0;
$staff_map[$staff['id']] = &$staff; // 现在可以引用赋值了
}
foreach ($customer_list as $val){
if(isset($staff_map[$val['consultant']])){
$staff_map[$val['consultant']]['wx_yj']++;
}
}
unset($staff); // 清除引用
if(in_array('market',$role_key_arr) || in_array('market_manager',$role_key_arr)){
//市场人员统计数据(地推拉人头的)
$data = [

10
niucloud/app/api/route/route.php

@ -331,6 +331,15 @@ Route::group(function () {
Route::get('teachingResearch/teachingTestPaper', 'apiController.teachingResearch/teachingTestPaper');
//提交试卷
Route::get('teachingResearch/submitTestPaper', 'apiController.teachingResearch/submitTestPaper');
Route::get('course/get_date', 'apiController.Course/get_date');
Route::get('course/courseAllList', 'apiController.course/courseAllList');
Route::post('course/addSchedule', 'apiController.course/addSchedule');
Route::get('course/scheduleList', 'apiController.course/schedule_list');
})->middleware(ApiChannel::class)
->middleware(ApiPersonnelCheckToken::class, true)
->middleware(ApiLog::class);
@ -408,7 +417,6 @@ Route::group(function () {
})->middleware(ApiChannel::class)
->middleware(ApiCheckToken::class, true)
->middleware(ApiLog::class);

8
niucloud/app/common.php

@ -1293,3 +1293,11 @@ function isDateInLastWeek($date) {
return $timestamp >= $startOfLastWeek && $timestamp <= $endOfLastWeek;
}
function getChineseWeekday($date)
{
$weekdays = ['日', '一', '二', '三', '四', '五', '六'];
return '星期' . $weekdays[$date->format('w')];
}

96
niucloud/app/service/api/apiService/CourseService.php

@ -19,6 +19,7 @@ use app\model\assignment\Assignment;
use app\model\course\Course;
use app\model\student_courses\StudentCourses;
use core\base\BaseApiService;
use DateTime;
use think\Model;
use think\facade\Db;
@ -217,6 +218,101 @@ class CourseService extends BaseApiService
}
}
public function getDate(array $baseDate)
{
$dates = [];
$this_date = $baseDate['date'] ?: date('Y-m-d');
$date = new DateTime($this_date);
for ($i = -2; $i <= 4; $i++) {
$tempDate = clone $date; // 避免修改原始对象
$tempDate->modify("$i days");
$status = false;
if($baseDate['day'] == $tempDate->format('d')){
$status = true;
}else if(empty($baseDate['day'])){
if($tempDate->format('Y-m-d') === date('Y-m-d')){
$status = true;
}
}
$dates[] = [
'date' => $tempDate->format('Y-m-d'),
'day' => $tempDate->format('d'),
'week' => getChineseWeekday($tempDate),
'status' => $status
];
}
return ['dates' => $dates,'date' => $this_date];
}
public function listAll($data)
{
$where = [];
if ($data['schedule_date']) {
$where[] = ['course_date','=', $data['schedule_date']];
}
$CourseSchedule = new CourseSchedule();
$list = $CourseSchedule
->where($where)
->with(['course' => function($query) {
$query->select();
},'venue' => function($query) {
$query->select();
},'campus','studentCourses'])->select()->toArray();
foreach ($list as $k => $v) {
$student = Db::name('person_course_schedule')
->alias('pcs')
->where('pcs.schedule_id', $v['id']) // 建议加上表别名避免冲突
->join('school_student st', 'pcs.student_id = st.id')
->join('school_customer_resources cr', 'st.user_id = cr.id')
->join('school_member sm', 'cr.member_id = sm.member_id')
->field('st.name, sm.headimg as avatar') // 👈 正确方式取字段
->select();
$list[$k]['student'] = $student;
}
return $list;
}
public function addSchedule(array $data){
$CourseSchedule = new CourseSchedule();
$personCourseSchedule = new PersonCourseSchedule();
if($personCourseSchedule->where([
'resources_id' => $data['resources_id'],
'schedule_id' => $data['schedule_id']
])->find()){
return fail("重复添加");
}
$personCourseSchedule->insert([
'resources_id' => $data['resources_id'],
'person_id' => $this->member_id,
'person_type' => $data['person_type'],
'schedule_id' => $data['schedule_id'],
'course_date' => $data['course_date'],
'time_slot' => $data['time_slot'],
]);
$CourseSchedule->where(['id' => $data['schedule_id']])->dec("available_capacity")->update();
return success("添加成功");
}
public function schedule_list(array $data){
$personCourseSchedule = new PersonCourseSchedule();
$list = $personCourseSchedule
->alias('a')
->join(['school_customer_resources' => 'b'],'a.resources_id = b.id','left')
->where('a.schedule_id',$data['schedule_id'])
->field("b.name,a.status")
->select()->toArray();
return $list;
}
}

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

@ -315,7 +315,7 @@ class CustomerResourcesService extends BaseApiService
return $res;
} catch (\Exception $exception) {
Db::rollback();
return $res;
return $exception->getMessage();
}
}

Loading…
Cancel
Save