get('dbXcrm'); } /** * @inheritdoc */ public function rules() { return [ [['id', 'add_time','is_close','is_used'], 'number'], [['account'], 'string'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => 'id', 'add_time' => 'add_time', 'is_close' => 'is_close', 'is_used' => 'is_used', 'account' => 'account', ]; } /** * @return array|bool|\yii\db\ActiveRecord[] */ public static function getAccountConfig() { $sql = "select id from crm_private_account where is_close = 0"; $res = static::findBySql($sql)->asArray()->all(); if(empty($res)){ return false;//没有开放的对私帐户 } $sql = "select id,account from crm_private_account where is_close = 0 and is_used = 0 order by id desc limit 1"; $account_arr = static::findBySql($sql)->asArray()->all(); if($account_arr[0]['id']){ return $account_arr[0]; }else{ static::updateAll(['is_used' => 0],['is_used' => 1,'is_close' => 0]); $sql = "select id,account from crm_private_account where is_close = 0 and is_used = 0 order by id desc limit 1"; $account_arr = static::findBySql($sql)->asArray()->all(); if($account_arr[0]['id']){ file_put_contents('test.txt',json_encode($account_arr[0])); return $account_arr[0]; } } } }