diff --git a/market/controllers/api/sylive/Activity.php b/market/controllers/api/sylive/Activity.php index b6419e3d..20244330 100644 --- a/market/controllers/api/sylive/Activity.php +++ b/market/controllers/api/sylive/Activity.php @@ -42,14 +42,13 @@ class Activity extends BaseController $where['status>='] = 0; $title && $where['title LIKE "%' . trim($title) . '%"'] = null; if ($_SESSION['brandName']) {//品牌机构 - $str_organizationIds = '-1'; $re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]); - if ($re_org['organizationId']) {//查找大区 - $res_all = $this->mdSyliveOrganization->select(['parentId' => $re_org['organizationId'], 'organizationType' => 2, 'status' => 0] - , 'sortNumber asc,organizationId desc', 0, 0, 'organizationId'); - $res_all && $str_organizationIds = implode(',', array_column($res_all, 'organizationId')); + if ($re_org['organizationId']) { + $organizationIds = ",{$re_org['organizationId']},"; + $where['organizationIds LIKE "%' . $organizationIds . '%"'] = null; + } else { + $where['organizationIds'] = '-1'; } - $where["activityId in(select distinct(activityId) as activityId from lc_market_sylive_activity_biz WHERE areaId in({$str_organizationIds}) AND status=0)"] = null; } $count = $this->mdSyliveActivity->count($where); if ($count) { @@ -182,7 +181,7 @@ class Activity extends BaseController $bgImg = $bgImg[0]['fileUrl']; $sharePhoto = $sharePhoto[0]['fileUrl'] ? $sharePhoto[0]['fileUrl'] : ''; $channelImg = $channelImg[0]['fileUrl'] ? $channelImg[0]['fileUrl'] : ''; - $shareTitle && $shareTitle = json_encode($shareTitle, JSON_UNESCAPED_UNICODE); + $shareTitle = $shareTitle ? json_encode($shareTitle, JSON_UNESCAPED_UNICODE) : ''; $setShareImg = ''; if ($shareImg) { foreach ($shareImg as $v) { @@ -204,16 +203,22 @@ class Activity extends BaseController if (!$activityId) { $this->return_json('添加活动失败'); } + $organizationIds = $add_biz = $add_team = []; if ($bizIds) { $bizIds = implode(',', $bizIds); $res_org = $this->mdSyliveOrganization->select(["organizationId in({$bizIds})" => null, 'organizationType' => 3] , 'organizationId desc', 0, 0, 'organizationId,parentId'); - $add_biz = []; if ($res_org) { $this->mdSyliveActivityBiz->update(['status' => -1], ["bizId not in({$bizIds})" => null, 'activityId' => $activityId, 'status' => 0]); foreach ($res_org as $v) { $add_biz[] = ['activityId' => $activityId, 'areaId' => $v['parentId'] , 'bizId' => $v['organizationId'], 'createTime' => date('Y-m-d H:i:s')]; + if ($v['parentId']) { + $re_org = $this->mdSyliveOrganization->get(["organizationId" => $v['parentId']]); + if ($re_org['parentId'] && !in_array($re_org['parentId'], $organizationIds)) { + $organizationIds[] = $re_org['parentId'];//所属机构 + } + } } //增加活动商家 $add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz); @@ -221,27 +226,27 @@ class Activity extends BaseController } if ($teamIds) { $teamIds = implode(',', $teamIds); - $res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 3], 'teamId desc', 0, 0, 'teamId,parentId'); - $add_biz = []; + $res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 2], 'teamId desc', 0, 0, 'teamId,parentId'); if ($res_org) { $this->mdSyliveActivityTeam->update(['status' => -1], ["teamId2 not in({$teamIds})" => null, 'activityId' => $activityId, 'status' => 0]); foreach ($res_org as $v) { - $teamId1 = $v['parentId']; - $teamId2 = $v['teamId']; + $add_team[] = ['activityId' => $activityId, 'teamId1' => $v['parentId'] + , 'teamId2' => $v['teamId'], 'createTime' => date('Y-m-d H:i:s')]; if ($v['parentId']) { $re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]); - if ($re_team && $re_team['parentId']) { - $teamId1 = $re_team['parentId']; - $teamId2 = $re_team['teamId']; + if ($re_team['organizationId'] && !in_array($re_team['organizationId'], $organizationIds)) { + $organizationIds[] = $re_team['organizationId']; } } - $add_biz[] = ['activityId' => $activityId, 'teamId1' => $teamId1 - , 'teamId2' => $teamId2, 'createTime' => date('Y-m-d H:i:s')]; } //增加活动商家 - $add_biz && $this->mdSyliveActivityTeam->add_batch($add_biz); + $add_team && $this->mdSyliveActivityTeam->add_batch($add_team); } } + if ($organizationIds) {//所属机构 + $organizationIds = ',' . implode(',', $organizationIds) . ','; + $this->mdSyliveActivity->update(['organizationIds' => $organizationIds], ['activityId' => $activityId]); + } $this->return_response(); } @@ -298,18 +303,15 @@ class Activity extends BaseController if (!$dateRange) { $this->return_json('请选择直播时间'); } -// if (!$introduction) { -// $this->return_json('请输入活动简介'); -// } $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); if (!$re) { $this->return_json('活动不存在'); } + $organizationIds = $add_biz = $add_team = []; if ($bizIds) { $bizIds = implode(',', $bizIds); $res_org = $this->mdSyliveOrganization->select(["organizationId in({$bizIds})" => null, 'organizationType' => 3] , 'organizationId desc', 0, 0, 'organizationId,parentId'); - $add_biz = []; if ($res_org) { $this->mdSyliveActivityBiz->update(['status' => -1], ["bizId not in({$bizIds})" => null, 'activityId' => $activityId, 'status' => 0]); foreach ($res_org as $v) { @@ -320,6 +322,12 @@ class Activity extends BaseController } else if ($re_org['status'] == -1) { $this->mdSyliveActivityBiz->update(['status' => 0], ['id' => $re_org['id']]); } + if ($v['parentId']) { + $re_org = $this->mdSyliveOrganization->get(["organizationId" => $v['parentId']]); + if ($re_org['parentId'] && !in_array($re_org['parentId'], $organizationIds)) { + $organizationIds[] = $re_org['parentId'];//所属机构 + } + } } //增加活动商家 $add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz); @@ -329,30 +337,26 @@ class Activity extends BaseController } if ($teamIds) { $teamIds = implode(',', $teamIds); - $res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 3], 'teamId desc', 0, 0, 'teamId,parentId'); - $add_biz = []; + $res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null, 'teamType' => 2], 'teamId desc', 0, 0, 'teamId,parentId'); if ($res_org) { $this->mdSyliveActivityTeam->update(['status' => -1], ["teamId2 not in({$teamIds})" => null, 'activityId' => $activityId, 'status' => 0]); foreach ($res_org as $v) { $re_org = $this->mdSyliveActivityTeam->get(['activityId' => $activityId, 'teamId2' => $v['teamId']]); if (!$re_org) { - $teamId1 = $v['parentId']; - $teamId2 = $v['teamId']; - if ($v['parentId']) { - $re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]); - if ($re_team && $re_team['parentId']) { - $teamId1 = $re_team['parentId']; - $teamId2 = $re_team['teamId']; - } - } - $add_biz[] = ['activityId' => $activityId, 'teamId1' => $teamId1 - , 'teamId2' => $teamId2, 'createTime' => date('Y-m-d H:i:s')]; + $add_team[] = ['activityId' => $activityId, 'teamId1' => $v['parentId'] + , 'teamId2' => $v['teamId'], 'createTime' => date('Y-m-d H:i:s')]; } else if ($re_org['status'] == -1) { $this->mdSyliveActivityTeam->update(['status' => 0], ['id' => $re_org['id']]); } + if ($v['parentId']) { + $re_team = $this->mdSyliveTeam->get(["teamId" => $v['parentId']]); + if ($re_team['organizationId'] && !in_array($re_team['organizationId'], $organizationIds)) { + $organizationIds[] = $re_team['organizationId']; + } + } } //增加活动商家 - $add_biz && $this->mdSyliveActivityTeam->add_batch($add_biz); + $add_team && $this->mdSyliveActivityTeam->add_batch($add_team); } } else { $this->mdSyliveActivityTeam->update(['status' => -1], ['activityId' => $activityId, 'status' => 0]); @@ -360,7 +364,7 @@ class Activity extends BaseController $bgImg = $bgImg[0]['fileUrl']; $sharePhoto = $sharePhoto[0]['fileUrl'] ? $sharePhoto[0]['fileUrl'] : ''; $channelImg = $channelImg[0]['fileUrl'] ? $channelImg[0]['fileUrl'] : ''; - $shareTitle && $shareTitle = json_encode($shareTitle, JSON_UNESCAPED_UNICODE); + $shareTitle = $shareTitle ? json_encode($shareTitle, JSON_UNESCAPED_UNICODE) : ''; $setShareImg = ''; if ($shareImg) { foreach ($shareImg as $v) { @@ -376,9 +380,10 @@ class Activity extends BaseController } $jsondata['pay'] = $pay; $jsondata = json_encode($jsondata, JSON_UNESCAPED_UNICODE); + $organizationIds = $organizationIds ? ',' . implode(',', $organizationIds) . ',' : ''; $upDate = ['title' => $title, 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'channelId' => $channelId, 'introduction' => $introduction, 'shareTitle' => $shareTitle, 'sharePhoto' => $sharePhoto, 'shareImg' => $setShareImg, 'jsondata' => $jsondata, - 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1]]; + 'timeStart' => $dateRange[0], 'timeEnd' => $dateRange[1], 'organizationIds' => $organizationIds]; $this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]); $this->return_response(); } @@ -861,7 +866,7 @@ class Activity extends BaseController $consultant = count($res_user); if ($allTeamIds) { $str_allTeamIds = implode(',', array_unique($allTeamIds)); - $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_allTeamIds})", 'status>=' => 0, 'teamId>' => 0]); + $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_allTeamIds})" => null, 'status>=' => 0, 'teamId>' => 0]); } $consultant > $allConsultant && $allConsultant = $consultant; $activityData1 = [['name' => '参与团队数', 'value' => count($teamData)] diff --git a/market/controllers/api/sylive/TeamUser.php b/market/controllers/api/sylive/TeamUser.php index 102bb5ec..dd77cc43 100644 --- a/market/controllers/api/sylive/TeamUser.php +++ b/market/controllers/api/sylive/TeamUser.php @@ -80,9 +80,11 @@ class TeamUser extends BaseController if (!$uname) { $this->return_json('请输入姓名'); } - $re = $this->mdSyliveUser->get(['mobile' => $mobile, 'status<>' => -1]); - if ($re && ($re['teamId'] || $re['organizationId'])) { - $this->return_json('手机号已存在'); + $re = $this->mdSyliveUser->get(['mobile' => $mobile]); + if ($re && $re['status'] != -1) { + if ($re['teamId'] || $re['organizationId']) { + $this->return_json('手机号已存在'); + } } $addDate = ['teamId' => $teamId, 'sex' => $sex, 'uname' => $uname, 'status' => 0, 'organizationId' => 0]; if ($re['userId']) { diff --git a/market/controllers/api/sylive/User.php b/market/controllers/api/sylive/User.php index bc088b4f..461837d8 100644 --- a/market/controllers/api/sylive/User.php +++ b/market/controllers/api/sylive/User.php @@ -86,9 +86,11 @@ class User extends BaseController if (!$uname) { $this->return_json('请输入姓名'); } - $re = $this->mdSyliveUser->get(['mobile' => $mobile, 'status<>' => -1]); - if ($re && ($re['teamId'] || $re['organizationId'])) { - $this->return_json('手机号已存在'); + $re = $this->mdSyliveUser->get(['mobile' => $mobile]); + if ($re && $re['status'] != -1) { + if ($re['teamId'] || $re['organizationId']) { + $this->return_json('手机号已存在'); + } } $addDate = ['organizationId' => $organizationId, 'sex' => $sex, 'uname' => $uname, 'status' => 0, 'teamId' => 0]; if ($re['userId']) {