64], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'account_id' => 'Account ID', 'mall_id' => 'Mall ID', 'book_type' => 'Book Type', 'is_default' => 'Is Default', 'merchant_user_id' => 'Merchant User ID', 'account_book_id' => 'Account Book ID', 'ext_card_info' => 'Ext Card Info', 'created_at' => 'Created At', 'agreement_no' => 'Agreement No', ]; } /** * 查询外部商户系统会员的唯一标识是否存在 * * @param string $account_book_id * @return boolean */ public static function bookIdExists($account_book_id) { return empty(self::find()->select('id')->where(['account_book_id' => $account_book_id])->one()) ? true : false; } /** * 外部商户系统会员的唯一标识 * * @return string */ public static function getMerchantUserId() { $book_id = self::PREFIX . date('YmdHi') . rand(100, 999); return self::bookIdExists($book_id) ? $book_id : self::getMerchantUserId(); } /** * 添加记帐本 * * @param array $data * @return boolean */ public static function addBook($data) { // 是否有默认的记账本 $book = self::find()->where(['mall_id' => $data['mall_id'], 'is_default' => 1])->one(); if (empty($book)) { $data['is_default'] = 1; } $data = array_merge($data, [ 'created_at' => time(), ]); $model = new self(); $model->load($data, ''); return $model->save(); } /** * 获取默认记账本 * * @param int $mall_id * @return self */ public static function byMallGetBook($mall_id) { return self::find() ->where(['mall_id' => $mall_id, 'book_type' => 1, 'is_default' => 1]) ->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(); } }