| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- namespace addons\YunfastPay\common\models;
- use addons\YunfastPay\common\enums\YunfastPayEnum;
- use common\models\order\OrderRefund;
- use Yii;
- /**
- * This is the model class for table "{{%addons_yunfast_pay_refund_order}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 会员ID
- * @property int $refund_id 退款订单ID
- * @property int $order_id 订单ID
- * @property string $order_no 退款订单号
- * @property float $refund_amount 退款金额
- * @property string|null $req_data 请求参数
- * @property string|null $res_data 返回参数
- * @property string|null $refund_params 退款参数
- * @property string $status 退款状态
- * @property int $updated_at
- * @property int $created_at
- * @property string $refund_source 退款订单来源
- */
- class RefundOrder extends ActiveRecord
- {
- protected static $json_fields = [
- 'req_data', 'res_data', 'refund_params'
- ];
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_yunfast_pay_refund_order}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'refund_id', 'order_id', 'order_no'], 'required'],
- [['mall_id', 'user_id', 'refund_id', 'order_id', 'updated_at', 'created_at'], 'integer'],
- [['refund_amount'], 'number'],
- [['req_data', 'res_data', 'refund_params'], 'string'],
- [['order_no'], 'string', 'max' => 32],
- [['refund_source'], 'string', 'max' => 50],
- [['status'], 'string', 'max' => 10],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'user_id' => 'User ID',
- 'refund_id' => 'Refund ID',
- 'order_id' => 'Order ID',
- 'order_no' => 'Order No',
- 'refund_amount' => 'Refund Amount',
- 'req_data' => 'Req Data',
- 'res_data' => 'Res Data',
- 'refund_params' => 'Refund Params',
- 'status' => 'Status',
- 'updated_at' => 'Updated At',
- 'created_at' => 'Created At',
- 'refund_source' => 'Refund Source',
- ];
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id']);
- }
- /**
- * @return ActiveQueryInterface the relational query object.
- */
- public function getRefund()
- {
- return $this->hasOne(OrderRefund::class, ['id' => 'refund_id']);
- }
- /**
- * 通过退款订单ID获取插件退款订单
- *
- * @param integer $refund_id
- * @param string $refund_source
- * @return static|null
- */
- public static function getOrderByRefundId(int $refund_id, string $refund_source = YunfastPayEnum::MALL_ORDER)
- {
- return static::find()
- ->where(['refund_id' => $refund_id, 'refund_source' => $refund_source])
- ->one();
- }
- /**
- * @return boolean
- */
- public function isRefundOk()
- {
- return $this->status == '100' ? true : false;
- }
- /**
- * 修改状态
- *
- * @param string $status
- * @return boolean
- */
- public function changeStatus(string $status)
- {
- $this->status = $status;
- return $this->save();
- }
- /**
- * 通过订单号获取订单
- *
- * @param integer $mall_id
- * @param string $order_no
- * @return static|null
- */
- public static function getOrderByNo(int $mall_id, string $order_no)
- {
- return static::find()
- ->where(['order_no' => $order_no])
- ->one();
- }
- }
|