HappinessStoreBank.php 3.5 KB

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