WriteOffUser.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace addons\WriteOff\common\models;
  3. use Yii;
  4. use common\models\user\User;
  5. use common\enums\StatusEnum;
  6. use common\models\mall\MallAddons;
  7. /**
  8. * This is the model class for table "{{%addons_write_off_user}}".
  9. *
  10. * @property int $id
  11. * @property int $mall_id 商城ID
  12. * @property int $user_id 用户ID
  13. * @property int $store_id
  14. * @property int $level 股东等级
  15. * @property float $commission 核销佣金,单位:元
  16. * @property float $promote_commission 促销佣金,单位:元
  17. * @property float $manage_commission 管理佣金,单位:元
  18. * @property float $total_commission 累计总佣金,单位:元
  19. * @property int|null $is_enable_manage_reward 是否开启管理奖[0:关闭;1启用]
  20. * @property int|null $status 状态[-1:删除;0:禁用;1启用]
  21. * @property int $created_at 创建时间
  22. * @property int $updated_at 修改时间
  23. */
  24. class WriteOffUser extends \common\models\base\BaseActiveRecord
  25. {
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%addons_write_off_user}}';
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. public function rules()
  37. {
  38. return [
  39. [['mall_id', 'user_id', 'store_id', 'level', 'is_enable_manage_reward', 'status', 'created_at', 'updated_at','total_num'], 'integer'],
  40. [['commission', 'promote_commission', 'manage_commission', 'total_commission'], 'number'],
  41. ];
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function attributeLabels()
  47. {
  48. return [
  49. 'id' => 'ID',
  50. 'mall_id' => 'Mall ID',
  51. 'user_id' => 'User ID',
  52. 'store_id' => 'Store ID',
  53. 'level' => 'Level',
  54. 'commission' => 'Commission',
  55. 'promote_commission' => 'Promote Commission',
  56. 'manage_commission' => 'Manage Commission',
  57. 'total_commission' => 'Total Commission',
  58. 'is_enable_manage_reward' => 'Is Enable Manage Reward',
  59. 'status' => 'Status',
  60. 'created_at' => 'Created At',
  61. 'updated_at' => 'Updated At',
  62. 'total_num' => 'Total Num',
  63. ];
  64. }
  65. public function getUser()
  66. {
  67. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id');
  68. }
  69. public function getLevel(){
  70. return $this->hasOne(WriteOffLevel::class, ['level' => 'level','mall_id'=>'mall_id'])->andWhere(['<>','status',StatusEnum::DELETE]);
  71. }
  72. public static function setData(array $params){
  73. try{
  74. if(!empty($params['user_id'])){
  75. $model = self::findOne(['user_id' => $params['user_id'],'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]);
  76. if(empty($model)) {
  77. $model = new self();
  78. $model->loadDefaultValues();
  79. $model->mall_id = $params['mall_id'];
  80. }
  81. }elseif(!empty($params['id'])){
  82. $model = self::findOne($params['id']);
  83. if(empty($model)) throw new \Exception('数据不存在或已删除');
  84. } else {
  85. throw new \Exception('数据不存在或已删除');
  86. }
  87. if(!$model->load($params,'') || !$model->save()){
  88. throw new \Exception($model->getErrorMessage());
  89. }
  90. return $model;
  91. }catch(\Exception $e){
  92. self::setStaticError($e->getMessage());
  93. return false;
  94. }
  95. }
  96. /**
  97. * @desc:推广中心-调用
  98. * @return array
  99. */
  100. public static function getIncomeInfo(array $params){
  101. $is_install = MallAddons::isInstall($params['mall_id'], $params['addons_name']);
  102. $data['total_commission'] = 0;
  103. $data['is_install'] = 0;
  104. $data['is_show_at_center'] = 1;
  105. if($is_install){
  106. $model = self::findOne(['user_id'=>$params['user_id'],'mall_id'=>$params['mall_id'],'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]);
  107. $data['total_commission'] = $model['total_commission']??0;
  108. $data['is_install'] = $is_install;
  109. }
  110. return $data;
  111. }
  112. }