CloudStockAgentOrderRefund.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace addons\CloudStock\common\models;
  3. use common\enums\StatusEnum;
  4. use Exception;
  5. use RuntimeException;
  6. use Yii;
  7. /**
  8. * This is the model class for table "qimall_addons_cloud_stock_agent_order_refund".
  9. *
  10. * @property int $id
  11. * @property int $mall_id
  12. * @property int $order_id 自提订单id
  13. * @property int $order_type 订单类型
  14. * @property int $user_id 用户id
  15. * @property string $order_no 退款编号
  16. * @property int $status 状态[-1:删除;0:禁用;1启用]
  17. * @property int $is_refund 是否已打款 -1 打款失败 0未打款 1打款成功
  18. * @property int $refund_at 打款时间
  19. * @property float $refund_price 退款金额
  20. * @property float $reality_refund_price 实际退款金额
  21. * @property int $created_at
  22. * @property int $updated_at
  23. */
  24. class CloudStockAgentOrderRefund extends \common\models\base\BaseActiveRecord
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return 'qimall_addons_cloud_stock_agent_order_refund';
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['mall_id', 'order_id', 'order_type', 'user_id', 'status', 'is_refund', 'refund_at', 'created_at', 'updated_at'], 'integer'],
  40. [['refund_price', 'reality_refund_price'], 'number'],
  41. [['order_no'], 'string', 'max' => 255],
  42. ];
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function attributeLabels()
  48. {
  49. return [
  50. 'id' => 'ID',
  51. 'mall_id' => 'Mall ID',
  52. 'order_id' => 'Order ID',
  53. 'order_type' => 'Order Type',
  54. 'user_id' => 'User ID',
  55. 'order_no' => 'Order No',
  56. 'status' => 'Status',
  57. 'is_refund' => 'Is Refund',
  58. 'refund_at' => 'Refund At',
  59. 'refund_price' => 'Refund Price',
  60. 'reality_refund_price' => 'Reality Refund Price',
  61. 'created_at' => 'Created At',
  62. 'updated_at' => 'Updated At',
  63. ];
  64. }
  65. /**
  66. * @param array $params
  67. *
  68. * @return bool|self
  69. */
  70. public static function setData(array $params)
  71. {
  72. try {
  73. if (!empty($params['id'])) {
  74. $model = self::findOne(['id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  75. if (!$model) {
  76. throw new RuntimeException('数据不存在或已删除');
  77. }
  78. if ($model->mall_id != $params['mall_id']) {
  79. throw new RuntimeException('不允许操作此数据');
  80. }
  81. } else {
  82. $model = new self();
  83. $model->loadDefaultValues();
  84. }
  85. if (!$model->load($params, '')) {
  86. throw new RuntimeException($model->getErrorMessage());
  87. }
  88. if (!$model->save()) {
  89. throw new RuntimeException($model->getErrorMessage());
  90. }
  91. return $model;
  92. } catch (Exception $e) {
  93. self::$static_error = $e->getMessage();
  94. return false;
  95. }
  96. }
  97. }