| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- <?php
- namespace addons\Store\common\models;
- use yii\helpers\Json;
- // use app\helpers\SerializeHelper;
- // use app\models\BaseActiveRecord;
- use common\models\order\CommonOrder;
- use common\models\order\CommonOrderDetail;
- use common\models\goods\Goods;
- use common\models\user\UserChildren;
- use common\models\user\UserGrowth;
- use Yii;
- /**
- * This is the model class for table "{{%plugin_store_boss_level}}".
- *
- * @property int $id
- * @property int $mall_id
- * @property int $store_id
- * @property int $level
- * @property string $name
- * @property int $is_auto_upgrade
- * @property string|null $detail
- * @property float $price 平级奖
- * @property float $extra_price 渠道奖
- * @property int $created_at
- * @property int $updated_at
- * @property int $is_delete
- * @property string|null $checked_condition_values 升级条件
- * @property int $is_enable 是否启用
- * @property string|null $checked_condition_keys 升级条件选中的key集合
- * @property int $condition_type 0 未选择、1满足其一 2、满足所有
- * @property int $upgrade_type_goods
- * @property int $upgrade_type_condition
- * @property string|null $goods_warehouse_ids 商品仓库的ID
- * @property string|null $goods_list 商品列表
- * @property int $goods_type 商品升级类型
- * @property int $buy_goods_type 0订单完成 1下单 完成
- * @property float $extra_limit_price 额外奖励上限金额
- * @property int $extra_type 存在额外奖励的条件 1 购物 2 条件 3 任意
- * @property int $is_extra 是否存在额外奖励
- * @property int $extra_is_limit 额外奖励是否存在上限
- */
- class StoreBossLevel extends \common\models\base\BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_store_boss_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'name'], 'required'],
- [['mall_id', 'level', 'is_auto_upgrade', 'created_at', 'updated_at', 'is_delete', 'is_enable', 'condition_type', 'upgrade_type_goods', 'upgrade_type_condition', 'goods_type', 'buy_goods_type', 'extra_type', 'is_extra', 'extra_is_limit', 'store_id'], 'integer'],
- [['detail', 'checked_condition_values', 'checked_condition_keys', 'goods_warehouse_ids', 'goods_list'], 'string'],
- [['price', 'extra_price', 'extra_limit_price'], 'number'],
- [['name'], 'string', 'max' => 45],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => 'Mall ID',
- 'store_id' => 'store_id',
- 'level' => 'Level',
- 'name' => 'Name',
- 'is_auto_upgrade' => 'Is Auto Upgrade',
- 'detail' => 'Detail',
- 'price' => '平级奖',
- 'extra_price' => '渠道奖',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- 'is_delete' => 'Is Delete',
- 'checked_condition_values' => '升级条件',
- 'is_enable' => '是否启用',
- 'checked_condition_keys' => '升级条件选中的key集合',
- 'condition_type' => '0 未选择、1满足其一 2、满足所有',
- 'upgrade_type_goods' => 'Upgrade Type Goods',
- 'upgrade_type_condition' => 'Upgrade Type Condition',
- 'goods_warehouse_ids' => '商品仓库的ID',
- 'goods_list' => '商品列表',
- 'goods_type' => '商品升级类型',
- 'buy_goods_type' => '0订单完成 1下单 完成',
- 'extra_limit_price' => '额外奖励上限金额',
- 'extra_type' => '存在额外奖励的条件 1 购物 2 条件 3 任意',
- 'is_extra' => '是否存在额外奖励',
- 'extra_is_limit' => '额外奖励是否存在上限',
- ];
- }
- /**
- * 获取可升级的等级列表
- * @Author bing
- * @DateTime 2020-11-07 09:59:33
- * @copyright: Copyright (c) 2020 广东七件事集团
- * @param integer $level
- * @param integer $mall_id
- * @param integer $store_id
- * @param string $order
- * @return void|mixed
- */
- public static function getCanLevelList($level,$mall_id = 0,$store_id = 0,$order = 'desc'){
- $mall_id = Yii::$app->mall->id ?? $mall_id;
- return self::find()
- ->where(['mall_id' => $mall_id,'store_id' => $store_id, 'is_enable' => 1, 'is_delete' => 0])
- ->andWhere(['>', 'level', $level])
- ->orderBy("level $order")
- ->all();
- }
- public function getList($mall_id,$store_id)
- {
- $levelList = StoreBossLevel::find()->where([
- 'mall_id' => $mall_id,'store_id' => $store_id, 'is_delete' => 0, 'is_enable' => 1,
- ])->select(['id', 'level', 'name'])->orderBy(['level' => SORT_ASC])->asArray()->all();
- // array_unshift($levelList, [
- //// 'id' => 0,
- //// 'level' => 0,
- //// 'name' => '默认等级'
- //// ]);
- return $levelList;
- }
- public function setData()
- {
- $store = Yii::$app->session->get('o2o');
- try {
- if ($this->equal_price_type == 1) {
- if ($this->price > 100) {
- throw new \Exception('平级奖佣金百分比不能大于100%');
- }
- }
- $level = StoreBossLevel::findOne(['is_delete' => 0, 'mall_id' => $store['mall_id'], 'store_id' => $store['id'], 'level' => $this->level]);
- if ($level) {
- if ($level->id != $this->id) {
- return [
- 'code' => 1,
- 'msg' => '选中的权重已经存在对应的记录'
- ];
- }
- }
- $level = StoreBossLevel::findOne(['is_delete' => 0, 'mall_id' => $store['mall_id'],'store_id' => $store['id'], 'id' => $this->id]);
- if ($level) {
- if ($level->level != $this->level) {
- $boss = StoreBoss::find()->where(['status' => 1, 'mall_id' =>$store['mall_id'],'store_id' => $store['id'], 'level' => $level->level])->asArray()->one();
- if ($boss) {
- return [
- 'code' =>1,
- 'msg' => '当前等级下已存在股东,不可变更等级权重!'
- ];
- }
- }
- }
- if (!$level) {
- $level = new StoreBossLevel();
- $level->is_delete = 0;
- $level->store_id = $store['id'];
- $level->mall_id = $store['mall_id'];
- }
- $level->attributes=$this-> attributes;
- $level->checked_condition_keys = Json::encode($this->checked_condition_keys);
- $level->checked_condition_values = Json::encode($this->checked_condition_values);
- $level->goods_list = Json::encode($this->goods_list);
- $level->goods_warehouse_ids = Json::encode($this->goods_warehouse_ids);
- if (!$level->save()) {
- throw new \Exception($level->getErrorMessage());
- // throw new \Exception($this->responseErrorMsg($level));
- } else {
- return [
- 'code' => 0,
- 'msg' => '保存成功'
- ];
- }
- } catch (\Exception $exception) {
- // $this->error($exception->getMessage());
- return [
- 'code' => 1,
- 'msg' => $exception->getMessage()
- ];
- }
- }
- public function getDetail()
- {
- $weights = (new StoreBossLevelCommon)->getLevelWeights();
- $level = self::findOne(['id' => $this->id, 'is_delete' => 0]);
- if ($level) {
- if ($level->checked_condition_values) {
- $level->checked_condition_values = Json::decode($level->checked_condition_values);
- }
- if ($level->checked_condition_keys) {
- $level->checked_condition_keys = Json::decode($level->checked_condition_keys);
- }
- if ($level->goods_warehouse_ids) {
- $level->goods_warehouse_ids = Json::decode($level->goods_warehouse_ids);
- } else {
- $level->goods_warehouse_ids = [];
- }
- if ($level->goods_list) {
- $level->goods_list = Json::decode($level->goods_list);
- } else {
- $level->goods_list = [];
- }
- return [
- 'code' => 0,
- 'msg' => '',
- 'data' => [
- 'detail' => $level,
- 'weights' => $weights['newList']
- ]
- ];
- }
- }
- }
|