AgentTeamAchievement.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace addons\Agent\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use Yii;
  6. /**
  7. * This is the model class for table "qimall_addons_agent_team_achievement".
  8. *
  9. * @property int $id
  10. * @property int $mall_id 商城ID
  11. * @property int $user_id 用户ID
  12. * @property float $personal_performance 个人业绩
  13. * @property float $team_performance 渠道业绩
  14. * @property string $month 月份
  15. * @property float $rate 百分比
  16. * @property int $level 渠道等级
  17. * @property int $is_settlement 是否结算
  18. * @property int $status 状态[-1:删除;0:禁用;1启用]
  19. * @property int $created_at 创建时间
  20. * @property int $updated_at 修改时间
  21. */
  22. class AgentTeamAchievement extends BaseActiveRecord
  23. {
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public static function tableName()
  28. {
  29. return '{{%addons_agent_team_achievement}}';
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function rules()
  35. {
  36. return [
  37. [['mall_id', 'user_id', 'status','is_settlement','level', 'created_at', 'updated_at'], 'integer'],
  38. [['personal_performance','team_performance','rate'], 'number'],
  39. [['month'], 'string', 'max' => 255],
  40. ];
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function attributeLabels()
  46. {
  47. return [
  48. 'id' => 'ID',
  49. 'mall_id' => 'Mall ID',
  50. 'user_id' => 'User ID',
  51. 'money' => 'Money',
  52. 'month' => 'Month',
  53. 'status' => 'Status',
  54. 'created_at' => 'Created At',
  55. 'updated_at' => 'Updated At',
  56. ];
  57. }
  58. public static function setData($params)
  59. {
  60. try {
  61. $model = self::findOne(['mall_id' => $params['mall_id'], 'user_id' => $params['user_id'], 'month' => $params['month'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  62. if (empty($model)) {
  63. $model = new self();
  64. $model->mall_id = $params['mall_id'];
  65. $model->user_id = $params['user_id'];
  66. $model->month = $params['month'];
  67. $model->loadDefaultValues();
  68. }
  69. if (!empty($params['personal_performance'])) $model->personal_performance += $params['personal_performance'];
  70. if (!empty($params['team_performance'])) $model->team_performance += $params['team_performance'];
  71. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  72. return true;
  73. } catch (\Exception $e) {
  74. self::$static_error = $e->getMessage();
  75. return false;
  76. }
  77. }
  78. }