BossPoolPrizePerformance.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace addons\Boss\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_boss_bonus_pool_performance}}".
  7. *
  8. * @property int $id ID
  9. * @property int $mall_id 商城ID
  10. * @property int $user_id 用户ID
  11. * @property float $performance 商品业绩
  12. * @property string $date 日期
  13. * @property int $status 状态[-1删除;0禁用;1正常]
  14. * @property int $created_at 创建时间
  15. * @property int $updated_at 更新时间
  16. */
  17. class BossPoolPrizePerformance extends \common\models\base\BaseActiveRecord
  18. {
  19. /**
  20. * {@inheritdoc}
  21. */
  22. public static function tableName()
  23. {
  24. return '{{%addons_boss_pool_prize_performance}}';
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function rules()
  30. {
  31. return [
  32. [['mall_id', 'user_id', 'status', 'created_at', 'updated_at'], 'integer'],
  33. [['performance'], 'number'],
  34. [['date'], 'string', 'max' => 8],
  35. ];
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function attributeLabels()
  41. {
  42. return [
  43. 'id' => 'ID',
  44. 'mall_id' => '商城ID',
  45. 'user_id' => '用户ID',
  46. 'performance' => '商品业绩',
  47. 'date' => '日期',
  48. 'status' => '状态[-1删除;0禁用;1正常]',
  49. 'created_at' => '创建时间',
  50. 'updated_at' => '更新时间',
  51. ];
  52. }
  53. /**
  54. * @Description: 保存数据
  55. * @Author: zsan
  56. * @DateTime 2023-10-12 09:32:36
  57. * @param array $data
  58. * @return bool|self
  59. */
  60. public static function setData(array $data)
  61. {
  62. try {
  63. $model = self::findOne(['user_id' => $data['user_id'], 'mall_id' => $data['mall_id'], 'date' => $data['date'], 'status' => StatusEnum::ENABLED]);
  64. if (empty($model)) {
  65. $model = new self();
  66. $model->loadDefaultValues();
  67. }
  68. $data['performance'] = $model['performance'] + $data['performance'];
  69. if (!$model->load($data, '') || !$model->save()) {
  70. throw new \Exception($model->getErrorMessage());
  71. }
  72. return $model;
  73. } catch (\Exception $e) {
  74. self::setStaticError($e->getMessage());
  75. return false;
  76. }
  77. }
  78. }