StoreBank.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. namespace addons\Store\common\models;
  3. use addons\JoinPay\common\models\JoinPayUserBankcard;
  4. use common\enums\StatusEnum;
  5. use common\models\base\BaseActiveRecord;
  6. use common\models\common\UserBankCard;
  7. use Yii;
  8. use yii\db\Exception;
  9. /**
  10. * This is the model class for table "qimall_addons_store_bank".
  11. *
  12. * @property int $id
  13. * @property int $mall_id 商城id
  14. * @property int $store_id 门店id
  15. * @property string $username 开户名
  16. * @property string $bank 开户银行
  17. * @property string $card_no 银行卡号
  18. * @property int $created_at
  19. * @property int $updated_at
  20. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  21. */
  22. class StoreBank extends BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_store_bank}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'store_id', 'created_at', 'updated_at', 'status'], 'integer'],
  38. [['username'], 'string', 'max' => 50],
  39. [['bank', 'card_no'], 'string', 'max' => 255],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'mall_id' => '商城id',
  50. 'store_id' => '门店id',
  51. 'username' => '开户名',
  52. 'bank' => '开户银行',
  53. 'card_no' => '银行卡号',
  54. 'created_at' => 'Created At',
  55. 'updated_at' => 'Updated At',
  56. 'status' => '状态[-1:删除;0:禁用;1启用]',
  57. ];
  58. }
  59. public static function setData(array $params)
  60. {
  61. try {
  62. if (!empty($params['id'])) {
  63. $where = ['id' => $params['id'], ['status' => StatusEnum::ENABLED]];
  64. if (isset($params['mall_id'])) $where[] = ['mall_id' => $params['mall_id']];
  65. if (isset($params['store_id'])) $where[] = ['store_id' => $params['store_id']];
  66. $model = self::findOne($where);
  67. if (empty($model)) throw new \Exception('服务不存在或已删除');
  68. } else {
  69. $model = new self();
  70. $model->loadDefaultValues();
  71. }
  72. if (!$model->load($params, '') || !$model->save()) throw new \PHPUnit\Util\Exception($model->getErrorMessage());
  73. return $model;
  74. } catch (\Exception $e) {
  75. self::$static_error = $e->getMessage();
  76. return false;
  77. }
  78. }
  79. public static function addJoinPayBankCard($mall_id,$post){
  80. try {
  81. $user_bank_card_data = [
  82. 'user_id' => $post['user_id'],
  83. 'bank_card_no' => $post['bank_card_no'],
  84. 'payer_name' => $post['payer_name'],
  85. 'bank_name' => $post['bank_name'],
  86. 'bank_code' => $post['bank_code'],
  87. 'card_type' => $post['card_type'],
  88. 'card_type_name' => $post['card_type_name'],
  89. 'bank_account_type' => $post['bank_account_type'],
  90. ];
  91. $model = UserBankCard::setData($mall_id, $user_bank_card_data);
  92. if (false === $model) throw new Exception(UserBankCard::getStaticError());
  93. $post['card_id'] = $model->id;
  94. unset($post['bank_account_type']);
  95. $resj = JoinPayUserBankcard::setData($mall_id, $post);
  96. if (false === $resj) throw new Exception(JoinPayUserBankcard::getStaticError());
  97. return $model->id;
  98. }catch (Exception $e){
  99. self::$static_error = $e->getMessage();
  100. return false;
  101. }
  102. }
  103. }