/var/www/hkosl.com/littleark/webadmin/models/MasterTxseqno.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
use Illuminate\Database\Capsule\Manager as DB;

class 
MasterTxseqno extends BaseModel
{
    protected 
$table "master_txseqno";

    public static function 
generate($increment true$lock true$module "ORDER")
    {
        
DB::beginTransaction();

        if (
$lock) {
            
DB::connection()->getPdo()->exec("LOCK TABLES master_txseqno WRITE;");

            
// lock test
            // sleep(10);
        
}

        
$master_txseqno self::where('module'$module)->first();
        
// var_dump($master_txseqno);

        
if (!$master_txseqno) {
            throw new 
Exception("Unable to generate a new number"1);
        }

        
$new_number $result["txseqno"];

        if (
$increment) {
            
$master_txseqno->txseqno++;
            
$master_txseqno->save();
        }

        if (
$lock) {
            
DB::connection()->getPdo()->exec("UNLOCK TABLES;");
        }

        
DB::commit();
        return 
$master_txseqno->txseqno;
    }
}