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; } }