码迷,mamicode.com
首页 > Web开发 > 详细

PHP单据号操作

时间:2016-04-20 11:12:20      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

此处约定单据号格式为“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     }

 

PHP单据号操作

标签:

原文地址:http://www.cnblogs.com/izhengyang/p/5411530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!