BusinessBonusUpgradeRecord.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace addons\BusinessBonus\common\models;
  3. use common\models\user\User;
  4. use Yii;
  5. /**
  6. * This is the model class for table "{{%addons_business_bonus_upgrade_record}}".
  7. *
  8. * @property int $id
  9. * @property int $mall_id 商城ID
  10. * @property float|null $bonus_rate 升级后的分红比例,仅记录作用
  11. * @property int|null $upgrade_type 升级方式:0未知,1无条件,2前端申请,3购买知道商品,4后台添加,5后台调整
  12. * @property int|null $upgrade_time 升级时间
  13. * @property string|null $extra_data 额外信息,json格式,根据不同升级方式保存不同信息
  14. * @property int|null $status 状态:-1删除,0禁用,1启用
  15. * @property int|null $created_at 创建时间
  16. * @property int|null $updated_at 更新时间
  17. */
  18. class BusinessBonusUpgradeRecord extends \common\models\base\BaseActiveRecord
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. public static function tableName()
  24. {
  25. return '{{%addons_business_bonus_upgrade_record}}';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. public function rules()
  31. {
  32. return [
  33. [['mall_id', 'user_id', 'business_bonus_level', 'upgrade_type', 'upgrade_time', 'status', 'created_at', 'updated_at'], 'integer'],
  34. [['bonus_rate'], 'number'],
  35. [['extra_data'], 'safe'],
  36. ];
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'id' => 'ID',
  45. 'mall_id' => '商城ID',
  46. 'user_id' => '会员ID',
  47. 'business_bonus_level' => '招商员等级',
  48. 'bonus_rate' => '升级后的分红比例,仅记录作用',
  49. 'upgrade_type' => '升级方式:0未知,1无条件,2前端申请,3购买指定商品,4后台添加,5后台调整',
  50. 'upgrade_time' => '升级时间',
  51. 'extra_data' => '额外信息,json格式,根据不同升级方式保存不同信息',
  52. 'status' => '状态:-1删除,0禁用,1启用',
  53. 'created_at' => '创建时间',
  54. 'updated_at' => '更新时间',
  55. ];
  56. }
  57. /**
  58. * 数据设置
  59. */
  60. public static function setData(array $params)
  61. {
  62. try{
  63. if (!isset($params['mall_id']) || empty($params['mall_id'])) throw new Exception('缺少商城ID');
  64. if (isset($params['id']) && !empty($params['id'])) {
  65. $model = self::findOne(['id' => $params['id'], 'mall_id' => $params['mall_id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  66. if(empty($model)) throw new Exception('升级记录不存在或已删除');
  67. } else {
  68. $model = new self();
  69. $model->loadDefaultValues();
  70. $model->mall_id = $params['mall_id'];
  71. }
  72. if (!$model->load($params,'') || !$model->save()) throw new Exception($model->getErrorMessage());
  73. return $model;
  74. }catch(Exception $e){
  75. self::setStaticError($e->getMessage());
  76. return false;
  77. }
  78. }
  79. public function getUser()
  80. {
  81. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id,username');
  82. }
  83. }