示例#1
0
文件: Soldier.php 项目: Sywooch/armin
 public function getUnitLink()
 {
     if ($this->unit) {
         $p = Unit::findOne($this->unit);
         if ($p) {
             return Html::a(Html::encode($p->name), ['/unit/view', 'id' => $p->id]);
         }
     }
 }
示例#2
0
 public function selectOptions()
 {
     $query = Unit::find();
     $arr = $query->select(['unit.id', 'unit.name', 'soldier.name sn', 'soldier.nickname'])->leftJoin('soldier', 'unit.soldier = soldier.id')->asArray()->all();
     $units = ['' => 'Обрати'];
     foreach ($arr as $unit) {
         $units[$unit['id']] = "{$unit['name']} / {$unit['nickname']} ({$unit['sn']})";
     }
     return $units;
 }
示例#3
0
文件: Item.php 项目: Sywooch/armin
 public function getAttachedToLink()
 {
     if (Attachment::isStorehouse($this->attached_to)) {
         return 'На складі';
     }
     if (Attachment::isRepaired($this->attached_to)) {
         return 'В ремонті';
     }
     if (Attachment::isSoldier($this->attached_to)) {
         $soldier = Soldier::findOne($this->attached_to_soldier);
         return Html::a(Html::encode("Службовець: {$soldier->nickname} ({$soldier->name})"), ['/soldier/view', 'id' => $soldier->id]);
     }
     if (Attachment::isUnit($this->attached_to)) {
         $unit = Unit::findOne($this->attached_to_unit);
         $soldier = Soldier::findOne($unit->soldier);
         return Html::a(Html::encode("Підрозділ: {$unit->name} ({$soldier->nickname}({$soldier->name}))"), ['/unit/view', 'id' => $unit->id]);
     }
     return 'undefined';
 }
示例#4
0
 /**
  * (void) validateAttribute : 校验当前用户是否取得单位编码的完全访问权限
  * @param \yii\base\Model $model
  * @param string $attribute
  */
 public function validateAttribute($model, $attribute)
 {
     /** @var integer $user_id 当前用户ID */
     $user_id = Yii::$app->user->identity->id;
     /** @var string $unitcode 校验单位编码 */
     $unitcode = $model->{$attribute};
     switch ($attribute) {
         case 'unitcode':
             //修改
             if (Unit::findOne(['unitcode' => $unitcode]) && MapUnit::getUserPower($user_id, $unitcode) != MapUnit::USER_POWER_ALLOW) {
                 $this->addError($model, $attribute, '你没有单位(部门)『' . $unitcode . '』的『完全访问』权限.');
             }
             break;
         case 'upunitcode':
             //新增
             if (!Unit::findOne(['upunitcode' => $unitcode]) && MapUnit::getUserPower($user_id, $unitcode) < MapUnit::USER_POWER_VIEW_DEPT) {
                 $this->addError($model, $attribute, '你没有单位(部门)『' . $unitcode . '』的『完全访问』权限.');
             }
             break;
     }
 }
示例#5
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;
 }
示例#6
0
 /**
  * Finds the Unit model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param $unitcode
  * @return Unit the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($unitcode)
 {
     if (($model = Unit::findOne(['unitcode' => $unitcode])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('数据获取失败..');
     }
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUnit()
 {
     return $this->hasOne(Unit::className(), ['id' => 'unit_id']);
 }
示例#8
0
 /**
  * Finds the Unit model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Unit the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Unit::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#9
0
 public function actionGetFieldConfig()
 {
     //传过来的数据格式为 pbc_tnam.pbc_cnam
     $params = Yii::$app->request->post('params', '');
     $config = [];
     if ($params) {
         $paramArr = explode('.', $params);
         if (count($paramArr) == 2) {
             $pbc_tnam = $paramArr[0];
             $pbc_cnam = $paramArr[1];
             $classmark = ColTable::getClassmark($pbc_tnam, $pbc_cnam);
             $data = $classmark ? Preferences::getByClassmark($classmark) : [];
             if ($pbc_cnam == 'unit') {
                 $data = Unit::getUnitcodeToUnitnameList();
             }
         }
     }
     if (count($data)) {
         foreach ($data as $key => $value) {
             $tmp['id'] = $key;
             $tmp['text'] = $value;
             $config[] = $tmp;
         }
     }
     return count($config) ? Json::encode($config) : '';
 }
示例#10
0
文件: Unit.php 项目: tqsq2005/Yii2adv
 /**
  * (array|\yii\db\ActiveRecord[]) getChildren : 根据用户权限获取下级信息
  * @param $id
  * @return array|\yii\db\ActiveRecord[]
  */
 public function getChildren($id)
 {
     $user_id = Yii::$app->user->identity->id;
     $data = Unit::find()->select(['id' => 'unit.unitcode', 'text' => 'unit.unitname'])->innerJoin('map_unit', '`map_unit`.`unitcode` = `unit`.`unitcode`')->andFilterWhere(['map_unit.user_id' => $user_id])->andFilterWhere(['unit.upunitcode' => $id == '0' ? '%' : $id])->orderBy(['unit.order_num' => SORT_ASC, 'unit.unitcode' => SORT_ASC])->asArray()->all();
     if (count($data) > 0) {
         foreach ($data as &$arr) {
             $arr['children'] = $this->isParent($arr['id']);
             $arr['icon'] = $arr['children'] ? 'fa fa-folder text-yellow' : 'fa fa-star-half-o text-success';
             $arr['id'] = $arr['id'] == '%' ? '0' : $arr['id'];
             $arr['url'] = Url::to(['detail', 'id' => $arr['id']]);
         }
     }
     return $data;
 }
示例#11
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;
 }