| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- namespace addons\Agent\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use Yii;
- /**
- * This is the model class for table "qimall_addons_agent_commission_level_setting".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $level
- * @property string $commission_type 分佣类型:积分score;佣金:commission
- * @property string $from_type 分佣类型:经销Agent;幸运平团:Lucky_group
- * @property int $is_percent_team 渠道奖类型 0百分比 1 固定金额
- * @property int $is_percent_equal 平级奖类型 0百分比 1 固定金额
- * @property int $is_percent_over 越级奖类型 0百分比 1 固定金额
- * @property int $is_percent_extra 额外奖类型 0百分比 1 固定金额
- * @property float $agent_team_prize 渠道奖
- * @property float $agent_equal_prize 平级奖
- * @property float $agent_over_prize 越级奖
- * @property float $agent_extra_prize 额外奖
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- * @property int $is_repurchase_subsidy 是否开启每月复购补贴奖[0否 1是]
- * @property string|null $repurchase_subsidy_condition 每月复购补贴奖奖励条件
- */
- class AgentCommissionLevelSetting extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_agent_commission_level_setting}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id'], 'required'],
- [['mall_id', 'level', 'is_percent_team', 'is_percent_equal', 'is_percent_over', 'is_percent_extra', 'status', 'created_at', 'updated_at','is_alone_agent_equal_prize', 'is_repurchase_subsidy'], 'integer'],
- [['agent_team_prize', 'agent_equal_prize', 'agent_over_prize', 'agent_extra_prize','team_achievement'], 'number'],
- [['commission_type', 'from_type'], 'string', 'max' => 255],
- [['alone_agent_equal_prize_info'], 'string', 'max' => 1000],
- [['repurchase_subsidy_condition'], 'string']
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'level' => 'Level',
- 'commission_type' => '分佣类型:积分score;佣金:commission',
- 'from_type' => '分佣类型:经销Agent;幸运平团:Lucky_group',
- 'is_percent_team' => '渠道奖类型 0百分比 1 固定金额',
- 'is_percent_equal' => '平级奖类型 0百分比 1 固定金额',
- 'is_percent_over' => '越级奖类型 0百分比 1 固定金额',
- 'is_percent_extra' => '额外奖类型 0百分比 1 固定金额',
- 'agent_team_prize' => '渠道奖',
- 'agent_equal_prize' => '平级奖',
- 'agent_over_prize' => '越级奖',
- 'agent_extra_prize' => '额外奖',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'is_repurchase_subsidy' => '是否开启每月复购补贴奖[0否 1是]',
- 'repurchase_subsidy_condition' => '每月复购补贴奖奖励条件',
- ];
- }
- public static function setData($params)
- {
- try{
- if (!empty($params['level'])&&!empty($params['from_type'])&&!empty($params['commission_type'])) {
- $where = [
- 'level' => $params['level'],
- 'mall_id' => $params['mall_id'],
- 'from_type'=>$params['from_type'],
- 'commission_type'=>$params['commission_type'],
- 'status' => [StatusEnum::ENABLED]];
- $model = self::findOne($where);
- if (empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- }
- } else {
- $model = new self();
- $model->loadDefaultValues();
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new \Exception($model->getErrorMessage());
- }
- return true;
- }catch(\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- public static function del($params){
- try{
- $model = self::updateAll(['status'=>StatusEnum::DELETE],['level'=>$params['level'],'mall_id'=>$params['mall_id']]);
- if(empty($model)) throw new \Exception("删除失败");
- return true;
- }catch (\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|