Exemplo n.º 1
0
 /**
  * 将加入service team的次要的supernova用户设置为primary loan officer    
  * @param integer $id
  * @return mixed
  */
 public function actionPrimary($id)
 {
     $model = $this->findModel($id);
     $model->is_primary_service_member = Dict::BD_PRIMARY_MEMBER_YES;
     /**
      * 如果选择了设置为primary loan officer,则将其他的自动调回不是primary
      */
     $result = Betterdebt::updateAll(['is_primary_service_member' => Dict::BD_PRIMARY_MEMBER_NOT], "id_betterdebt not in ({$id}) ");
     if ($result != 0) {
         //$result 返回的被修改的行数
         $model->save();
     }
     return $this->redirect(['index']);
 }
Exemplo n.º 2
0
 public function UserUpdate($role, $content, $id)
 {
     switch ($role) {
         case Dict::USER_ROLE_BETTERDEBT:
             $model = new Betterdebt();
             $modelkey = "Betterdebt";
             break;
         case Dict::USER_ROLE_ADVISOR:
             $model = new Advisor();
             $modelkey = "Advisor";
             break;
         case Dict::USER_ROLE_CLIENT:
             $model = new Client();
             $modelkey = "Client";
             break;
         case Dict::USER_ROLE_BANK:
             $model = new BankUser();
             $modelkey = "BankUser";
             break;
         default:
             break;
     }
     if (empty($content['id_group'])) {
         $content['id_group'] = [];
     }
     $model = $model::findOne($id);
     $user = static::find()->where(['id_user' => $model->id_user])->one();
     $userOld = static::find()->where(['id_user' => $model->id_user])->one();
     //事务开始
     $transaction = Yii::$app->db->beginTransaction();
     //保存到用户信息主表
     if (isset($content['User']['email'])) {
         $email = $content['User']['email'];
     } elseif (isset($content['User']['new_email'])) {
         $email = $content['User']['new_email'];
     }
     foreach ($content['User'] as $key => $value) {
         $user->{$key} = $value;
     }
     if ($userOld['email'] != $email) {
         $user->email = $userOld['email'];
         $user->new_email = $email;
         // 发送修改邮件的email
         if (!$this->changEmail($user)) {
             $this->_istrue = false;
         }
     }
     if (!$user->save()) {
         $this->_istrue = false;
     }
     //保存到用户信息表(advisor/client/betterdebt/bank_user)
     foreach ($content[$modelkey] as $key => $value) {
         $model->{$key} = $value;
         if ($key == 'date_of_birth' || $key == 'identification_expiration_date') {
             $model->{$key} = strtotime($value);
         }
     }
     if (!$model->save()) {
         $this->_istrue = false;
     }
     if ($modelkey == "Betterdebt") {
         if (empty($model->is_primary_service_member)) {
             //判断是否设置为primary loan officer
             $model->is_primary_service_member = Dict::BD_PRIMARY_MEMBER_NOT;
         } else {
             /**
              * 如果选择了设置为primary loan officer,则将其他的自动调回不是primary
              */
             $rows = Betterdebt::updateAll(['is_primary_service_member' => Dict::BD_PRIMARY_MEMBER_NOT], "id_betterdebt not in ({$model->id_betterdebt}) ");
         }
     }
     //修改advisor时特有的
     $advisorGroups = AdvisorGroup::findAll(['id_advisor' => $id]);
     $groupArray = ArrayHelper::map($advisorGroups, 'id_group', 'id_group');
     $delgroupArray = array_diff($groupArray, $content['id_group']);
     foreach ($delgroupArray as $delGroupId) {
         $advisorGroup = AdvisorGroup::findOne(['id_group' => $delGroupId, 'id_advisor' => $model->primaryKey]);
         $advisorGroup->delete = 1;
         if (!$advisorGroup->save()) {
             //$this->_istrue = false;
         }
     }
     /*
             $advisorgroup_del = new AdvisorGroup();
             if ($advisorgroup_del->findAll(['id_advisor' => $id])){
        if (!$advisorgroup_del->deleteAll(['id_advisor' => $id])){
            $this->_istrue = false;
        }
             }
     */
     if (!empty($content['id_group'])) {
         $addAdvisorGroupArray = array_diff($content['id_group'], $groupArray);
         $advisorgroup = new AdvisorGroup();
         $advisorgroup->id_advisor = $model->primaryKey;
         foreach ($addAdvisorGroupArray as $key => $value) {
             $insertadvisorgroup = clone $advisorgroup;
             $insertadvisorgroup->id_group = $value;
             if (!$insertadvisorgroup->save()) {
                 $this->_istrue = false;
             }
         }
     }
     //事务结束提交
     if ($this->_istrue) {
         $transaction->commit();
         return true;
     } else {
         $transaction->rollback();
         return false;
     }
 }