| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace backend\models;
- use Yii;
- /**
- * This is the model class for table "crm_public_account".
- *
- * @property integer $id
- * @property integer $add_time
- * @property integer $is_close
- * @property integer $is_used
- * @property string $account
- */
- class PublicAccount extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'crm_public_account';
- }
- /**
- * @return \yii\db\Connection the database connection used by this AR class.
- */
- public static function getDb()
- {
- return Yii::$app->get('dbXcrm');
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['id', 'add_time','is_close','is_used'], 'number'],
- [['account','name','bank'], 'string'],
- ];
- }
- /**
- * @return array|bool|\yii\db\ActiveRecord[]
- */
- public function getAccountConfig()
- {
- $sql = "select id from crm_public_account where is_close = 0";
- $res = static::findBySql($sql)->asArray()->all();
- if(empty($res)){
- return false;//没有开放的对公帐户
- }
- $sql = "select account,bank,name from crm_public_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){
- return $account_arr[0];
- }else{
- $sql = "update crm_public_account set is_used = 1 where is_close = 1";
- Yii::$app->db->createCommand($sql)->execute();
- static::getAccountConfig();
- }
- }
- }
|