PaymentTypeRefundStatisticsDetails.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace common\models\statistics;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "qimall_payment_type_refund_statistics_details".
  7. *
  8. * @property int $id
  9. * @property int $mall_id
  10. * @property int $status 状态[-1:删除;0:禁用;1启用]
  11. * @property int $payment_type 支付方式
  12. * @property int $statistics_id 关联qimall_payment_type_refund_statistics表
  13. * @property string $trade_type 聚合支付具体的支付方式
  14. * @property float $total_refund_money 成功退款的退款金额
  15. * @property float $total_pay_money 成功退款的订单的实付金额
  16. * @property int $date
  17. * @property int $created_at
  18. * @property int $updated_at
  19. */
  20. class PaymentTypeRefundStatisticsDetails extends \common\models\base\BaseActiveRecord
  21. {
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public static function tableName()
  26. {
  27. return 'qimall_payment_type_refund_statistics_details';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function rules()
  33. {
  34. return [
  35. [['mall_id', 'status', 'payment_type', 'statistics_id', 'date', 'created_at', 'updated_at'], 'integer'],
  36. [['total_refund_money', 'total_pay_money'], 'number'],
  37. [['trade_type'], 'string', 'max' => 100],
  38. ];
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function attributeLabels()
  44. {
  45. return [
  46. 'id' => 'ID',
  47. 'mall_id' => 'Mall ID',
  48. 'status' => 'Status',
  49. 'payment_type' => 'Payment Type',
  50. 'statistics_id' => 'Statistics ID',
  51. 'trade_type' => 'Trade Type',
  52. 'total_refund_money' => 'Total Refund Money',
  53. 'total_pay_money' => 'Total Pay Money',
  54. 'date' => 'Date',
  55. 'created_at' => 'Created At',
  56. 'updated_at' => 'Updated At',
  57. ];
  58. }
  59. /**
  60. * @param array $data
  61. *
  62. * @return array
  63. */
  64. public static function setData(array $data): array
  65. {
  66. $models = [];
  67. foreach ($data as $item) {
  68. $model = self::findOne([
  69. 'mall_id' => $item['mall_id'],
  70. 'status' => StatusEnum::ENABLED,
  71. 'statistics_id' => $item['statistics_id'],
  72. 'date' => $item['date'],
  73. 'payment_type' => $item['payment_type'],
  74. 'trade_type' => $item['trade_type'],
  75. ]);
  76. if (!$model) {
  77. $model = new self();
  78. $model->loadDefaultValues();
  79. $model->load($item, '');
  80. } else {
  81. $model->total_refund_money += $item['total_refund_money'];
  82. $model->total_pay_money += $item['total_pay_money'];
  83. }
  84. $saveRes = $model->save();
  85. if (!$saveRes) {
  86. throw new \RuntimeException('数据写入失败');
  87. }
  88. $models[] = $model;
  89. }
  90. return $models;
  91. }
  92. }