SaasStoreUnionLevel.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * 厦门云联储网络科技有限公司
  4. * https://www.baokuaiyun.com
  5. * Copyright (c) 2023 爆块云 All rights reserved.
  6. */
  7. namespace app\models;
  8. use Yii;
  9. use yii\behaviors\TimestampBehavior;
  10. use yii\db\ActiveRecord;
  11. /**
  12. * This is the model class for table "{{%saas_partner_level}}".
  13. *
  14. * @property integer $id
  15. * @property integer $level
  16. * @property string $name
  17. * @property string $rate
  18. * @property string $achieve
  19. * @property integer $is_delete
  20. * @property integer $status
  21. * @property integer $created_at
  22. * @property integer $updated_at
  23. */
  24. class SaasStoreUnionLevel extends \yii\db\ActiveRecord
  25. {
  26. /**
  27. * @inheritdoc
  28. */
  29. public static function tableName()
  30. {
  31. return '{{%saas_store_union_level}}';
  32. }
  33. public function behaviors()
  34. {
  35. return [
  36. [
  37. 'class' => TimestampBehavior::class,
  38. 'attributes' => [
  39. ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'],
  40. ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']
  41. ]
  42. ]
  43. ];
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function rules()
  49. {
  50. return [
  51. [['level', 'status','is_delete'], 'integer'],
  52. [['rate','achieve'], 'number'],
  53. [['name'], 'string'],
  54. [['created_at', 'updated_at'], 'safe']
  55. ];
  56. }
  57. /**
  58. * @inheritdoc
  59. */
  60. public function attributeLabels()
  61. {
  62. return [
  63. 'id' => 'ID',
  64. 'level' => '等级',
  65. 'name' => '名称',
  66. 'rate' => '比例',
  67. 'status' => '状态',
  68. 'created_at' => '创建时间',
  69. 'updated_at' => '更新时间',
  70. ];
  71. }
  72. public static function levelUp($store_id,$pool_id){
  73. $achieve = StoreUnionPoolDetail::find()->where(['store_id'=>$store_id,'pool_id'=>$pool_id])->sum('total_pv')?:0;
  74. $level = SaasStoreUnionLevel::find()->andWhere(['<=','achieve',$achieve])->orderBy('achieve desc')->one();
  75. if (!empty($level)){
  76. $union = SaasStoreUnion::find()->where(['store_id'=>$store_id])->one();
  77. if (empty($union)){
  78. $union = new SaasStoreUnion();
  79. $union->store_id = $store_id;
  80. }
  81. $storeLevel = SaasStoreUnionLevel::findOne($union->level_id);
  82. if (!$union->level_id || empty($storeLevel) || $storeLevel->level < $level->level){
  83. $union->level_id = $level->id;
  84. $union->save();
  85. }
  86. }
  87. }
  88. }