| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- namespace addons\AvoidTax\common\models;
- use Yii;
- use yii\db\ActiveQuery;
- /**
- * This is the model class for table "{{%addons_tax_account}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $book_type 1 税务方 2用工方
- * @property string|null $external_agreement_no 代扣协议中标示用户的唯一签约号(确保在商户系统中唯一)。
- * @property string|null $agreement_no 支付宝系统中用以唯一标识用户签约记录的编号。
- * @property string|null $alipay_logon_id 返回脱敏的支付宝账号,如需要返回不脱敏的支付宝用户账号,需要用户在签约页面上授权
- * @property string|null $personal_product_code 协议产品码,商户和支付宝签约时确定,不同业务场景对应不同的签约产品码。
- * @property int|null $valid_time 用户代扣协议的实际生效时间
- * @property int|null $sign_time 支付宝代扣协议的实际签约时间
- * @property int $is_default 是否默认
- * @property string|null $status 协议当前状态 1. TEMP:暂存,协议未生效过; 2. NORMAL:正常; 3. STOP:暂停
- * @property string|null $sign_scene 签约协议的场景。
- * @property string|null $third_party_type 签约第三方主体类型。对于三方协议,表示当前用户和哪一类的第三方主体进行签约。 取值范围: 1. PARTNER(平台商户); 2. MERCHANT(集团商户),集团下子商户可共享用户签约内容; 默认为PARTNER。
- * @property TaxAccountBook $book
- */
- class TaxAccount extends \yii\db\ActiveRecord
- {
- /**
- * 税务方
- */
- const TAXATION = 1;
- /**
- * 用工方
- */
- const EMPLOY = 2;
- /**
- * 九尾(过流水)
- */
- const PAYMENT_FLOW = 3;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_tax_account}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'book_type', 'valid_time', 'sign_time', 'is_default'], 'integer'],
- [['external_agreement_no', 'agreement_no', 'status', 'third_party_type'], 'string', 'max' => 32],
- [['alipay_logon_id', 'personal_product_code', 'sign_scene'], 'string', 'max' => 64],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'book_type' => 'Book Type',
- 'external_agreement_no' => 'External Agreement No',
- 'agreement_no' => 'Agreement No',
- 'alipay_logon_id' => 'Alipay Logon ID',
- 'personal_product_code' => 'Personal Product Code',
- 'valid_time' => 'Valid Time',
- 'sign_time' => 'Sign Time',
- 'is_default' => 'Is Default',
- 'status' => 'Status',
- 'sign_scene' => 'Sign Scene',
- 'third_party_type' => 'Third Party Type',
- ];
- }
- /**
- * 获取关联记帐本
- *
- * @return ActiveQuery
- */
- public function getBook()
- {
- return $this->hasOne(TaxAccountBook::class, ['account_id' => 'id']);
- }
- /**
- * 查询协议产品码是否存在
- *
- * @param string $no
- * @return boolean
- */
- public static function noExists($no)
- {
- return empty(self::find()->select('id')->where(['external_agreement_no' => $no])->one())
- ? true
- : false;
- }
- /**
- * 获取一个商户签约号
- *
- * @return string
- */
- public static function getAgreementNo()
- {
- $no = date('YmdH') . rand(100, 999);
- return self::noExists($no)
- ? $no
- : self::getAgreementNo();
- }
- /**
- * 新增一个账户
- *
- * @param array $data
- * @return boolean
- */
- public static function addAccount($data)
- {
- $model = new self;
- $model->load($data, '');
- // return $model->save();
- return $model->save() ? $model : false;
- }
- /**
- * 获取默认账户
- *
- * @param integer $mall_id
- * @return boolean|TaxAccount
- */
- public static function getDefaultAccount(int $mall_id, int $book_type = TaxAccount::TAXATION)
- {
- return self::find()
- ->with('book')
- ->where(['mall_id' => $mall_id, 'is_default' => 1, 'book_type' => $book_type])
- ->one();
- }
- /**
- * id和type获取记账本
- *
- * @param integer $mall_id
- * @param integer $id
- * @param integer|array $type
- * @return static|null
- */
- public static function getAccountByIdAndType(int $mall_id, int $id, $type)
- {
- return static::find()
- ->where([
- 'mall_id' => $mall_id, 'book_type' => $type, 'id' => $id
- ])
- ->one();
- }
- /**
- * id获取未签约的账户
- *
- * @param integer $mall_id
- * @param integer $id
- * @return static|null
- */
- public static function getAccountByIdAndNotSign(int $mall_id, int $id)
- {
- return static::find()
- ->where(['mall_id' => $mall_id, 'id' => $id, 'status' => 0])
- ->one();
- }
- /**
- * 获取税务方默认记账本
- *
- * @param integer $mall_id
- * @return static|null
- */
- public static function getTaxation(int $mall_id)
- {
- return self::find()
- ->where(['mall_id' => $mall_id, 'book_type' => TaxAccount::TAXATION, 'is_default' => 1])
- ->one();
- }
- /**
- * 获取用工方默认记账本
- *
- * @param integer $mall_id
- * @return static|null
- */
- public static function getEmploy(int $mall_id)
- {
- return self::find()
- ->where(['mall_id' => $mall_id, 'book_type' => TaxAccount::EMPLOY, 'is_default' => 1])
- ->one();
- }
- /**
- * 获取流水方默认记账本
- *
- * @param integer $mall_id
- * @return static|null
- */
- public static function getPaymentFlow(int $mall_id)
- {
- return self::find()
- ->where(['mall_id' => $mall_id, 'book_type' => TaxAccount::PAYMENT_FLOW, 'is_default' => 1])
- ->one();
- }
- /**
- * 判断是否为税务方记账本
- *
- * @return boolean
- */
- public function isTaxation()
- {
- return $this->book_type == TaxAccount::TAXATION;
- }
- /**
- * 该记账本是过流水记账本
- *
- * @return boolean
- */
- public function isPaymentFlow()
- {
- return $this->book_type == TaxAccount::PAYMENT_FLOW;
- }
- }
|