Exemplo n.º 1
0
 /**
 * 根据品牌ID对beu_brand表中数据的数据进行修改
 * @param $id:int 品牌id 默认0
 * @param $arr:Array 其内容如下
 * logoimgpath:string(255) (可不填,品牌图片)
 		telephone:string(255) (可不填,品牌电话)
 		address:string(255) (可不填,品牌地址)
 		fax:string(255) (可不填,传真)
 		website:string(255) (可不填,网站地址:http://dfa.com)
 		companyname:string(255) (可不填,公司名)
 		status:int (可不填,是否显示,默认为1。参数值也只能为1或2)
 		createdate:string(10) (可不填,创建时间)
 		code_start:款号规则开始位置
 		code_end:款号规则结束位置
 * @return 如果修改数据成功返回true
 * 否则返回false
 */
 public static function brandUpdateById($id = 0, $arr = array())
 {
     $id = trim($id);
     try {
         Comm::checkValue($id, Yii::t('public', '品牌号'), 1, 1);
     } catch (BeubeuException $e) {
         throw new BeubeuException($e->getMessage(), $e->getCode());
     }
     if (count($arr) > 0 && gettype($arr) == 'array') {
         $updata_arr = array();
         if (isset($arr['englishname'])) {
             try {
                 $englishname = trim($arr['englishname']);
                 Comm::checkValue($englishname, Yii::t('beu_brand', '品牌英文名'), 0, 1, 255);
                 $updata_arr['englishname'] = $englishname;
             } catch (BeubeuException $e) {
             }
         }
         if (isset($arr['name'])) {
             try {
                 $name = trim($arr['name']);
                 Comm::checkValue($name, Yii::t('beu_brand', '品牌名'), 0, 1, 255);
                 $updata_arr['name'] = $name;
             } catch (BeubeuException $e) {
                 throw new BeubeuException($e->getMessage(), $e->getCode());
             }
         }
         if (isset($arr['logoimgpath'])) {
             try {
                 $logoimgpath = trim($arr['logoimgpath']);
                 Comm::checkValue($logoimgpath, Yii::t('beu_brand', '公司地址'), 0, 0, 255);
                 $updata_arr['logoimgpath'] = $logoimgpath;
             } catch (BeubeuException $e) {
             }
         }
         if (isset($arr['telephone'])) {
             //公司电话字段存在,并且长度不超过255
             try {
                 $telephone = trim($arr['telephone']);
                 Comm::phoneToSingle($telephone, Yii::t('beu_brand', '电话号码'));
                 $updata_arr['telephone'] = $telephone;
             } catch (BeubeuException $e) {
             }
         }
         if (isset($arr['address'])) {
             //公司地址字段存在,并且长度不超过255
             try {
                 $address = trim($arr['address']);
                 Comm::checkValue($address, Yii::t('beu_brand', '公司地址'), 0, 0, 255);
                 $updata_arr['address'] = $address;
             } catch (BeubeuException $e) {
             }
         }
         if (isset($arr['fax'])) {
             //传真字段存在,并且长度不超过255
             try {
                 $fax = trim($arr['fax']);
                 Comm::phoneToSingle($fax, Yii::t('beu_brand', '传真'));
                 $updata_arr['fax'] = $fax;
             } catch (BeubeuException $e) {
             }
         }
         if (isset($arr['website'])) {
             //网站地址字段存在,并且长度不超过255
             try {
                 $website = trim($arr['website']);
                 Comm::checkValue($website, Yii::t('beu_brand', '网站地址'), 0, 0, 255);
                 $updata_arr['website'] = $website;
             } catch (BeubeuException $e) {
             }
         }
         if (isset($arr['companyname']) && !empty($arr['companyname']) && strlen($arr['companyname']) <= 255) {
             //公司名字段存在,并且长度不超过255
             try {
                 $companyname = trim($arr['companyname']);
                 Comm::checkValue($companyname, Yii::t('beu_brand', '公司名称'), 0, 0, 255);
                 $updata_arr['companyname'] = $companyname;
             } catch (BeubeuException $e) {
             }
         }
         if (!isset($arr['code_start']) || intval($arr['code_start']) != $arr['code_start']) {
             $updata_arr['code_start'] = 0;
         } else {
             $updata_arr['code_start'] = $arr['code_start'];
         }
         if (!isset($arr['code_end']) || intval($arr['code_end']) != $arr['code_end']) {
             $updata_arr['code_end'] = 0;
         } else {
             $updata_arr['code_end'] = $arr['code_end'];
         }
         if (isset($arr['status']) && !empty($arr['status']) && trim($arr['status']) == 11) {
             //显示状态字段存在,并且为2表示不显示
             $updata_arr['status'] = 11;
             //不显示
         } else {
             if (isset($arr['status']) && !empty($arr['status']) && trim($arr['status']) == 10) {
                 $updata_arr['status'] = 10;
                 //显示
             }
         }
         if (isset($arr['angle']) && !empty($arr['angle']) && intval($arr['angle']) == $arr['angle'] && $arr['angle'] > 0) {
             //衣服支持的角度
             $updata_arr['angle'] = $arr['angle'];
         }
         if (isset($arr['model'])) {
             //衣服支持的角度
             $updata_arr['model_type'] = $arr['model'];
         }
         if (isset($arr['createdate']) && !empty($arr['createdate'])) {
             //时间字段存在并格式正确
             try {
                 $createdate = trim($arr['createdate']);
                 Comm::dataSingle($createdate, Yii::t('beu_brand', '添加时间'), false);
                 $updata_arr['createdate'] = $createdate;
             } catch (BeubeuException $e) {
             }
         }
         $img = self::brandImgUp($id);
         if ($img) {
             $img = json_decode($img, true);
             try {
                 $updata_arr['logoimgpath'] = $img['brand']['img'];
             } catch (Exception $e) {
             }
         }
         try {
             beu_brand::model()->updateAll($updata_arr, 'id=:textx', array(':textx' => $id));
             Yii::app()->cache->delete(CacheName::getCacheName('brand_name_list_all'));
             //清除品牌列表
         } catch (BeubeuException $e) {
             throw new BeubeuException(Yii::t('public', '修改数据失败'), BeubeuException::SQL_UPDATE_ERR);
         }
     } else {
         throw new BeubeuException(Yii::t('beu_brand', '数据') . Yii::t('public', '不能为空'), BeubeuException::FIELD_EMPTY);
     }
     return true;
 }