zoukankan      html  css  js  c++  java
  • 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;
    }

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


  • 相关阅读:
    bzoj1066: [SCOI2007]蜥蜴
    bzoj3504: [Cqoi2014]危桥
    bzoj2756: [SCOI2012]奇怪的游戏
    bzoj1570: [JSOI2008]Blue Mary的旅行
    Ultra-QuickSort
    Bin Packing
    Watering Grass
    区间覆盖
    抄书 Copying Books UVa 714
    分馅饼 Pie
  • 原文地址:https://www.cnblogs.com/dennyxiao/p/8611180.html
Copyright © 2011-2022 走看看