| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- <?php
- namespace addons\WechatVideoShop\common\models;
- use common\enums\StatusEnum;
- use common\models\base\BaseActiveRecord;
- use PHPUnit\Util\Exception;
- /**
- * This is the model class for table "qimall_addons_wechat_video_shop_level".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $level
- * @property string $name 等级名称
- * @property int $is_auto_upgrade 是否开启自动升级
- * @property int $upgrade_type_condition 是否开启条件升级
- * @property string $checked_condition_values 升级条件
- * @property string $checked_condition_keys 升级条件选中的key集合
- * @property int $condition_type 0 未选择、1满足其一 2、满足所有
- * @property int $upgrade_type_goods 购买升级商品,0关闭,1开启
- * @property int $buy_goods_type 购买升级商品触发升级:0订单完成 1下单完成
- * @property int $goods_type 商品升级类型,1- 任意商品 2- 指定商品
- * @property string $goods_ids 商品id集合
- * @property string $goods_list 商品列表json
- * @property string $explain 等级说明
- * @property int $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at
- * @property int $updated_at
- * @property int $reward_commission_type
- * @property int $reward_score_type
- * @property string $reward_commission
- * @property string $reward_score
- */
- class WechatVideoShopLevel extends BaseActiveRecord
- {
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_wechat_video_shop_level}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'checked_condition_values'], 'required'],
- [['mall_id', 'level', 'is_auto_upgrade', 'upgrade_type_condition', 'condition_type', 'upgrade_type_goods',
- 'buy_goods_type', 'goods_type', 'status', 'created_at', 'updated_at','reward_commission_type', 'reward_score_type'], 'integer'],
- [['checked_condition_values'], 'string'],
- [['name'], 'string', 'max' => 45],
- [['checked_condition_keys'], 'string', 'max' => 1000],
- [['goods_ids'], 'string', 'max' => 3000],
- [['goods_list', 'explain'], 'string'],
- [['reward_commission', 'reward_score'], 'number'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'level' => 'Level',
- 'name' => '等级名称',
- 'is_auto_upgrade' => '是否开启自动升级',
- 'upgrade_type_condition' => '是否开启条件升级',
- 'checked_condition_values' => '升级条件',
- 'checked_condition_keys' => '升级条件选中的key集合',
- 'condition_type' => '0 未选择、1满足其一 2、满足所有',
- 'upgrade_type_goods' => '购买升级商品,0关闭,1开启',
- 'buy_goods_type' => '购买升级商品触发升级:0订单完成 1下单完成',
- 'goods_type' => '商品升级类型,1- 任意商品 2- 指定商品',
- 'goods_ids' => '商品id集合',
- 'goods_list' => '商品列表json',
- 'explain' => '等级说明',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => 'Created At',
- 'updated_at' => 'Updated At',
- ];
- }
- /**
- * @desc:保存数据
- * @Author: hua
- * @Date: 2021/10/20
- * @Time: 15:46
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return WechatVideoShopLevel|false|null
- * @throws \Exception
- */
- public static function setData(array $params)
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- if(!empty($params['id'])){
- $model = self::findOne(['mall_id' => $params['mall_id'], 'id' => $params['id'], 'status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]]);
- if (empty($model)) throw new \Exception('服务不存在或已删除');
- }else{
- $model = new self();
- $model->loadDefaultValues();
- }
- if (!$model->load($params, '')) throw new \Exception($model->getErrorMessage());
- if (empty($params['checked_condition_keys'])) $params['checked_condition_keys'] = [];
- if (empty($params['checked_condition_values'])) $params['checked_condition_values'] = [];
- if (empty($params['goods_ids'])) $params['goods_ids'] = [];
- if (empty($params['goods_list'])) $params['goods_list'] = [];
- $model->checked_condition_keys = json_encode($params['checked_condition_keys'], JSON_NUMERIC_CHECK);
- $model->checked_condition_values = json_encode($params['checked_condition_values'], JSON_NUMERIC_CHECK);
- $model->goods_ids = json_encode($params['goods_ids'], JSON_NUMERIC_CHECK);
- $model->goods_list = json_encode($params['goods_list'], JSON_NUMERIC_CHECK);
- if (!$model->save()) throw new Exception($model->getErrorMessage());
- $t->commit();
- return $model;
- } catch (\Exception $e) {
- $t->rollBack();
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * @desc:条件升级数据源使用
- * @Author: hua
- * @Date: 2021/10/20
- * @Time: 9:54
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return array
- */
- public static function getAgentListByUpgrade($params)
- {
- $rows = [];
- if (!empty($params['mall_id'])) {
- $where = ['mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED];
- $list = self::findAll($where);
- foreach ($list as $v) {
- $rows[] = ['level' => $v['level'], 'name' => $v['name']];
- }
- }
- return $rows;
- }
- /**
- * @desc:等级和权重
- * @Author: hua
- * @Date: 2021/10/20
- * @Time: 16:08
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @return array
- */
- 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),
- ];
- }
- // array_unshift($newList, [
- // 'name' => "默认等级",
- // 'level' => 0,
- // 'disabled' => true,
- // ]);
- return $newList;
- }
- /**
- * @desc:获取经销商等级列表
- * @Author: hua
- * @Date: 2021/10/26
- * @Time: 14:52
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $cond
- * @param array $with
- * @param bool $is_array
- * @param string $select
- * @return array|\yii\db\ActiveRecord[]
- */
- public static function getLevelList(array $cond = [], array $with = [], bool $is_array = true, string $select = '*')
- {
- $default_cond = [['<>', 'status', StatusEnum::DELETE]];
- $cond = array_merge($default_cond, $cond);
- $query = self::find()->select($select);
- self::paramPack(['where' => $cond, 'with' => $with], $query);
- return $query->asArray($is_array)->all();
- }
- public static function del($params){
- try{
- $model = self::findOne(['id'=>$params['id']]);
- if(!empty($model)){
- $res = WechatVideoShopSharer::findOne(['level'=>$model->level,
- 'mall_id'=>$params['mall_id'],'status'=>[StatusEnum::ENABLED,StatusEnum::DISABLED]]);
- if(!empty($res)) throw new \Exception('该等级关联了经销商');
- $model->status = StatusEnum::DELETE;
- $res = $model->save();
- if(!$res) throw new \Exception($model->getErrorMessage());
- }
- return true;
- }catch (\Exception $e){
- self::$static_error = $e->getMessage();
- return false;
- }
- }
- /**
- * 获取等级
- * @Author: lun
- * @DateTime: 2021/12/16 0016 9:17
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @return array
- */
- public static function getLevelByColumn($mall_id){
- return self::find()
- ->select('name')
- ->where(array('mall_id'=>$mall_id,'status'=>StatusEnum::ENABLED))
- ->asArray()
- ->indexBy('level')
- ->orderBy('level desc')
- ->column();
- }
- /**
- * @desc:条件升级数据源使用
- * @Author: hua
- * @Date: 2021/10/23
- * @Time: 15:30
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params
- * @return array
- */
- public static function getListByUpgrade($params)
- {
- $rows = [];
- if (!empty($params['mall_id'])) {
- $where = ['mall_id' => $params['mall_id'],'status'=>StatusEnum::ENABLED];
- $list = self::findAll($where);
- foreach ($list as $v) {
- $rows[] = ['level' => $v['level'], 'name' => $v['name']];
- }
- }
- return $rows;
- }
- }
|