php自动编号 月份 序号,php 自动生成编号

C8k1JdAAAAAElFTkSuQmCC

html代码

责任书编号

value="" readonly />

*

PHP代码

public function create(){

if($this->input->server('REQUEST_METHOD') == 'GET'){

$data=array();

$data = $this->_getGlobalData($data);

$data['responsecode'] = $this->dball->getNo("SG_".date("Ymd",time()),5);

$this->load->view('project/project/datadetailcreate.php',$this->_beforemethod($data));

}

else if($this->input->server('REQUEST_METHOD') == 'POST'){

$datain=$_POST;

if($datain['companyname']==''){

$result["ret"] = 1;

$result["success"] = false;

$result["msg"] = "请输入企业名称!";

$result["obj"] = '';

echo json_encode($result);

exit;

}

$sql = "select * from projects where responsecode = '".$datain['responsecode']."'";

$query = $this->mydb->find($sql);

if(count($query['obj']) > 0)

{

$result["ret"] = 1;

$result["success"] = false;

$result["msg"] = "责任书编号已存在,请确认!";

$result["obj"] = '';

echo json_encode($result);

exit;

}

$sql = "select * from projects where projectname = '".$datain['projectname']."'";

$query = $this->mydb->find($sql);

if(count($query['obj']) > 0)

{

$result["ret"] = 1;

$result["success"] = false;

$result["msg"] = "项目名称已存在,请确认!";

$result["obj"] = '';

echo json_encode($result);

exit;

}

$datainfo = $this->_getRequestModel();

$datainfo = $this->_setAddModifyData($datainfo);

$datainfo['status'] = '审核通过';

$datainfo['mikey'] = $this->dball->getNo("P",7);

$datainfo['saferid'] = $this->sessioninfo['userId'];

$datainfo['companyname'] = $_POST['companyname'];

$result=$this->mydb->addData($this->_beforeMethod($datainfo));

$result=$this->_afterDBAct($result);

$code=$this->dball->getNo('PTP'.date('Ymd',time()),6);

$progressid = '申报开工条件审查新开工';

$sql = "insert into projectprogresses(id,code,projectcode,projectid,progress,userid,date,createuser,createdatetime,modifyuser,modifydatetime) values('','".$code."','".$datainfo['code']."',".$id.",'".$progressid."','".$this->sessioninfo['userId']."','".date('Y-m-d',time())."','".$this->sessioninfo['fullName']."','".date('Y-m-d',time())."','".$this->sessioninfo['fullName']."','".date('Y-m-d',time())."')";

$this->mydb->execSql($sql);

$this->setLogs("新建项目",$datainfo);

echo $this->_ReturnMsg($result);

}

else redirect($this->url_module.'/'.$this->url_model);

}

/**

* 获取编号

* @param string $type  编号的固定开始文字

* @param integer $num  编号的最加流水号长度,默认2位

* @return array $result

*/

public function getNo($type,$num=2){

$CI =& get_instance();

$sql = "SELECT * FROM dictdatas WHERE type='编号生成' AND name = '".$type."'";  //dictdatas 数据字典

$query = $this->db->query($sql);

$result = $query->result_array();

//print_r($CI);exit();

if (sizeof($result) == 0){

$result = $type.''.str_pad('1', $num,'0',STR_PAD_LEFT);

$data['type'] = '编号生成';

$data['seq'] = $type;

$data['value'] = '1';

$data['name'] = $type;

$data["createdatetime"] = date('Y-m-d G:i:s');

$data["createuser"] = $CI->session->userdata['userId'];

$this->db->insert('dictdatas',$data);

}

else {

$no = $result[0]['value'] + 1;

$data['value'] = $no;

$data["modifydatetime"] = date('Y-m-d G:i:s');

$data["modifyuser"] = $CI->session->userdata['userId'];

$this->db->where('id',$result[0]['id']);

$this->db->update('dictdatas',$data);

$result = $type.''.str_pad($no,$num,'0',STR_PAD_LEFT);

}

return $result;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值