@@ -37,6 +37,27 @@ public function init()
3737 parent ::init ();
3838 }
3939
40+ public function setAttributesModels ($ attributes , $ models )
41+ {
42+ $ modelServer = Servers::model ()->find ([
43+ 'condition ' => 'type = "asterisk" AND status = 1 AND weight > 0 ' ,
44+ 'order ' => 'last_call DESC ' ,
45+ ]);
46+ $ last_call = date ("Y-m-d H:i:s " , strtotime ("-5 minutes " , strtotime ($ modelServer ->last_call )));
47+
48+ $ pkCount = is_array ($ attributes ) || is_object ($ attributes ) ? $ attributes : [];
49+ for ($ i = 0 ; $ i < count ($ pkCount ); $ i ++) {
50+
51+ if ($ attributes [$ i ]['status ' ] == 4 ) {
52+ Servers::model ()->updateByPk ($ attributes [$ i ]['id ' ], array ('status ' => 1 ));
53+ }
54+ if ($ attributes [$ i ]['type ' ] == 'asterisk ' && $ attributes [$ i ]['status ' ] > 0 && $ attributes [$ i ]['weight ' ] > '0 ' && $ attributes [$ i ]['last_call ' ] < $ last_call ) {
55+ Servers::model ()->updateByPk ($ attributes [$ i ]['id ' ], array ('status ' => 4 ));
56+ }
57+ }
58+ return $ attributes ;
59+ }
60+
4061 public function afterSave ($ model , $ values )
4162 {
4263
@@ -69,7 +90,7 @@ public function afterSave($model, $values)
6990 foreach ($ modelServerAS as $ key => $ server ) {
7091
7192 $ modelServer = Servers::model ()->find ("id = :key AND (type = 'asterisk' OR type = 'mbilling')
72- AND status = 1 AND weight > 0 " , [':key ' => $ server ->id_server ]);
93+ AND status IN( 1,4) AND weight > 0 " , [':key ' => $ server ->id_server ]);
7394
7495 if (isset ($ modelServer ->id )) {
7596 if ($ this ->ip_is_private ($ hostname )) {
@@ -90,7 +111,7 @@ public function afterSave($model, $values)
90111 } else {
91112
92113 $ modelServerAS = Servers::model ()->findAll ("(type = 'asterisk' OR type = 'mbilling')
93- AND status = 1 AND weight > 0 " );
114+ AND status IN( 1,4) AND weight > 0 " );
94115 foreach ($ modelServerAS as $ key => $ server ) {
95116
96117 if ($ this ->ip_is_private ($ hostname )) {
0 commit comments