Tp5 寫隨機數(商品貨號)


此隨機數是添加時就產生了一組隨機數,然后通過后台進行傳入數據庫

1.靜態

<input type="hidden" name="product_number" value="{$random}" class="form-control" id="title">
2.控制器內

 public function add(){
$article = new YouproModel();
$result = $article->getProSelect();
$this->assign('result', $result);
//隨機號 商品貨號
$random = $article->randomStr();
$this->assign('random', $random);
// var_dump($random);
// exit;
if(request()->isAjax()){
$param = input('post.');
unset($param['file']);
$article = new YouproModel();
$flag = $article->insertCategory($param);
// var_dump($flag);exit;
return json(['code' => $flag['code'], 'data' => $flag['data'], 'msg' => $flag['msg']]);
}
return $this->fetch();
}
3.模型內

public function randomStr(){
$arr = array_merge(range(0,9),range('A','Z'));
$str = '';
$arr_len = count($arr);
for($i = 0;$i < 8;$i++){
$rand = mt_rand(0,$arr_len-1);
$str.=$arr[$rand];
}
return $str;
}

隨機數產生,點擊保存之后,隨機數也就傳入了數據庫,隨之產生



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM