ServeBonusAchievement.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace addons\ServeBonus\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\user\User;
  5. use Yii;
  6. use yii\db\Exception;
  7. /**
  8. * This is the model class for table "{{%addons_servebonus_achievement}}".
  9. *
  10. * @property int $id
  11. * @property int $mall_id 商城ID
  12. * @property int $user_id 用户ID
  13. * @property int $buy_uid 购买者uid
  14. * @property int $level 出单用户等级
  15. * @property int $order_id 订单ID
  16. * @property int $order_no 订单编号
  17. * @property int $prize 出单奖励,单位:元
  18. * @property int $average_count 结算人数
  19. * @property int $date 出单日期,格式:20220124
  20. * @property int $is_settlement 是否已结算【0否,1是】
  21. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  22. * @property int $created_at
  23. * @property int $updated_at
  24. */
  25. class ServeBonusAchievement extends \common\models\base\BaseActiveRecord
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public static function tableName()
  31. {
  32. return '{{%addons_servebonus_achievement}}';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function rules()
  38. {
  39. return [
  40. [['mall_id', 'user_id', 'buy_uid', 'level', 'order_id', 'average_count', 'date', 'is_settlement', 'status', 'created_at', 'updated_at'], 'integer'],
  41. [['order_no'], 'string'],
  42. [['prize'], 'number'],
  43. ];
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function attributeLabels()
  49. {
  50. return [
  51. 'id' => 'ID',
  52. 'mall_id' => '商城ID',
  53. 'user_id' => '用户ID',
  54. 'buy_uid' => '购买者uid',
  55. 'level' => '出单用户等级',
  56. 'order_id' => '订单ID',
  57. 'order_no' => '订单编号',
  58. 'prize' => '出单奖励,单位:元',
  59. 'average_count' => '结算人数',
  60. 'date' => '出单日期,格式:20220124',
  61. 'is_settlement' => '是否已结算【0否,1是】',
  62. 'status' => '状态[-1:删除;0:禁用;1启用]',
  63. 'created_at' => 'Created At',
  64. 'updated_at' => 'Updated At',
  65. ];
  66. }
  67. /**
  68. * 关联用户
  69. * @Author: lun
  70. * @DateTime: 2022/1/26 0026 18:26
  71. * @Copyright: copyright (c) 2021 广东七件事集团
  72. * @return \yii\db\ActiveQuery
  73. */
  74. public function getUser()
  75. {
  76. return $this->hasOne(User::class, ['id' => 'user_id']);
  77. }
  78. /**
  79. * 关联用户
  80. * @Author: lun
  81. * @DateTime: 2022/1/26 0026 18:26
  82. * @Copyright: copyright (c) 2021 广东七件事集团
  83. * @return \yii\db\ActiveQuery
  84. */
  85. public function getBuy()
  86. {
  87. return $this->hasOne(User::class, ['id' => 'buy_uid']);
  88. }
  89. /**
  90. * 保存数据
  91. * @Author: lun
  92. * @DateTime: 2022/1/25 0025 17:28
  93. * @Copyright: copyright (c) 2021 广东七件事集团
  94. * @param $params
  95. * @return bool
  96. */
  97. public static function setData($params)
  98. {
  99. try {
  100. $model = self::findOne(['mall_id' => $params['mall_id'], 'order_id' => $params['order_id'], 'status' => StatusEnum::ENABLED]);
  101. if (!empty($model)) return true;
  102. $model = new self();
  103. $model->loadDefaultValues();
  104. if (!$model->load($params, '') || !$model->save()) {
  105. throw new Exception($model->getErrorMessage());
  106. }
  107. return true;
  108. } catch (\Exception $e) {
  109. self::setStaticError($e->getMessage());
  110. return false;
  111. }
  112. }
  113. /**
  114. * 获取出单列表
  115. * @Author: lun
  116. * @DateTime: 2022/1/25 0025 17:40
  117. * @Copyright: copyright (c) 2021 广东七件事集团
  118. * @param array $cond
  119. * @param array $with
  120. * @param bool $is_array
  121. * @param string $select
  122. * @return array|\yii\db\ActiveRecord[]
  123. */
  124. public static function getServeBonusAchievement(array $cond=[], array $with=[],bool $is_array=true,string $select='*'){
  125. $default_cond = [['=','status',StatusEnum::ENABLED]];
  126. $cond = array_merge($default_cond,$cond);
  127. $query = self::find()->select($select);
  128. self::paramPack(['where'=>$cond, 'with'=>$with],$query);
  129. $data = $query->asArray($is_array)->all();
  130. return $data;
  131. }
  132. }