此隨機數是添加時就產生了一組隨機數,然后通過后台進行傳入數據庫
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;
}
隨機數產生,點擊保存之后,隨機數也就傳入了數據庫,隨之產生