| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630 |
- <?php
- namespace addons\Boss\common\models;
- use addons\Boss\common\enums\BossEnum;
- use addons\Boss\common\enums\LevelEnum;
- use common\enums\LevelUpgradeLogEnum;
- use common\enums\StatusEnum;
- use common\helpers\Base64Helper;
- use common\models\common\Addons;
- use common\models\mall\MallAddons;
- use common\models\user\User;
- use common\enums\RabbitMqEnum;
- use common\helpers\csv\CsvImportForm;
- use common\models\common\Download;
- use common\components\export\CsvTool;
- use common\enums\DownloadEnum;
- use common\models\user\UserPartitionRelationship;
- use Yii;
- use yii\db\Exception;
- /**
- * This is the model class for table "{{%addons_boss}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int $user_id 用户ID
- * @property int $level 股东等级
- * @property float $commission 累计永久佣金,单位:元
- * @property float $extra_commission 累计额外佣金,单位:元
- * @property float $temp_extra_commission 额外分红金额,主要用于判断是否会导致超额
- * @property float $performance 累计团队营业额,单位:元
- * @property float $performance_commission 业绩佣金(额外佣金2)
- * @property float $total_commission 累计总佣金,单位:元
- * @property int $upgrade_status 1条件升级,2购买指定商品升级,3手动升级
- * @property int $upgrade_level_at 股东等级升级时间
- * @property string $remark 备注
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- * @property float $digital 累计数字币永久分红,单位:元
- * @property float $extra_digital 累计额外分红数字币,单位:元
- * @property float $total_digital 累计数字币,单位:元
- * @property float $bonus_pool_commission 奖金池佣金,单位:元
- * @property int $is_extra_bonus_alone_limit 是否开启额外分红独立限额
- * @property float $extra_bonus_limit 额外分红独立限额
- */
- class AddonsBoss extends \common\models\base\BaseActiveRecord
- {
- const ADDONS_NAME = 'Boss';
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_boss}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['mall_id', 'user_id', 'level', 'upgrade_status', 'upgrade_level_at', 'status', 'created_at', 'updated_at', 'is_extra_bonus_alone_limit'], 'integer'],
- [['commission', 'extra_commission', 'temp_extra_commission','performance','performance_commission', 'total_commission', 'total_digital', 'extra_digital', 'digital', 'bonus_pool_commission', 'extra_bonus_limit'], 'number'],
- [['remark'], 'string'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => 'ID',
- 'mall_id' => '商城ID',
- 'user_id' => '用户ID',
- 'level' => '股东等级',
- 'commission' => '累计永久佣金,单位:元',
- 'extra_commission' => '累计额外佣金,单位:元',
- 'temp_extra_commission' => '额外分红金额,主要用于判断是否会导致超额',
- 'performance' => '累计团队业绩,单位:元',
- 'performance_commission' => '业绩佣金(额外佣金2)',
- 'total_commission' => '累计总佣金,单位:元',
- 'upgrade_status' => '1条件升级,2购买指定商品升级,3手动升级',
- 'upgrade_level_at' => '股东等级升级时间',
- 'remark' => '备注',
- 'status' => '状态[-1:删除;0:禁用;1启用]',
- 'created_at' => '创建时间',
- 'updated_at' => '修改时间',
- 'digital' => '累计数字币永久分红,单位:元',
- 'extra_digital' => '累计额外分红数字币,单位:元',
- 'total_digital' => '累计数字币,单位:元',
- 'bonus_pool_commission' => '奖金池佣金,单位:元',
- 'is_extra_bonus_alone_limit' => '是否开启额外分红独立限额',
- 'extra_bonus_limit' => '额外分红独立限额',
- ];
- }
- public static $head_list = [
- '0' => [
- 'field' => 'serial_number',
- 'field_name' => '序号',
- ],
- '1' => [
- 'field' => 'mobile',
- 'field_name' => '手机号码',
- ],
- '2' => [
- 'field' => 'level',
- 'field_name' => '等级权重',
- ]
- ];
- public static $max_count = 5000;
- public static $column_num = 3;
-
- /**
- * 导出字段
- */
- public static function exportFieldsList($field = null)
- {
- $fields = [
- 'user_id' => '用户ID',
- 'nickname' => '昵称',
- 'mobile' => '手机号',
- 'level' => '股东等级',
- 'level_id' => '股东等级id',
- 'parent_id' => '推荐人ID',
- 'parent_name' => '推荐人昵称',
- 'parent_mobile' => '推荐人手机号',
- 'create' => '创建时间',
- ];
- return $fields;
- }
- /**
- * @name:
- * @msg: 处理导出数据,这个方法是异步队列处理时使用的,请别修改
- * @param {array} $data
- * @return bool
- */
- public static function exportHandle(array $data)
- {
- $download_id = $data['download_id'] ?? 0;
- $download = Download::findOne(['id' => $download_id]);
- if($download){
- try{
- $params = json_decode($download->params,true);
- $filename = $download->name;
- $type = $download->type;
- $fields = $params['fields'];
- $fields_arr = self::exportFieldsList();
- $have_select_field_arr = [];
- foreach ($fields as $value){
- $have_select_field_arr[]=$fields_arr[$value];
- }
- $csv = new CsvTool();
- $csv->filename = $filename;
- $csv->file_dirname = DownloadEnum::getTypeStorageDirMap($type);
- $csv->export_mode = CsvTool::EXPORT_MODE_ASYNC;
- $csv->header = $have_select_field_arr;
- $model = self::find();
- $model->where(['mall_id'=>$params['mall_id']]);
- $model->andWhere(['>=','status',StatusEnum::DISABLED]);
- $user_id = 0;
- $user_id_arr = [];
- //拼接查询条件
- if(!empty($params['user_id'])) $user_id = $params['user_id'];
- if(!empty($params['level'])) $model->andWhere( ['=', 'level', $params['level']]);
- if (!empty($params['keyword'])) {
- $condition['where'] = [[
- 'or',
- ['like', 'username', $params['keyword']],
- ['like', 'nickname', $params['keyword']],
- ['like', 'mobile', $params['keyword']]
- ]];
- $user_list = User::lists($condition);
- $user_id_arr = array_column($user_list,'id');
- }
- if($user_id&&$user_id_arr){
- $user_ids = array_intersect([$user_id],$user_id_arr);
- $model->andWhere(['in', 'user_id', $user_ids]);
- }else if($user_id){
- $model->andWhere(['in', 'user_id', $user_id]);
- }elseif($user_id_arr){
- $model->andWhere(['in', 'user_id', $user_id_arr]);
- }
- $model->with(['user','bossLevel'=>function($query){
- $query->where(['status'=>StatusEnum::ENABLED]);
- }]);
- //遍历组装数据
- foreach ($model->batch() as $list) {
- $parent_id_arr = $parent_arr = [];
- //查询上级昵称数组
- if(in_array('parent_id',$fields)||in_array('parent_name',$fields)||in_array('parent_mobile',$fields)){
- foreach ($list as $item){
- $parent_id_arr[] = $item['user']['parent_id'];
- }
- $parent_arr = User::lists(['where' => [['id' => array_unique($parent_id_arr)]], 'index' => 'id', 'select' => 'id,nickname,avatar_url,mobile,parent_id']);
- }
- $csv->data = array_map(function($agent)use($fields,$parent_arr){
- $row = [];
- //遍历所选字段
- foreach ($fields as $field){
- if(in_array($field,['nickname','mobile'])){
- $row[] = !empty($agent['user'][$field])?$agent['user'][$field]:'';
- }elseif(in_array($field,['level'])){
- $row[] = !empty($agent['bossLevel']['name'])?$agent['bossLevel']['name']:'';
- }elseif(in_array($field,['level_id'])){
- $row[] = !empty($agent['bossLevel']['level'])?$agent['bossLevel']['level']:'';
- }
- elseif(in_array($field,['parent_id'])){
- $row[] = !empty($agent['user']['parent_id'])?$agent['user']['parent_id']:'0';
- }
- elseif(in_array($field,['parent_name'])){
- $row[] = !empty($parent_arr[$agent['user']['parent_id']])?$parent_arr[$agent['user']['parent_id']]['nickname']:'平台';
- }
- elseif(in_array($field,['parent_mobile'])){
- $row[] = !empty($parent_arr[$agent['user']['parent_id']])?$parent_arr[$agent['user']['parent_id']]['mobile']:'平台';
- }
- elseif(in_array($field,['create'])){
- $row[] = !empty($agent["created_at"])? date('Y-m-d h:i:s',$agent['created_at']):'';
- }
- else{
- $row[] = !empty($agent[$field])?$agent[$field]:'';
- }
- }
- return $row;
- },$list);
- $csv->export();
- }
- $csv->updateDown($download,$params['mall_id']);
- return true;
- }catch(Exception $e){
- $download->status = 3;
- $res = $download->save();
- var_dump($e->getMessage());
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- }
- public function getUser()
- {
- return $this->hasOne(User::class, ['id' => 'user_id'])->select('id,mobile,nickname,avatar_url,parent_id');
- }
- /**
- * @desc:关联股东等级
- * @Author: hua
- * @Date: 2021/11/5
- * @Time: 10:04
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @return \yii\db\ActiveQuery
- */
- public function getBossLevel(){
- return $this->hasOne(AddonsBossLevel::class, ['level' => 'level','mall_id'=>'mall_id'])->andWhere(['<>','status',StatusEnum::DELETE]);
- }
- /**
- * 保存数据
- * @Author: lun
- * @DateTime: 2021/10/22 0022 17:13
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param array $params
- * @return AddonsBoss|bool
- */
- public static function setData(array $params){
- try{
- if(!empty($params['user_id'])){
- $model = self::findOne(['user_id' => $params['user_id'],'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]);
- if(empty($model)) {
- $model = new self();
- $model->loadDefaultValues();
- $model->mall_id = $params['mall_id'];
- $model->upgrade_status = LevelEnum::UPGRADE_MANUAL;
- $model->upgrade_level_at = time();
- // 记录升级日志(如果创建的不是默认等级,则认为手动升级)
- if ($params['level'] > 0) {
- $upgrade_log_obj = new BossLevelUpgradeLog();
- $upgrade_log_obj->before_level = 0;
- $upgrade_log_obj->upgrade_type = LevelUpgradeLogEnum::MANUALLY_UPGRADE;
- }
- } else {
- // 记录升级日志
- if (
- !empty($params['upgrade_status']) &&
- $params['upgrade_status'] === LevelEnum::UPGRADE_MANUAL &&
- $model->level != $params['level']
- ) {
- $upgrade_log_obj = new BossLevelUpgradeLog();
- $upgrade_log_obj->before_level = $model->level;
- $upgrade_log_obj->upgrade_type = $params['level'] > $model->level ? LevelUpgradeLogEnum::MANUALLY_UPGRADE : LevelUpgradeLogEnum::DOWNGRADE_MANUALLY;
- }
- }
- if (isset($upgrade_log_obj)) {
- $upgrade_log_obj->admin_id = $params['admin_id'];
- $upgrade_log_obj->mall_id = $params['mall_id'];
- $upgrade_log_obj->user_id = $params['user_id'];
- $upgrade_log_obj->after_level = $params['level'];
- $upgrade_log_obj->save();
- }
- } else {
- throw new \Exception('股东数据不存在或已删除');
- }
- if(!$model->load($params,'') || !$model->save()){
- throw new Exception($model->getErrorMessage());
- }
- return $model;
- }catch(\Exception $e){
- self::setStaticError($e->getMessage());
- return false;
- }
- }
- /**
- * 获取股东列表
- * @Author: lun
- * @DateTime: 2021/10/25 0025 10:05
- * @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 getBoss(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);
- $data = $query->asArray($is_array)->all();
- return $data;
- }
- /**
- * @desc:推广中心-调用
- * @Author: hua
- * @Date: 2021/11/12
- * @Time: 9:30
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $params ['user_id' => 1, 'mall_id' => 5, 'addons_name' => 'Agent']
- * @return array
- */
- public static function getIncomeInfo(array $params){
- $is_install = MallAddons::isInstall($params['mall_id'], $params['addons_name']);
- $data['total_commission'] = 0;
- $data['is_install'] = 0;
- $basic = \Yii::$app->services->setting->addons->get($params['mall_id'], $params['addons_name'], 'basic');
- $data['is_show_at_center'] = 1;
- if(isset($basic['is_show_at_center'])) $data['is_show_at_center'] = $basic['is_show_at_center'];
- if($is_install){
- $model = self::findOne(['user_id'=>$params['user_id'], 'mall_id' => $params['mall_id'], 'status' => StatusEnum::ENABLED]);
- $data['total_commission'] = $model['total_commission']??0;
- $data['is_install'] = $is_install;
- }
- return $data;
- }
- public static function getAddons(array $params){
- $is_install = MallAddons::isInstall($params['mall_id'], BossEnum::ADDONS_NAME);
- if($is_install){
- $detail = Addons::getOne([['name' => BossEnum::ADDONS_NAME], ['is_online' => 1]], true);
- return [
- 'addons_name'=>BossEnum::ADDONS_NAME,
- 'title'=>$detail['title'],
- ];
- }
- return [];
- }
- /**
- * 根据等级+升级类型统计人数
- * @Author:lun
- * @Date:2024-03-16 15:07
- * @Copyright:copyright(c)2024 广东七件事集团
- * @param $mall_id
- * @return array
- */
- public static function getBossCountByExtraUpgrade($mall_id)
- {
- $data = [];// 初始化返回值
- //获取权重等级数据
- $level = AddonsBossLevel::lists([
- 'where' => [
- ['mall_id' => $mall_id],
- ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]],
- ],
- 'index' => 'level',
- 'with' => ['setting'],
- ]);
- $list = self::find()->where(['mall_id' => $mall_id, 'status' => StatusEnum::ENABLED])
- ->asArray()->all();
- if ($list) {
- foreach ($list as $item) {
- if ($level[$item['level']]['setting']['is_static_extra'] == 2 && $item['temp_extra_commission'] >= $level[$item['level']]['setting']['extra_limit_price']) continue;
- if (empty($data[$item['level'] . '_' . $item['upgrade_status']])) {
- $data[$item['level'] . '_' . $item['upgrade_status']] = 1;
- } else {
- $data[$item['level'] . '_' . $item['upgrade_status']] += 1;
- }
- }
- }
- return $data;
- }
- /**
- * 批量更新代理等级
- * @param $params
- * @return array|bool
- */
- public static function importLevel($params)
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- self::isCanImport($params['mall_id']);
- $csvImport = new CsvImportForm();
- $data = $csvImport->setDataForm($params)
- ->setMaxCount(self::$max_count)
- ->setImportFieldConfig(self::$head_list)
- ->setColumnNum(self::$column_num)
- ->readCsvData();
- if (!$data) throw new \Exception(CsvImportForm::getStaticError());
- $success_counts = $fail_counts = 0;
- $counts = count($data);
- $fail_arr = [];
- $success_user_id_arr = [];
- $merge_arr = [];
- foreach ($data as $item) {
- $param = $item;
- $merge_arr[] = $param;
- }
- self::batchUpdateLevel($params['mall_id'], $merge_arr, $success_counts, $fail_arr, $fail_counts, $success_user_id_arr);
- $param['counts'] = $counts;
- $param['success_counts'] = $success_counts;
- $param['fail_counts'] = $fail_counts;
- $param['status'] = 1;
- $param['mall_id']=$params['mall_id'];
- $import_log_model = BossImportLevelLog::setData($param);
- if (!$import_log_model) throw new \Exception(BossImportLevelLog::getStaticError());
- if (!empty($fail_arr)) {
- $res = BossImportLevelFailLog::setData($fail_arr, $import_log_model->id);
- if (!$res) throw new \Exception(BossImportLevelFailLog::getStaticError());
- }
- $t->commit();
- return ['counts' => $counts, 'success_counts' => $success_counts, 'fail_counts' => $fail_counts];
- } catch (\Exception $e) {
- var_dump($e->getMessage().$e->getFile());
- self::$static_error = $e->getMessage();
- $t->rollBack();
- return false;
- }
- }
- public static function importLevelSync($params)
- {
- $t = \Yii::$app->db->beginTransaction();
- try {
- self::isCanImport($params['mall_id']);
- $basePath = \Yii::$app->basePath;
- if (empty($_FILES) || !isset($_FILES['file'])) throw new \Exception('请上传csv文件');
- $fileName = $_FILES['file']['name'];
- $tmpName = $_FILES['file']['tmp_name'];
- $basePath = $basePath . '/web/uploads/';
- if (!is_dir($basePath))mkdir($basePath, 0775, true);
- $ext = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
- if ($ext != 'csv') throw new \Exception('请上传csv文件');
- $uploadFile = $basePath . 'ADMIN-' . date('Y-m-d His') . '.' . $ext;
- //上传
- move_uploaded_file($tmpName, $uploadFile);
- $success_counts = $fail_counts = 0;
- $counts = 0;
- $param['counts'] = $counts;
- $param['success_counts'] = $success_counts;
- $param['fail_counts'] = $fail_counts;
- $param['upload_file'] = $uploadFile;
- $param['mall_id'] = $params['mall_id'];
- $user_import_log_model = BossImportLevelLog::setData($param);
- if (!$user_import_log_model) throw new \Exception(BossImportLevelLog::getStaticError());
- $t->commit();
- $params = ['id'=>$user_import_log_model['id']];
- \Yii::$app->services->rabbitMq->push(RabbitMqEnum::TASK_QUEUE, RabbitMqEnum::TASK_QUEUE, $params, self::class, 'syncImportLevel');
- return ['counts' => $counts, 'success_counts' => $success_counts, 'fail_counts' => $fail_counts];
- } catch (\Exception $e) {
- self::$static_error = $e->getMessage();
- var_dump($e->getMessage());
- $t->rollBack();
- return false;
- }
- }
- public static function isCanImport($mall_id){
- $time = strtotime('2024-04-28 23:59:59');
- $res = BossImportLevelLog::find()->where(['mall_id'=>$mall_id,'status'=>3])->andWhere(['>=','created_at',$time])->one();
- if(!empty($res)) throw new \Exception('等上一次导入执行完再导入');
- }
- //异步执行
- public static function syncImportLevel($params){
- if(empty($params['id'])) return false;
- $model = BossImportLevelLog::findOne(['id' => $params['id']]);
- if (!empty($model['upload_file'])) {
- $upload_file = $model['upload_file'];
- $mall_id = $model['mall_id'];
- $cvsFile = fopen($upload_file, 'r'); //开始读取csv文件数据
- $fail_arr = [];
- $success_counts = $fail_counts =$counts = $i = 0;
- $counts = 0;
- $success_user_id_arr = [];
- $data = [];// 初始化数据
- while ($fileData = fgetcsv($cvsFile)) {
- $i++;
- if ($i == 1) continue;//过滤表头
- $counts++;
- $user_id=0;
- $level_id=0;
-
- foreach ($fileData as $k => &$val) {
- $val = mb_convert_encoding(trim($val), "UTF-8", "GBK");
- switch ($k) {
- case 1:
- $user_id = !empty($val)?$val:'';
- break;
- case 2:
- $level_id = !empty($val)?trim($val):0;
- break;
- }
- }
- $param['mobile'] = $user_id;
- $param['level'] = $level_id;
- $data[] = $param;
- }
- self::batchUpdateLevel($mall_id, $data, $success_counts, $fail_arr, $fail_counts);
- $model->counts = $counts;
- $model->success_counts = $success_counts;
- $model->fail_counts = $fail_counts;
- $model->status = 1;
- if (!$model->save()) throw new \Exception($model->getErrorMessage());
- if (!empty($fail_arr)) {
- $res = BossImportLevelFailLog::setData($fail_arr, $model->id);
- if (!$res) throw new \Exception(BossImportLevelFailLog::getStaticError());
- }
- }
- }
-
- /**
- * 批量更新等级
- * @Author: zfh
- * @DateTime: 2024/4/28 0003 15:16
- * @Copyright: copyright (c) 2021 广东七件事集团
- * @param $mall_id
- * @param $data
- * @param int $success_counts
- * @param array $fail_arr
- * @param int $fail_counts
- * @throws Exception
- */
- public static function batchUpdateLevel($mall_id, $data, &$success_counts = 0, &$fail_arr = [], &$fail_counts = 0, &$success_user_id_arr = [])
- {
- foreach ($data as $item) {
- $fail_params = $item;
- $fail_params['maill_id']=$mall_id;
- $where = [];
- $where[] = ['mall_id' => $mall_id];
- $where[] = ['mobile' => $item['mobile']];
- $user = User::getUser($where,'id,mobile');
- if (empty($user)) {
- $fail_params['reason'] = '用户不存在';
- list($fail_arr, $fail_counts) = BossImportLevelFailLog::packFailArr($fail_params, $fail_arr, $fail_counts);
- } else if (empty(AddonsBossLevel::getOne([['level' => $item['level'],'status'=>1,'mall_id'=>$mall_id]]))) {
- $fail_params['reason'] = '股东等级id不存在';
- list($fail_arr, $fail_counts) = BossImportLevelFailLog::packFailArr($fail_params, $fail_arr, $fail_counts);
- } else {
- $agent = AddonsBoss::getOne([['user_id' => $user['id']]]);
- if ($agent) {
- $item['id'] = $agent['id'];
- }
- $item['mall_id']=$mall_id;
- $item['user_id']=$user['id'];
- $item['upgrade_level_at']=time();
- $item['admin_id'] = 0;
- $item['upgrade_status']=LevelEnum::UPGRADE_MANUAL;
- $res = AddonsBoss::setData($item);
- if ($res) {
- $success_user_id_arr[] = $res['id'];
- $success_counts++;
- } else {
- $fail_params['reason'] = AddonsBoss::getStaticError();
- list($fail_arr, $fail_counts) = BossImportLevelFailLog::packFailArr($fail_params, $fail_arr, $fail_counts);
- }
- }
- }
- }
- /**
- * 获取团队中对应层级有多少人数
- * @param $user_id //会员id
- * @param $level //查询层级
- * @return false|int|string|null
- */
- public static function getTeamlevelCount($user_id,$level){
- list($tree,$parent_deep,$all_tree, $all_tree_arr) = UserPartitionRelationship::getTree($user_id);
- $count = (new \yii\db\Query())
- ->select(['COUNT(DISTINCT u.id) as count'])
- ->from(['u' => 'qimall_addons_boss'])
- ->innerJoin(['upr' => 'qimall_user_partition_relationship'], 'u.user_id = upr.user_id') //股东身份还是看主商城会员关系链
- ->where(['u.level' => $level,'u.status'=>StatusEnum::ENABLED])
- ->andWhere(['like', 'upr.tree', "{$tree},%", false])
- ->scalar();
- return $count;
- }
- }
|