<commit_before><?php

class CustomerassController extends GController
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	//public $layout='//layouts/column2';

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			//'postOnly + delete', // we only allow deletion via POST request
		);
	}


	/**
	 * Displays a particular model.
	 * @param integer $id the ID of the model to be displayed
	 */
	public function actionView($id)
	{
		$this->render('view',array(
			'model'=>$this->loadModel($id),
		));
	}

	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionAssign()
	{
		$model=new CustomerAss;
		$deptArr = Userinfo::getDept();
		$deptArr = array_merge(array('0'=>'--请选择部门--'), $deptArr);
		$category = Userinfo::getCategory();//类目
		$ids = Yii::app()->request->getParam('ids');
		$model->ids = $ids;
		if(isset($_POST['CustomerAss']))
		{
			$model->attributes=$_POST['CustomerAss'];
			$eno = $model->eno;
			$enoNum = Yii::app()->db->createCommand("select cust_num from {{users}} where eno=:eno")->queryAll(TRUE,array(":eno"=>$eno));
			$enoNum = $enoNum ? (int)$enoNum[0]['cust_num'] : 0;//该用户已分配的资源数
			$assCount = explode(',', $model->ids);
			$assCount = count($assCount);//待分配的资源个数
			if( ($assCount + $enoNum) > 300 ){//每个用户的分配资源数不能超过300个
				exit("<script>alert(\"对不起, 该用户当前已分配了".$enoNum."个资源, 每个用户最多只能分配300个资源, 本次操作失败。\");javascript:history.go(-1);</script>");
			}
			else{
				if(empty($eno))
				{
					exit("<script>alert(\"对不起, 您没有选择被分配人, 本次操作失败。\");javascript:history.go(-1);</script>");
				}
				$assign_eno = Yii::app()->session['user']['eno'];
				$assign_time = time();
				$sql = "update {{customer_info}} set eno='$eno',assign_time=$assign_time,assign_eno='$assign_eno' where id in({$model->ids})";
				$sql2 = "update {{users}} set cust_num=cust_num+$assCount where eno='{$model->eno}'";
				$transaction = Yii::app()->db->beginTransaction();
				try {
					$res = Yii::app()->db->createCommand($sql)->execute();
					$res2 = Yii::app()->db->createCommand($sql2)->execute();
					$transaction->commit();
					exit("<script>alert(\"恭喜你, 成功分配了".$assCount."个资源。\");javascript:history.go(-1);</script>");	
				} catch (Exception $exc) {
					$transaction->rollBack();//事务回滚
					exit("<script>alert(\"对不起, 由于未知的错误, 本次操作失败, 请重新操作。\");javascript:history.go(-1);</script>");
				}
			}
		}
		$this->renderPartial('assign_form',array(
			'model'=>$model,
			'deptArr'=>$deptArr,
			'category'=>$category,
		));
	}

	public function actionGetGroup(){
		$deptid = yii::app()->request->getparam('deptid');
		$deptinfo = Userinfo::getGroupById($deptid);
		echo json_encode($deptinfo);
	}

	public function actiongetUsers()
	{
		$gid = Yii::app()->request->getparam('gid');
                $deptid = Yii::app()->request->getparam('deptid');
		$userinfo = Userinfo::getUserbygid($gid, $deptid);
		echo json_encode($userinfo);
	}
<commit_msg>客户资源分配BUG修复<commit_after><?php

class CustomerassController extends GController
{
	/**
	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
	 * using two-column layout. See 'protected/views/layouts/column2.php'.
	 */
	//public $layout='//layouts/column2';

	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return array(
			'accessControl', // perform access control for CRUD operations
			//'postOnly + delete', // we only allow deletion via POST request
		);
	}


	/**
	 * Displays a particular model.
	 * @param integer $id the ID of the model to be displayed
	 */
	public function actionView($id)
	{
		$this->render('view',array(
			'model'=>$this->loadModel($id),
		));
	}

	/**
	 * Creates a new model.
	 * If creation is successful, the browser will be redirected to the 'view' page.
	 */
	public function actionAssign()
	{
		$model=new CustomerAss;
		$deptArr = Userinfo::getDept();
		$deptArr = array_merge(array('0'=>'--请选择部门--'), $deptArr);
		$category = Userinfo::getCategory();//类目
		$ids = Yii::app()->request->getParam('ids');
		$model->ids = $ids;
		if(isset($_POST['CustomerAss']))
		{
			$model->attributes=$_POST['CustomerAss'];
			$eno = $model->eno;
			$enoNum = Yii::app()->db->createCommand("select cust_num from {{users}} where eno=:eno")->queryAll(TRUE,array(":eno"=>$eno));
			$enoNum = $enoNum ? (int)$enoNum[0]['cust_num'] : 0;//该用户已分配的资源数
			$assCount = explode(',', $model->ids);
			$assCount = count($assCount);//待分配的资源个数
			if( ($assCount + $enoNum) > 300 ){//每个用户的分配资源数不能超过300个
				exit("<script>alert(\"对不起, 该用户当前已分配了".$enoNum."个资源, 每个用户最多只能分配300个资源, 本次操作失败。\");javascript:history.go(-1);</script>");
			}
			else{
				if(empty($eno))
				{
					exit("<script>alert(\"对不起, 您没有选择被分配人, 本次操作失败。\");javascript:history.go(-1);</script>");
				}
				$allocation = Yii::app()->db->createCommand("select id from {{customer_info}} where eno='$eno'")->queryAll();//已分配的
				if($allocation){
					$alArr = array();
					foreach ($allocation as $k1=>$v1){
						$alArr[] = $v1['id'];
					}
					
					$idArr = explode(',', $model->ids);
					//$intersectArr = array_intersect($alArr, $idArr);//取出已分配给该员工的客户ID
					$diffArr = array_diff($idArr, $alArr);
					if($diffArr){
						$model->ids = implode(',', $diffArr);
						$assCount = count($diffArr);//待分配的资源个数
					}
					else{
						$model->ids = 0;
						$assCount = 0;//待分配的资源个数
					}
				}
				$assign_eno = Yii::app()->session['user']['eno'];
				$assign_time = time();
				$sql = "update {{customer_info}} set eno='$eno',assign_time=$assign_time,assign_eno='$assign_eno' where id in({$model->ids})";
				$sql2 = "update {{users}} set cust_num=cust_num+$assCount where eno='{$model->eno}'";
				/////////////分配资源的时候原所属工号减1/////////
				if($model->ids){
					$reduce = explode(',', $model->ids);
					$reduceArr = array();
					foreach ($reduce as $k2=>$v2){
						$result = Customerass::model()->findByPk($v2);
						$beEno = $result->getAttribute('eno');
						if($result){
							$reduceArr[] = "update {{users}} set cust_num=cust_num-1 where eno='$beEno'";
						}
					}
				}
				///////////////////////////////////////////////////
				$transaction = Yii::app()->db->beginTransaction();
				try {
					$res = Yii::app()->db->createCommand($sql)->execute();
					$res2 = Yii::app()->db->createCommand($sql2)->execute();
					if($reduceArr){
						foreach ($reduceArr as $k3=>$v3){
							Yii::app()->db->createCommand($v3)->execute();
						}
					}
					$transaction->commit();
					exit("<script>alert(\"恭喜你, 成功分配了".$assCount."个资源。\");javascript:history.go(-1);</script>");	
				} catch (Exception $exc) {
					$transaction->rollBack();//事务回滚
					exit("<script>alert(\"对不起, 由于未知的错误, 本次操作失败, 请重新操作。\");javascript:history.go(-1);</script>");
				}
			}
		}
		$this->renderPartial('assign_form',array(
			'model'=>$model,
			'deptArr'=>$deptArr,
			'category'=>$category,
		));
	}

	public function actionGetGroup(){
		$deptid = yii::app()->request->getparam('deptid');
		$deptinfo = Userinfo::getGroupById($deptid);
		echo json_encode($deptinfo);
	}

	public function actiongetUsers()
	{
		$gid = Yii::app()->request->getparam('gid');
                $deptid = Yii::app()->request->getparam('deptid');
		$userinfo = Userinfo::getUserbygid($gid, $deptid);
		echo json_encode($userinfo);
	}

{'fraction_non_alphanumeric': 0.21705529646902066, 'fraction_numerical': 0.007594936708860759, 'mean_word_length': 3.7148241206030153, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '828244', 'n_tokens_mistral': 3235, 'n_tokens_neox': 2872, 'n_words': 461}