商品發佈時,欄目選擇
商品貨號,如不填寫,自動生成
詳細描述,使用編輯器
在GoodModel.class.php增加自動生成商品貨號
/*創建商品貨號*/ public function createSn(){ $sn = 'YGF'.date('ymd').mt_rand(1000,9999); $sql = 'select count(*) from '.$this->table." where goods_sn = '".$sn ."'"; return $this->db->getOne($sql)?$this->createSn():$sn; } |
在goodsaddAct.php增加:
/*自動生成商品貨號*/ if(empty($data['goods_sn'])){ $data['goods_sn'] = $goods->createSn(); } |
完善ImageTool.class.php,增加驗證碼功能
public static function captcha($width = 50, $height = 25){ //造畫布 $image = imagecreatetruecolor($width,$height); //造背景顏色 $gray = imagecolorallocate($image,200,200,200); //填充背景 imagefill($image,0,0,$gray); //造隨機字體顏色 $color = imagecolorallocate($image,mt_rand(0,125),mt_rand(0,125),mt_rand(0,125)); //造隨機線條顏色 $color1 = imagecolorallocate($image,mt_rand(100,125),mt_rand(100,125),mt_rand(100,125)); $color2 = imagecolorallocate($image,mt_rand(100,125),mt_rand(100,125),mt_rand(100,125)); $color3 = imagecolorallocate($image,mt_rand(100,125),mt_rand(100,125),mt_rand(100,125)); //在畫布上畫線條 imageline($image,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),$color1); imageline($image,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),$color2); imageline($image,mt_rand(0,$width),mt_rand(0,$height),mt_rand(0,$width),mt_rand(0,$height),$color3); //在畫布上寫字 $text = substr(str_shuffle('ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'),0,4); imagestring($image,5,7,5,$text,$color); //顯示文字 header("content-type:image/jpeg"); imagejpeg($image); imagedestroy($image); } |