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; } }