| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace common\models\statistics;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "qimall_payment_type_refund_statistics_details".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $payment_type 支付方式
- * @property int $statistics_id 关联qimall_payment_type_refund_statistics表
- * @property string $trade_type 聚合支付具体的支付方式
- * @property float $total_refund_money 成功退款的退款金额
- * @property float $total_pay_money 成功退款的订单的实付金额
- * @property int $date
- * @property int $created_at
- * @property int $updated_at
- */
- class PaymentTypeRefundStatisticsDetails extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return 'qimall_payment_type_refund_statistics_details';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'status', 'payment_type', 'statistics_id', 'date', 'created_at', 'updated_at'], 'integer'],
- [['total_refund_money', 'total_pay_money'], 'number'],
- [['trade_type'], 'string', 'max' => 100],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'status' => 'Status',
- 'payment_type' => 'Payment Type',
- 'statistics_id' => 'Statistics ID',
- 'trade_type' => 'Trade Type',
- 'total_refund_money' => 'Total Refund Money',
- 'total_pay_money' => 'Total Pay Money',
- 'date' => 'Date',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @param array $data
- *
- * @return array
- */
- public static function setData(array $data): array
- {
- $models = [];
- foreach ($data as $item) {
- $model = self::findOne([
- 'mall_id' => $item['mall_id'],
- 'status' => StatusEnum::ENABLED,
- 'statistics_id' => $item['statistics_id'],
- 'date' => $item['date'],
- 'payment_type' => $item['payment_type'],
- 'trade_type' => $item['trade_type'],
- ]);
- if (!$model) {
- $model = new self();
- $model->loadDefaultValues();
- $model->load($item, '');
- } else {
- $model->total_refund_money += $item['total_refund_money'];
- $model->total_pay_money += $item['total_pay_money'];
- }
- $saveRes = $model->save();
- if (!$saveRes) {
- throw new \RuntimeException('数据写入失败');
- }
- $models[] = $model;
- }
- return $models;
- }
- }
|