ServeBonusUpgradeCount.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace addons\ServeBonus\common\models;
  3. use common\enums\StatusEnum;
  4. use Yii;
  5. use yii\db\Exception;
  6. /**
  7. * This is the model class for table "{{%addons_servebonus_upgrade_count}}".
  8. *
  9. * @property int $id
  10. * @property int|null $mall_id 商城ID
  11. * @property int|null $user_id 服务商ID
  12. * @property int|null $direct_num 好友人数
  13. * @property float|null $achievement 服务商团队业绩,单位:元
  14. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  15. * @property int|null $created_at 创建时间
  16. * @property int|null $updated_at 修改时间
  17. */
  18. class ServeBonusUpgradeCount extends \common\models\base\BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_servebonus_upgrade_count}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id', 'user_id', 'direct_num', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['achievement'], 'number'],
  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. 'direct_num' => '好友人数',
  47. 'achievement' => '服务商团队业绩,单位:元',
  48. 'status' => '状态[-1:删除;0:禁用;1启用]',
  49. 'created_at' => '创建时间',
  50. 'updated_at' => '修改时间',
  51. ];
  52. }
  53. /**
  54. * 保存业绩
  55. * @Author: lun
  56. * @DateTime: 2023/4/1 0001 15:34
  57. * @Copyright: copyright (c) 2021 广东七件事集团
  58. * @param $mall_id
  59. * @param $user_id
  60. * @param int $direct_num
  61. * @param int $achievement
  62. * @return bool
  63. */
  64. public static function setData($mall_id, $user_id, $direct_num = 0, $achievement = 0)
  65. {
  66. try {
  67. $model = self::findOne(['user_id' => $user_id, 'status' => StatusEnum::ENABLED]);
  68. if (empty($model)) {
  69. $model = new self();
  70. $model->mall_id = $mall_id;
  71. $model->user_id = $user_id;
  72. $model->loadDefaultValues();
  73. }
  74. !empty($direct_num) && $model->direct_num += $direct_num;
  75. !empty($achievement) && $model->achievement += $achievement;
  76. if (!$model->save()) throw new Exception($model->getErrorMessage());
  77. return true;
  78. } catch (\Exception $e) {
  79. self::setStaticError($e->getMessage());
  80. return false;
  81. }
  82. }
  83. }