BossPoolPrizeOrderLog.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace addons\Boss\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_boss_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 int $order_id 订单ID
  14. * @property string $order_no 订单编号
  15. * @property int $status 状态[-1删除;0禁用;1正常]
  16. * @property string $date 日期
  17. * @property int $settlement_status 结算状态[0未结算;1已结算]
  18. * @property int $created_at 创建时间
  19. * @property int $updated_at 更新时间
  20. */
  21. class BossPoolPrizeOrderLog extends \common\models\base\BaseActiveRecord
  22. {
  23. /**
  24. * {@inheritdoc}
  25. */
  26. public static function tableName()
  27. {
  28. return '{{%addons_boss_pool_prize_order_log}}';
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function rules()
  34. {
  35. return [
  36. [['mall_id', 'user_id', 'order_id', 'status', 'settlement_status', 'created_at', 'updated_at'], 'integer'],
  37. [['amount'], 'number'],
  38. [['order_no'], 'string', 'max' => 100],
  39. [['date'], 'string', 'max' => 8],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'mall_id' => '商城ID',
  50. 'user_id' => '用户ID',
  51. 'amount' => '进入奖金池金额',
  52. 'order_id' => '订单ID',
  53. 'order_no' => '订单编号',
  54. 'status' => '状态[-1删除;0禁用;1正常]',
  55. 'date' => '日期',
  56. 'settlement_status' => '结算状态[0未结算;1已结算]',
  57. 'created_at' => '创建时间',
  58. 'updated_at' => '更新时间',
  59. ];
  60. }
  61. /**
  62. * @Description: 保存数据
  63. * @Author: zsan
  64. * @DateTime 2023-10-12 09:32:36
  65. * @param array $data
  66. * @return bool|self
  67. */
  68. public static function setData(array $data)
  69. {
  70. try {
  71. $model = self::findOne(['order_id' => $data['order_id'], 'mall_id' => $data['mall_id'], 'date' => $data['date'], 'status' => StatusEnum::ENABLED]);
  72. if (empty($model)) {
  73. $model = new self();
  74. $model->loadDefaultValues();
  75. }
  76. if (!$model->load($data, '') || !$model->save()) {
  77. throw new \Exception($model->getErrorMessage());
  78. }
  79. return $model;
  80. } catch (\Exception $e) {
  81. self::setStaticError($e->getMessage());
  82. return false;
  83. }
  84. }
  85. public function getUser()
  86. {
  87. return $this->hasOne(User::class, ['id' => 'user_id']);
  88. }
  89. }