| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace addons\Mch\common\models;
- use addons\JoinPay\common\models\JoinPayUserBankcard;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use common\models\common\UserBankCard;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "qimall_addons_mch_bank".
- *
- * @property int $id
- * @property int $mall_id 商城id
- * @property int $mch_id 多商户id
- * @property string $username 开户名
- * @property string $bank 开户银行
- * @property string $card_no 银行卡号
- * @property int $created_at
- * @property int $updated_at
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- */
- class MchBank extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_mch_bank}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'mch_id', 'created_at', 'updated_at', 'status'], 'integer'],
- [['username'], 'string', 'max' => 50],
- [['bank', 'card_no'], 'string', 'max' => 255],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城id',
- 'mch_id' => '多商户id',
- 'username' => '开户名',
- 'bank' => '开户银行',
- 'card_no' => '银行卡号',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- ];
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- $where = ['id' => $params['id'], ['status' => StatusEnum::ENABLED]];
- if (isset($params['mall_id'])) $where[] = ['mall_id' => $params['mall_id']];
- if (isset($params['mch_id'])) $where[] = ['mch_id' => $params['mch_id']];
- $model = self::findOne($where);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '') || !$model->save()) throw new \PHPUnit\Util\Exception($model->getErrorMessage());
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public static function addJoinPayBankCard($mall_id,$post){
- try {
- $user_bank_card_data = [
- 'user_id' => $post['user_id'],
- 'bank_card_no' => $post['bank_card_no'],
- 'payer_name' => $post['payer_name'],
- 'bank_name' => $post['bank_name'],
- 'bank_code' => $post['bank_code'],
- 'card_type' => $post['card_type'],
- 'card_type_name' => $post['card_type_name'],
- 'bank_account_type' => $post['bank_account_type'],
- ];
- $model = UserBankCard::setData($mall_id, $user_bank_card_data);
- if (false === $model) throw new Exception(UserBankCard::getStaticError());
- $post['card_id'] = $model->id;
- unset($post['bank_account_type']);
- $resj = JoinPayUserBankcard::setData($mall_id, $post);
- if (false === $resj) throw new Exception(JoinPayUserBankcard::getStaticError());
- return $model->id;
- }catch (Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|