| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /**
- * Created by PhpStorm.
- * User: user
- * Date: 2019/11/17
- * Time: 14:38
- */
- namespace backend\models;
- use Yii;
- /**
- * This is the model class for table "crm_private_account".
- *
- * @property integer $id
- * @property integer $add_time
- * @property integer $is_close
- * @property integer $is_used
- * @property string $account
- */
- class PrivateAccount extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'crm_private_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'], '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];
- }
- }
- }
- }
|