标签:
此处约定单据号格式为“ysd201604200001”,单据代码,日期,四位数字
1 $conn = MySqlPdoHelper::getConnection(); 2 3 $billCode = ‘ysd‘; 4 5 //获取今日的验收单编号数量 6 $now = date(‘Ymd‘); 7 $reg = ‘^‘. $billCode. $now; 8 $sql = ‘SELECT count(1) FROM tb_yanshoudan_title WHERE bill_number REGEXP :reg;‘; 9 $count = MySqlPdoHelper::executeScalar($sql, $conn, array(‘:reg‘ => $reg)); 10 if($count == 0) 11 { 12 self::insertViewBag(‘billNumber‘,$billCode. $now.‘0001‘); 13 } 14 else 15 { 16 //获取今日验收单后四位的数组 17 $sql = ‘SELECT substr(bill_number,-4) AS bill FROM tb_yanshoudan_title WHERE bill_number REGEXP "^‘.$billCode.$now.‘";‘; 18 $result = MySqlPdoHelper::executeData($sql, $conn); 19 20 //遍历结果,找出最大值 21 $maxBill = ‘‘; 22 for($i = 0; $i < count($result); $i++) 23 { 24 $preMaxBill = $maxBill; 25 $nowMaxBill = $result[$i][‘bill‘]; 26 $maxBill = $preMaxBill < $nowMaxBill ? $nowMaxBill : $preMaxBill; 27 } 28 self::insertViewBag(‘billNumber‘,$billCode. $now. sprintf(‘%04d‘,$maxBill + 1)); 29 } 30 }
标签:
原文地址:http://www.cnblogs.com/izhengyang/p/5411530.html