PublicAccount.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace backend\models;
  3. use Yii;
  4. /**
  5. * This is the model class for table "crm_public_account".
  6. *
  7. * @property integer $id
  8. * @property integer $add_time
  9. * @property integer $is_close
  10. * @property integer $is_used
  11. * @property string $account
  12. */
  13. class PublicAccount extends \yii\db\ActiveRecord
  14. {
  15. /**
  16. * @inheritdoc
  17. */
  18. public static function tableName()
  19. {
  20. return 'crm_public_account';
  21. }
  22. /**
  23. * @return \yii\db\Connection the database connection used by this AR class.
  24. */
  25. public static function getDb()
  26. {
  27. return Yii::$app->get('dbXcrm');
  28. }
  29. /**
  30. * @inheritdoc
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['id', 'add_time','is_close','is_used'], 'number'],
  36. [['account','name','bank'], 'string'],
  37. ];
  38. }
  39. /**
  40. * @return array|bool|\yii\db\ActiveRecord[]
  41. */
  42. public function getAccountConfig()
  43. {
  44. $sql = "select id from crm_public_account where is_close = 0";
  45. $res = static::findBySql($sql)->asArray()->all();
  46. if(empty($res)){
  47. return false;//没有开放的对公帐户
  48. }
  49. $sql = "select account,bank,name from crm_public_account where is_close = 0 and is_used = 0 order by id desc limit 1";
  50. $account_arr = static::findBySql($sql)->asArray()->all();
  51. if($account_arr){
  52. return $account_arr[0];
  53. }else{
  54. $sql = "update crm_public_account set is_used = 1 where is_close = 1";
  55. Yii::$app->db->createCommand($sql)->execute();
  56. static::getAccountConfig();
  57. }
  58. }
  59. }