HappinessWeightPoolOrderLog.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace addons\Happiness\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. /**
  7. * This is the model class for table "{{%addons_weight_bonus_pool_order_log}}".
  8. *
  9. * @property int $id ID
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 用户ID
  12. * @property float $amount 进入奖金池金额
  13. * @property float $before_amount 变动前金额
  14. * @property float $after_amount 变动后金额
  15. * @property float $price 订单金额(销售价)
  16. * @property float $pay_price 订单实付金额
  17. * @property int $order_id 订单ID
  18. * @property string $order_no 订单编号
  19. * @property int $status 状态[-1删除;0禁用;1正常]
  20. * @property string $date 日期
  21. * @property int $settlement_status 结算状态[0未结算;1已结算]
  22. * @property string $desc 备注
  23. * @property int $created_at 创建时间
  24. * @property int $updated_at 更新时间
  25. */
  26. class HappinessWeightPoolOrderLog extends \common\models\base\BaseActiveRecord
  27. {
  28. /**
  29. * {@inheritdoc}
  30. */
  31. public static function tableName()
  32. {
  33. return '{{%addons_happiness_weight_pool_order_log}}';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function rules()
  39. {
  40. return [
  41. [['mall_id', 'user_id', 'order_id', 'status', 'settlement_status', 'created_at', 'updated_at'], 'integer'],
  42. [['amount','before_amount','after_amount','price','pay_price'], 'number'],
  43. [['order_no'], 'string', 'max' => 100],
  44. [['desc'], 'string', 'max' => 100],
  45. [['date'], 'string', 'max' => 15],
  46. ];
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function attributeLabels()
  52. {
  53. return [
  54. 'id' => 'ID',
  55. 'mall_id' => '商城ID',
  56. 'user_id' => '用户ID',
  57. 'amount' => '进入奖金池金额',
  58. 'price' => '订单金额(销售价)',
  59. 'pay_price' => '订单实付金额',
  60. 'before_amount' => '变动前金额',
  61. 'after_amount' => '变动后金额',
  62. 'order_id' => '订单ID',
  63. 'order_no' => '订单编号',
  64. 'status' => '状态[-1删除;0禁用;1正常]',
  65. 'date' => '日期',
  66. 'settlement_status' => '结算状态[0未结算;1已结算]',
  67. 'created_at' => '创建时间',
  68. 'updated_at' => '更新时间',
  69. ];
  70. }
  71. /**
  72. * @Description: 保存数据
  73. * @Author: zfh
  74. * @DateTime 2024-5-5 09:32:36
  75. * @param array $data
  76. * @return bool|self
  77. */
  78. public static function setData(array $data)
  79. {
  80. try {
  81. $model = self::findOne(['order_id' => $data['order_id'], 'mall_id' => $data['mall_id'], 'date' => $data['date'], 'status' => StatusEnum::ENABLED]);
  82. if (empty($model)) {
  83. $model = new self();
  84. $model->loadDefaultValues();
  85. }
  86. if (!$model->load($data, '') || !$model->save()) {
  87. throw new \Exception($model->getErrorMessage());
  88. }
  89. return $model;
  90. } catch (\Exception $e) {
  91. self::setStaticError($e->getMessage());
  92. return false;
  93. }
  94. }
  95. public function getUser()
  96. {
  97. return $this->hasOne(User::class, ['id' => 'user_id']);
  98. }
  99. public static function addData($data)
  100. {
  101. try {
  102. $model = new self();
  103. $model->loadDefaultValues();
  104. if (!$model->load($data, '') || !$model->save()) {
  105. throw new \Exception($model->getErrorMessage());
  106. }
  107. return $model;
  108. } catch (\Exception $e) {
  109. self::setStaticError($e->getMessage());
  110. return false;
  111. }
  112. }
  113. }