123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- namespace app\admin\controller\statistics;
- use app\admin\controller\Base;
- use app\admin\extend\screen\TimeHandle;
- use app\common\model\base\org\Org;
- use app\common\model\base\org\OrgType;
- use app\common\model\base\user\UserRole;
- use app\common\model\enroll\EnrollStudents;
- use app\common\model\enroll\JdfEnrollVolunteer;
- use daorui\platform\platformAuth;
- class Statistics extends Base
- {
- protected $noNeedLogin = [];
- protected $noNeedAuth = [];
- public function initialize()
- {
- parent::initialize();
- }
-
- public function getOrgList()
- {
- $userinfo = $this->userinfo;
- $SchoolCode = (new platformAuth())->interfaceRequest('getSchoolCode', []);
- $codes = array_column($SchoolCode['data'], 'code');
- if (!$userinfo['is_developer']) {
- $org_ids =$this->userinfo['org_id'];
- $where = [];
- $where[] = ['type', 'IN', $codes];
- if($org_ids!==1){
- $where[] = ['org_id', 'IN', $org_ids];
- }
- $list = Org::where($where)->field("org_id,name,type")->select();
- } else {
- $list = Org::where('type', 'IN', $codes)->field("org_id,name,type")->select();
- }
- return res(1, '获取成功', $list);
- }
-
- public function orderNumCount()
- {
- $data = $this->request->param();
- $where = [];
- $SchoolCode = (new platformAuth())->interfaceRequest('getSchoolCode', []);
- $codes = array_column($SchoolCode['data'], 'code');
- $timeMode = 'Y-m-d H:i:s';
- $x = [];
- $userinfo = $this->userinfo;
- if (empty($data['type'])) {
- $data['type'] = 1;
- }
- switch ($data['type']) {
- case 1:
-
- $timeData = TimeHandle::getSrceenSE("", 1, $timeMode);
- $x = TimeHandle::getChartX($timeData['s'], $timeData['e'], 2)['x'];
-
- $where[] = ['b.create_at', '>=', $timeData['s']];
- $where[] = ['b.create_at', '<=', $timeData['e']];
- break;
- case 2:
-
- $timeData = TimeHandle::getSrceenSE("", 2, $timeMode);
- $x = TimeHandle::getChartX($timeData['s'], $timeData['e'], 2)['x'];
-
- $where[] = ['b.create_at', '>=', $timeData['s']];
- $where[] = ['b.create_at', '<=', $timeData['e']];
- break;
- }
- if (!$userinfo['is_developer']) {
- $org_ids = UserRole::where('user_id', $this->userinfo['user_id'])->column("org_id");
- $types = Org::where('org_id', 'IN', $org_ids)->field("org_id,name,type")->column("type");
-
- $types = array_unique($types);
- $where[] = ['b.stage_code', 'IN', $types];
- if (!in_array(1, $org_ids)) {
- $where[] = ['a.org_id', 'IN', $org_ids];
- }
- } else {
- $where[] = ['b.stage_code', 'IN', $codes];
- }
- if (!empty($data['org_id'])) {
- $where[] = ['a.org_id', '=', $data['org_id']];
- }
- $list = JdfEnrollVolunteer::alias('a')
- ->join('jdf_enroll_students b', 'a.enroll_id=b.enroll_id')
- ->where($where)
- ->field('a.org_id,b.semester_date,b.create_at,b.stage_code,count(*) as value')
- ->group('DATE(b.create_at),b.stage_code')->select()->toArray();
- $arr_code = array_column($list, 'stage_code');
- $arr_code = array_unique($arr_code);
- $typeList = OrgType::where('code', 'IN', $arr_code)->field("org_type_name as name,code")->select();
-
- $initialData = [];
- foreach ($x as $date) {
- foreach ($arr_code as $code) {
- if (!isset($initialData[$code])) {
- $initialData[$code] = [];
- }
- $initialData[$code][$date] = 0;
- }
- }
-
- foreach ($list as $item) {
- $date = date('Y-m-d', strtotime($item['semester_date']));
- $date = TimeHandle::beginToday(2, $date, 'd') . '号';
- $stageCode = $item['stage_code'];
- $value = $item['value'];
- $initialData[$stageCode][$date] = $value;
- }
-
- $typeData = [];
- foreach ($initialData as $stageCode => $dailyData) {
- $values = array_values($dailyData);
- $typeData[$stageCode] = $values;
- }
- return res(1, '获取成功', ['x' => $x, 'data' => $typeData, 'type' => $typeList]);
- }
-
- public function orderSexCount()
- {
- $org_id = input('org_id/d', 0);
- $where = [];
- $userinfo = $this->userinfo;
- if (!$userinfo['is_developer']) {
- $org_ids = UserRole::where('user_id', $userinfo['user_id'])->column("org_id");
- if (!in_array(1, $org_ids)) {
- $where[] = ['a.org_id', 'IN', $org_ids];
- }
- }
- if (!empty($org_id)) {
- $where[] = ['a.org_id', '=', $org_id];
- }
- $list = JdfEnrollVolunteer::alias('a')
- ->join('jdf_enroll_students b', 'a.enroll_id=b.enroll_id')
- ->where($where)
- ->field('a.org_id,b.sex,count(*) as value')
- ->group('b.sex')
- ->select()
- ->toArray();
- if ($list) {
-
- $total = array_sum(array_column($list, 'value'));
- foreach ($list as $k => &$v) {
- $list[$k]['name'] = $v['sex'] == 1 ? '男' : '女';
- $v['percentage'] = round(($v['value'] / $total) * 100, 2);
- }
-
- unset($v);
- } else {
- $list = [];
- }
- return res(1, '获取成功', $list);
- }
- }
|