CloudStockFillStatistics.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace addons\CloudStock\common\models;
  3. use common\enums\StatusEnum;
  4. use common\models\base\BaseActiveRecord;
  5. use common\models\user\User;
  6. use Yii;
  7. /**
  8. * This is the model class for table "qimall_addons_cloud_stock_fill_statistics".
  9. *
  10. * @property int $id 自增id
  11. * @property int $mall_id 商城id
  12. * @property int $user_id 增加库存代理商用户id
  13. * @property int $level 等级
  14. * @property int $self_num 自身补货数量
  15. * @property int $direct_num 直推们的数量,等级一致
  16. * @property int $indirect_num 间推们数量,等级一致
  17. * @property int $start
  18. * @property int $end
  19. * @property float $money
  20. * @property int $award_proportion_settlement_type
  21. * @property int $is_upgrade_bag_give_goods
  22. * @property int $is_equal_2_step
  23. * @property string $award_proportion
  24. * @property int $status 状态[-1:删除;0:禁用;1启用]
  25. * @property int $created_at
  26. * @property int $updated_at
  27. */
  28. class CloudStockFillStatistics extends BaseActiveRecord
  29. {
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public static function tableName()
  34. {
  35. return '{{%addons_cloud_stock_fill_statistics}}';
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function rules()
  41. {
  42. return [
  43. [['mall_id', 'user_id', 'self_num', 'direct_num', 'indirect_num'], 'required'],
  44. [['mall_id', 'user_id', 'level', 'start', 'end', 'award_proportion_settlement_type', 'is_upgrade_bag_give_goods', 'is_equal_2_step', 'status', 'created_at', 'updated_at','award_proportion_calculate_type'], 'integer'],
  45. [['award_proportion', ], 'string'],
  46. [['money','self_num', 'direct_num', 'indirect_num'], 'number'],
  47. ];
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function attributeLabels()
  53. {
  54. return [
  55. 'id' => '自增id',
  56. 'mall_id' => '商城id',
  57. 'user_id' => '增加库存代理商用户id',
  58. 'level' => '等级',
  59. 'self_num' => '自身补货数量',
  60. 'direct_num' => '直推们的数量,等级一致',
  61. 'indirect_num' => '间推们数量,等级一致',
  62. 'start' => 'Start',
  63. 'end' => 'End',
  64. 'money' => '奖励金额',
  65. 'award_proportion_settlement_type' => 'Is Award Proportion Settlement',
  66. 'is_upgrade_bag_give_goods' => 'Is Upgrade Bag Give Goods',
  67. 'is_equal_2_step' => 'Is Equal 2 Step',
  68. 'award_proportion' => 'award_proportion',
  69. 'status' => '状态[-1:删除;0:禁用;1启用]',
  70. 'created_at' => 'Created At',
  71. 'updated_at' => 'Updated At',
  72. ];
  73. }
  74. public function getUser()
  75. {
  76. return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id');
  77. }
  78. public static function setData(array $params)
  79. {
  80. try {
  81. if (!empty($params['id'])) {
  82. $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
  83. if (empty($model)) throw new \Exception('服务不存在或已删除');
  84. } else {
  85. $model = new self();
  86. $model->loadDefaultValues();
  87. }
  88. if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
  89. if (!$model->save()) throw new \Exception($model->getErrorMessage());
  90. return $model;
  91. } catch (\Exception $e) {
  92. self::$static_error = $e->getMessage();
  93. return false;
  94. }
  95. }
  96. }