生成唯一流水号

PHP cooljun 123℃ 0评论

生成唯一流水号:

/**
 * [contractNo 获取合同编号]
 * Author Yangjun <[cooljun@126.com]>
 * DateTime 2017-07-31
 * @param [type] $c_id [合同id]
 * @param [type] $b_apply_time [合同申请时间]
 * @return [type] [description]
 */
protected function contractNo($c_id,$b_apply_time){
 $yDate = array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
 $y = date(Y,strtotime($b_apply_time))-2017;
 return $yDate[$y].date("md",strtotime($b_apply_time)).floor($c_id/9999).str_pad($c_id%9999,5,0,STR_PAD_LEFT);
}

/**
 * [contractNo 根据合同编号获取合同id]
 * Author Yangjun <[cooljun@126.com]>
 * DateTime 2017-07-31
 * @param [type] $contractNo [合同编号]
 * @return [type] [description]
 */
protected function contractNoToId($contractNo){
 $n = substr($contractNo, 5,-5);
 $d = substr($contractNo,-5);
 return 9999*$n + (int)$d;
}

结果:

$this->contractNo("12312","2017-07-31");  //A0731102313
$this->contractNoToId("A0731102313"); //12312

转载请注明:cooljun小站 » 生成唯一流水号

如果你觉得这篇文章对你有帮助,请支持我继续更新网站 !捐赠本站
喜欢 (0)or分享 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址