此随机数是添加时就产生了一组随机数,然后通过后台进行传入数据库

1.静态

Tp5  写随机数(商品货号)

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

Tp5  写随机数(商品货号)

 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.模型内

Tp5  写随机数(商品货号)

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;
}

随机数产生,点击保存之后,随机数也就传入了数据库,随之产生


相关文章:

  • 2021-12-06
  • 2021-09-27
  • 2021-05-08
  • 2021-11-01
  • 2021-08-12
  • 2021-06-14
  • 2021-08-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-04
  • 2022-12-23
  • 2022-01-15
  • 2022-12-23
  • 2021-09-14
相关资源
相似解决方案