PrivateAccount.php 1.7 KB

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