|
|
@@ -638,22 +638,24 @@ class Tool {
|
|
|
public static function generateInvoiceNo()
|
|
|
{
|
|
|
$prefix = 'Inv';
|
|
|
-
|
|
|
+ $currentDate = date('dmY');
|
|
|
+
|
|
|
+ // 查询今天生成的最新发票号(包含当天日期格式的)
|
|
|
$order = Order::find()
|
|
|
- ->where(['STATUS' => 1, 'IS_DELETE' => 0, 'INVOICE_NO' => ['$ne' => '']])
|
|
|
- ->orderBy(['PAY_AT' => SORT_DESC])
|
|
|
+ ->where(['STATUS' => 1, 'IS_DELETE' => 0])
|
|
|
+ ->andWhere(['like', 'INVOICE_NO', $prefix . $currentDate])
|
|
|
+ ->orderBy(['INVOICE_NO' => SORT_DESC])
|
|
|
->one();
|
|
|
|
|
|
- $invoiceNo = $order->INVOICE_NO;
|
|
|
-
|
|
|
- if ($invoiceNo) {
|
|
|
- // 截取后 5 位, 转为数字+1
|
|
|
- $no = intval(substr($invoiceNo, -5)) + 1;
|
|
|
- $no = sprintf('%05d', $no);
|
|
|
+ if ($order && !empty($order->INVOICE_NO)) {
|
|
|
+ $invoiceNo = $order->INVOICE_NO;
|
|
|
+ // 截取最后5位数字部分并+1
|
|
|
+ $no = sprintf('%05d', intval(substr($invoiceNo, -5)) + 1);
|
|
|
} else {
|
|
|
+ // 如果今天没有生成过发票号或没有符合条件的订单,从00001开始
|
|
|
$no = '00001';
|
|
|
}
|
|
|
|
|
|
- return $prefix . date('dmY') . $no;
|
|
|
+ return $prefix . $currentDate . $no;
|
|
|
}
|
|
|
}
|