/** * 向beu_clothes表添加新的数据 * @parm $arr:Array 其内容如下 * brandid:int(11) (必填)品牌id * color:int(11) (必填)颜色id * level:int(11) (必填)层次 * clothescategory:int(11) (必填)品类一级目录 * clothescategory2:int(11) (必填)品类二级目录 * thumbnail:string(255) (必填)列表页显示图 * * name:string(255) (可不填)衣服名 * colorimage:string(255) (可不填)上传的颜色图片 * brandnumber:string(255) (可不填)品牌衣服款号,默认模特的款号 * material:int(11) (可不填)质地,对应category表中style=6,单选 * underwear:int(4) (可不填)是否穿内衣,0是穿内衣,1是脱内衣 * modelgender:int(11) (可不填)模特类型,是否男女模.对应b_category style为9的. * label:int(11) (可不填)标签属性ID,指新品等,对应b_category的style为10的类型 * foottype:int(11) (可不填)脚部类型,对应b_category中type15 * supportfoot:string(50) (可不填)支持不同脚的ID,以逗号分隔,如果存在就表示该衣服支持该脚 * imagescontent:string(6000) (可不填)json格式{一维:customImagecontent:自定义图片(二维:{"customimage序列1-2 (三维:{customImagecontent序列1-50})})、staticImagecontent:静态图(二维{staticImagecontent序列1-50})、detailImagecontent:细节图(二维:{detailImagecontent序列1-50})、graphicmodel:立体图{二维:graphicmodel序列1-50}、collocationmap:搭 * masks:string(1000) (可不填)遮罩JSON参数 * price:float (可不填)价钱 * discountprice:float (可不填)折扣后价格 * date_add:data(可不填)添加时间 * buyurl:string(1024) (可不填)购买地址,也需序列化 * * @return 成功返回添加数据id,否则返回false */ public static function beuclothesForadd($arr = array()) { if (count($arr) > 0 && gettype($arr) == 'array') { $clothes_biao = new beu_clothes(); if (isset($arr['brandid']) && isset($arr['color']) && isset($arr['level']) && isset($arr['clothescategory']) && isset($arr['clothescategory2']) && isset($arr['thumbnail'])) { try { $brandid = trim($arr['brandid']); $color = trim($arr['color']); $level = trim($arr['level']); $clothescategory = trim($arr['clothescategory']); $clothescategory2 = trim($arr['clothescategory2']); $thumbnail = trim($arr['thumbnail']); Comm::checkValue($brandid, Yii::t('public', '品牌号'), 1, 1, self::$Int_max); Comm::checkValue($color, Yii::t('clothes', '颜色ID'), 1, 1, self::$Int_max); Comm::checkValue($level, Yii::t('clothes', '衣服层次'), 1, 1, self::$Int_max); Comm::checkValue($clothescategory, Yii::t('clothes', '一级品类'), 1, 1, self::$Int_max); Comm::checkValue($clothescategory2, Yii::t('clothes', '二级品类'), 1, 1, self::$Int_max); Comm::checkValue($thumbnail, Yii::t('clothes', '列表页显示图'), 0, 10, 255); $clothes_biao->brandid = $brandid; $clothes_biao->color = $color; $clothes_biao->level = $level; $clothes_biao->clothescategory = $clothescategory; $clothes_biao->clothescategory2 = $clothescategory2; $clothes_biao->thumbnail = $thumbnail; } catch (BeubeuException $e) { throw new BeubeuException($e->getMessage(), $e->getCode()); } } else { return false; } if (isset($arr['name'])) { //衣服名字段存在,并且长度不超过255 try { $str_param = trim($arr['name']); Comm::checkValue($str_param, Yii::t('clothes', '单品名称'), 0, 0, 255); $clothes_biao->name = $str_param; } catch (BeubeuException $e) { } } if (isset($arr['id'])) { //衣服名字段存在,并且长度不超过255 try { $str_param = trim($arr['id']); Comm::checkValue($str_param, 'ID', 1, 1, self::$Int_max); $clothes_biao->id = $str_param; } catch (BeubeuException $e) { } } if (isset($arr['colorimage'])) { //上传的颜色图片字段存在,并且长度不超过255 try { $str_param = trim($arr['colorimage']); Comm::checkValue($str_param, Yii::t('clothes', '上传的颜色图片'), 0, 0, 255); $clothes_biao->colorimage = $str_param; } catch (BeubeuException $e) { } } if (isset($arr['brandnumber'])) { //品牌衣服款号字段存在,并且长度不超过255 try { $str_param = trim($arr['brandnumber']); Comm::checkValue($str_param, Yii::t('clothes', '款号'), 0, 0, 255); $brand_biao->brandnumber = $str_param; } catch (BeubeuException $e) { } } if (isset($arr['material'])) { //质地字段存在,并且长度不超过255 try { $str_param = trim($arr['material']); if (!empty($str_param)) { Comm::checkValue($str_param, Yii::t('clothes', '质地'), 1, 1, self::$Int_max); $brand_biao->material = $str_param; } } catch (BeubeuException $e) { } } if (isset($arr['modelgender'])) { //模特类型字段存在,并且长度不超过255 try { $str_param = trim($arr['modelgender']); if (!empty($str_param)) { Comm::checkValue($str_param, Yii::t('public', '模特类型'), 1, 1, self::$Int_max); $brand_biao->modelgender = $str_param; } } catch (BeubeuException $e) { } } if (isset($arr['label'])) { //标签属性ID字段存在,并且长度不超过255 try { $str_param = trim($arr['label']); if (!empty($str_param)) { Comm::checkValue($str_param, Yii::t('clothes', '标签属性ID'), 1, 1, self::$Int_max); $brand_biao->label = $str_param; } } catch (BeubeuException $e) { } } if (isset($arr['foottype'])) { //脚部类型字段存在,并且长度不超过255 try { $str_param = trim($arr['foottype']); if (!empty($str_param)) { Comm::checkValue($str_param, Yii::t('clothes', '脚部类型'), 1, 1, self::$Int_max); $brand_biao->foottype = $str_param; } } catch (BeubeuException $e) { } } if (isset($arr['supportfoot'])) { //支持不同脚的ID字段存在,并且长度不超过255 $str_param = trim($arr['supportfoot']); if (!empty($str_param)) { $str_param_id_arr = explode(',', $str_param); //将字符串拆分后进行整数检查 foreach ($str_param_id_arr as $key => $value) { $value = trim($value); try { Comm::checkValue($value, Yii::t('clothes', '脚ID'), 1, 1, self::$Int_max); } catch (BeubeuException $e) { unset($str_param_id_arr[$key]); } } if (count($str_param_id_arr) > 0) { //将检查后的数组拼接为字符串 $str_param = join(',', $str_param_id_arr); try { Comm::checkValue($str_param, Yii::t('clothes', '支持不同脚的ID'), 0, 1, 50); $clothes_biao->supportfoot = $str_param; } catch (BeubeuException $e) { } } } } if (isset($arr['imagescontent'])) { //图片JSON数据字段存在,并且长度不超过255 try { $str_param = trim($arr['imagescontent']); Comm::checkValue($str_param, Yii::t('clothes', '图片JSON数据'), 0, 0, 6000); $clothes_biao->imagescontent = $str_param; } catch (BeubeuException $e) { } } if (isset($arr['masks'])) { //遮罩JSON参数字段存在,并且长度不超过255 try { $str_param = trim($arr['masks']); Comm::checkValue($str_param, Yii::t('clothes', '遮罩JSON数据'), 0, 0, 1000); $clothes_biao->masks = $str_param; } catch (BeubeuException $e) { } } if (isset($arr['video'])) { //视频JSON数据字段存在,并且长度不超过255 try { $str_param = trim($arr['video']); Comm::checkValue($str_param, Yii::t('clothes', '视频JSON数据'), 0, 0, 500); $clothes_biao->video = $str_param; } catch (BeubeuException $e) { } } if (isset($arr['buyurl'])) { //购买地址字段存在,并且长度不超过255 try { $str_param = trim($arr['buyurl']); Comm::checkValue($str_param, Yii::t('clothes', '购买地址'), 0, 0, 1024); $clothes_biao->buyurl = $str_param; } catch (BeubeuException $e) { } } if (isset($arr['price'])) { //价钱字段存在,并且长度不超过255 try { $str_param = trim($arr['price']); $clothes_biao->price = 0; if (!empty($str_param)) { Comm::moneySingle($str_param, Yii::t('clothes', '价格')); $clothes_biao->price = $str_param; } } catch (BeubeuException $e) { } } if (isset($arr['discountprice'])) { //折扣后价格字段存在,并且长度不超过255 try { $str_param = trim($arr['discountprice']); $clothes_biao->discountprice = 0; if (!empty($str_param)) { Comm::moneySingle($str_param, Yii::t('clothes', '折扣后价格')); $clothes_biao->discountprice = $str_param; } } catch (BeubeuException $e) { } } if (isset($arr['underwear']) && !empty($arr['underwear']) && trim($arr['underwear']) == 1) { //是否穿内衣,默认0穿内衣,1不穿 $clothes_biao->underwear = 1; //不穿 } else { $clothes_biao->underwear = 0; //穿内衣 } if (isset($arr['underpants']) && !empty($arr['underpants']) && trim($arr['underpants']) == 1) { //是否穿内裤,默认0穿内裤,1不穿 $clothes_biao->underpants = 1; //不穿 } else { $clothes_biao->underpants = 0; //穿内裤 } if (isset($arr['showneckline']) && !empty($arr['showneckline']) && trim($arr['showneckline']) == 1) { //是否翻领,默认0翻,1不翻 $clothes_biao->showneckline = 1; //不翻领 } else { $clothes_biao->showneckline = 0; //翻领 } if (isset($arr['date_add']) && !empty($arr['date_add'])) { //时间字段存在并格式正确 try { $createdate = trim($arr['date_add']); if (!empty($createdate)) { $createdate = Comm::dataSingle($createdate, Yii::t('clothes', '添加时间')); $clothes_biao->date_add = $createdate; } } catch (BeubeuException $e) { } } try { $count = $clothes_biao->insert(); if ($count > 0) { return $count; } else { throw new BeubeuException(Yii::t('public', '插入数据失败'), BeubeuException::SQL_INSERT_ERR); } } catch (BeubeuException $e) { throw new BeubeuException(Yii::t('public', '插入数据失败'), BeubeuException::SQL_INSERT_ERR); } } else { throw new BeubeuException(Yii::t('beu_brand', '数据') . Yii::t('public', '不能为空'), BeubeuException::FIELD_EMPTY); } return false; }