| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace common\models\common;
- use common\models\order\OrderRefund;
- use Yii;
- /**
- * This is the model class for table "{{%payment_trade_item_refund}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $trade_id 支付流水ID
- * @property int $item_id 组合支付ID
- * @property int $refund_id 售后订单ID
- * @property float $refund_fee 售后金额
- * @property int $refund_status 是否售后
- * @property int $pay_type 支付类型
- * @property int|null $refund_at 售后时间
- * @property int|null $updated_at
- * @property int|null $created_at
- * @property string $refund_source 退款数据来源(Mall是主商城 否则是插件)
- */
- class PaymentTradeItemRefund extends \common\models\base\BaseActiveRecord
- {
- /**
- * 已退款
- */
- const REFUND = 1;
- /**
- * 已拒绝
- */
- const REFUSE = 2;
- /**
- * 等待
- */
- const WAIT = 0;
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%payment_trade_item_refund}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'trade_id', 'item_id', 'refund_id', 'pay_type'], 'required'],
- [['mall_id', 'trade_id', 'item_id', 'refund_id', 'refund_status', 'pay_type', 'refund_at', 'updated_at', 'created_at'], 'integer'],
- [['refund_source'], 'string'],
- [['refund_fee'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'trade_id' => 'Trade ID',
- 'item_id' => 'Item ID',
- 'refund_id' => 'Refund ID',
- 'refund_fee' => 'Refund Fee',
- 'refund_status' => 'Is Refund',
- 'pay_type' => 'Pay Type',
- 'refund_at' => 'Refund At',
- 'updated_at' => 'Updated At',
- 'created_at' => 'Created At',
- 'refund_source' => 'Refund Source',
- ];
- }
- /**
- * @param integer $refund_id
- * @return array
- */
- public static function getMixedPayRefundList(int $trade_id, int $refund_id, string $refund_source = 'Mall')
- {
- return static::find()
- ->where(['trade_id' => $trade_id, 'refund_id' => $refund_id, 'refund_status' => 0, 'refund_source' => $refund_source])
- ->all();
- }
- /**
- * @param array $params
- * @param OrderRefund|null $refund
- * @return float
- */
- public function getRefundFee(array $params = [], $refund = null)
- {
- // 不使用$params传入金额
- return $this->refund_fee;
- }
- /**
- * @param integer $trade_id
- * @param integer $refund_id
- * @param string $refund_source
- * @return int
- */
- public static function setRefund(int $trade_id, int $refund_id, string $refund_source = 'Mall')
- {
- return static::updateAll(
- ['refund_status' => static::REFUND, 'refund_at' => time()],
- ['trade_id' => $trade_id, 'refund_id' => $refund_id, 'refund_status' => static::WAIT, 'refund_source' => $refund_source]
- );
- }
- /**
- * @param integer $trade_id
- * @param integer $refund_id
- * @param string $refund_source
- * @return int
- */
- public static function setRefuse(int $trade_id, int $refund_id, string $refund_source = 'Mall')
- {
- return static::updateAll(
- ['refund_status' => static::REFUSE, 'refund_at' => time()],
- ['trade_id' => $trade_id, 'refund_id' => $refund_id, 'refund_status' => static::WAIT, 'refund_source' => $refund_source]
- );
- }
- /**
- * @return int
- */
- public function getTradeId()
- {
- return $this->trade_id;
- }
- /**
- * @param OrderRefund $refund
- * @param PaymentTrade $trade
- * @param PaymentTradeItem $item
- * @param float $fee
- * @param string $refund_source
- * @return boolean
- */
- public static function addRefundItem(
- OrderRefund $refund, PaymentTrade $trade, PaymentTradeItem $item, float $fee, string $refund_source = 'Mall'
- )
- {
- $model = new static();
- $model->mall_id = $refund->mall_id;
- $model->trade_id = $trade->id;
- $model->item_id = $item->id;
- $model->pay_mode = $item->pay_mode;
- $model->refund_id = $refund->id;
- $model->pay_type = $item->pay_type;
- $model->refund_fee = $fee;
- $model->refund_source = $refund_source;
- return $model->save();
- }
- }
|