Example #1
0
 /**
  * (返回更新的记录数) userPowerUpdate :
  * @param $currentUID   integer 当前登录的用户ID
  * @param $setUID       integer 需要设置单位权限的用户ID
  * @param $permission   integer 单位权限级别
  * @param $unitcode     string  单位编码
  * @param int $type             更新类型
  * @return 返回更新的记录数
  * @throws \yii\db\Exception
  */
 private function userPowerUpdate($currentUID, $setUID, $permission, $unitcode, $type = self::UPDATE_SELF)
 {
     /** @var $result 返回更新的记录数*/
     $result = 0;
     /** @var $adminRole string 在Preferences中配置,classmark:sSystem */
     $adminRole = Preferences::get('sSystem', 'adminRole');
     //超级管理员
     /** @var $role \yii\rbac\Role[] 当前用户角色数组*/
     $role = Yii::$app->authManager->getRolesByUser(Yii::$app->user->identity->id);
     /** @var $is_admin boolean 是否为超级管理员*/
     $is_admin = array_key_exists($adminRole, $role);
     $unitlist = $unitcode;
     switch ($type) {
         case self::UPDATE_CHILDLIST:
             $unitlist = Unit::getChildList($unitcode);
             break;
         case self::UPDATE_PARENTLIST:
             $unitlist = Unit::getParentList($unitcode);
             break;
     }
     $SQL = "REPLACE INTO `map_unit`(`user_id`, `unitcode`, `user_power`) " . " SELECT {$setUID}, cur_mu.unitcode, CASE WHEN cur_mu.user_power >= :user_power THEN :user_power ELSE cur_mu.user_power END FROM " . " (SELECT unitcode, user_power FROM `map_unit` WHERE `user_id` = :currentUID AND FIND_IN_SET(unitcode,:unitlist)) cur_mu " . " LEFT JOIN (SELECT unitcode, user_power FROM `map_unit` WHERE `user_id` = :setUID ) set_mu ON (cur_mu.unitcode = set_mu.unitcode) " . " WHERE (set_mu.user_power <= cur_mu.user_power and set_mu.user_power <> :user_power or set_mu.user_power IS NULL)";
     //超级管理员
     if ($is_admin) {
         $SQL = "REPLACE INTO `map_unit`(`user_id`, `unitcode`, `user_power`) " . " SELECT {$setUID}, u.unitcode, {$permission} FROM " . " (SELECT unitcode FROM `unit` WHERE FIND_IN_SET(unitcode,:unitlist)) u " . " LEFT JOIN (SELECT unitcode, user_power FROM `map_unit` WHERE `user_id` = :setUID ) set_mu ON (u.unitcode = set_mu.unitcode) " . " WHERE :currentUID > 0 and (set_mu.user_power <> :user_power or set_mu.user_power IS NULL)";
     }
     $result = Yii::$app->db->createCommand($SQL)->bindValues([':currentUID' => $currentUID, ':user_power' => $permission, ':unitlist' => $unitlist, ':setUID' => $setUID])->execute();
     if ($permission == MapUnit::USER_POWER_DENY) {
         //清除禁止访问的
         MapUnit::deleteAll(['user_power' => MapUnit::USER_POWER_DENY]);
     }
     return $result;
 }
Example #2
0
 /**
  * (void) actionSummary : 一个单位或部门的情况概述.
  * @param string $unit 单位编码
  * @return string
  */
 public function actionSummary($unit = '%')
 {
     //前三个月日期
     $dateThreeMonthAgo = date('Ymd', mktime(0, 0, 0, date("m") - 3, date("d"), date("Y")));
     $unitlist = Unit::getChildList($unit);
     //总人数
     $num1 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0])->count(1);
     //流动人口
     $num2 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0])->andFilterWhere(['<>', 'flag', '01'])->count(1);
     //已婚男性
     $num3 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0, 'sex' => '01'])->andFilterWhere(['<>', 'marry', '10'])->count(1);
     //已婚女性
     $num4 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0, 'sex' => '02'])->andFilterWhere(['<>', 'marry', '10'])->count(1);
     //未婚男性
     $num5 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0, 'sex' => '01', 'marry' => '10'])->count(1);
     //未婚女性
     $num6 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0, 'sex' => '02', 'marry' => '10'])->count(1);
     //已婚未育
     $num7 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0, 'childnum' => 0])->andFilterWhere(['<>', 'marry', '10'])->count(1);
     //已婚育一孩
     $num8 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0, 'childnum' => 1])->andFilterWhere(['<>', 'marry', '10'])->count(1);
     //已婚育二孩
     $num9 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0, 'childnum' => 2])->andFilterWhere(['<>', 'marry', '10'])->count(1);
     //已婚育三孩+
     $num10 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0])->andFilterWhere(['<>', 'marry', '10'])->andFilterWhere(['>=', 'childnum', '3'])->count(1);
     //近三个月内新入职
     $num11 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['logout' => 0])->andFilterWhere(['>=', 'ingoingdate', $dateThreeMonthAgo])->count(1);
     //近三个月内离开单位
     $num12 = Personal::find()->where('FIND_IN_SET (unit, :unitlist)', [':unitlist' => $unitlist])->andFilterWhere(['>', 'logout', 0])->andFilterWhere(['>=', 'e_date', $dateThreeMonthAgo])->count(1);
     $data = "总人数为<span data-toggle='tooltip' data-filter='无过滤条件' title='总人数' class='text-red p-extra-filter'> {$num1} </span>人," . "流动人口为<span data-toggle='tooltip' data-filter='流动人口' title='流动人口' class='text-red p-extra-filter'> {$num2} </span>人," . "已婚男性人数为<span data-toggle='tooltip' data-filter='已婚男性' title='已婚男性人数' class='text-red p-extra-filter'> {$num3} </span>人," . "已婚女性人数为<span data-toggle='tooltip' data-filter='已婚女性' title='已婚女性人数' class='text-red p-extra-filter'> {$num4} </span>人," . "未婚男性人数为<span data-toggle='tooltip' data-filter='未婚男性' title='未婚男性人数' class='text-red p-extra-filter'> {$num5} </span>人," . "未婚女性人数为<span data-toggle='tooltip' data-filter='未婚女性' title='未婚女性人数' class='text-red p-extra-filter'> {$num6} </span>人," . "已婚未育<span data-toggle='tooltip' data-filter='已婚未育' title='已婚未育' class='text-red p-extra-filter'> {$num7} </span>人," . "已婚育一孩<span data-toggle='tooltip' data-filter='已婚育一孩' title='已婚育一孩' class='text-red p-extra-filter'> {$num8} </span>人," . "已婚育二孩<span data-toggle='tooltip' data-filter='已婚育二孩' title='已婚育二孩' class='text-red p-extra-filter'> {$num9} </span>人," . "已婚育三孩及以上<span data-toggle='tooltip' data-filter='已婚育三孩及以上' title='已婚育三孩及以上' class='text-red p-extra-filter'> {$num10} </span>人," . "近三个月内新入职<span data-toggle='tooltip' data-filter='近三个月内新入职' title='近三个月内新入职' class='text-red p-extra-filter'> {$num11} </span>人," . "近三个月内离开单位<span data-toggle='tooltip' data-filter='近三个月内离开单位' title='近三个月内离开单位' class='text-red p-extra-filter'> {$num12} </span>人";
     return $data;
 }