| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace addons\ReservationService\common\models;
- use common\enums\StatusEnum;
- use Yii;
- /**
- * This is the model class for table "{{%addons_reservation_service_level}}".
- *
- * @property int $id ID
- * @property int $mall_id 商城ID
- * @property string $name 名称
- * @property int $level 等级
- * @property float $item_commission 项目佣金
- * @property int $item_commission_type 0百分比;1固定值
- * @property int $enable_distribution_commission 享受分销提成奖励; 0关闭,1开启
- * @property float $level1_commission 一级佣金
- * @property int $level1_commission_type 0百分比;1固定值
- * @property float $level2_commission 一级佣金
- * @property int $level2_commission_type 0百分比;1固定值
- * @property int $status 状态;1正常,0禁用,-1删除
- * @property int $created_at 创建时间
- * @property int $updated_at 更新时间
- */
- class ReservationServiceLevel extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_reservation_service_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'level', 'item_commission_type', 'enable_distribution_commission', 'level1_commission_type', 'level2_commission_type', 'status', 'created_at', 'updated_at'], 'integer'],
- [['item_commission', 'level1_commission', 'level2_commission'], 'number'],
- [['name'], 'string', 'max' => 64],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'name' => '名称',
- 'level' => '等级',
- 'item_commission' => '项目佣金',
- 'item_commission_type' => '0百分比;1固定值',
- 'enable_distribution_commission' => '享受分销提成奖励; 0关闭,1开启',
- 'level1_commission' => '一级佣金',
- 'level1_commission_type' => '0百分比;1固定值',
- 'level2_commission' => '一级佣金',
- 'level2_commission_type' => '0百分比;1固定值',
- 'status' => '状态;1正常,0禁用,-1删除',
- 'created_at' => '创建时间',
- 'updated_at' => '更新时间',
- ];
- }
- public static function getLevelWeights($mall_id)
- {
- $list = self::find()->select('level')->where(['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED], 'mall_id' => $mall_id])->column();
- $newList = [];
- for ($i = 1; $i <= 10; $i++) {
- $newList[] = [
- 'name' => '等级' . $i,
- 'level' => $i,
- 'disabled' => in_array($i, $list),
- ];
- }
- return $newList;
- }
- public static function setData(array $params)
- {
- try {
- if (!empty($params['id'])) {
- if (!empty(self::getOne([['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]],
- ['level' => $params['level']], ['mall_id' => $params['mall_id']], ['<>', 'id', $params['id']]]))) throw new \Exception("当前等级已经存在");
- $model = self::findOne(['and', ['id' => $params['id'], 'mall_id' => $params['mall_id']], ['<>', 'status', StatusEnum::DELETE]]);
- if (empty($model)) throw new \Exception('等级不存在或已删除');
- // 判断等级是否有被修改
- if ($model->level != $params['level']) {
- // 判断该等级下是否有用户存在
- $boss = ReservationServiceUser::find()->where(['mall_id' => $model->mall_id, 'level' => $model->level, 'status' => StatusEnum::ENABLED])->asArray()->one();
- if ($boss) throw new \Exception('该等级下存在技师,不能被修改');
- }
- } else {
- // 判断当前等级是否已经存在
- if (!empty(self::getOne([['status' => [StatusEnum::DISABLED, StatusEnum::ENABLED]], ['mall_id' => $params['mall_id']], ['level' => $params['level']]]))) throw new \Exception("当前等级已经存在");
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- }
- if (!$model->load($params, '') || !$model->save()) {
- throw new \Exception($model->getErrorMessage());
- }
- return $model;
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- }
|