From 656415090972c0e67640063c39aaa5c2a5b90c3d Mon Sep 17 00:00:00 2001 From: dengbw Date: Tue, 25 Oct 2022 14:30:23 +0800 Subject: [PATCH] market_team_1025 --- .../Market_sylive_activity_team_model.php | 11 + .../market/Market_sylive_items_model.php | 11 + .../market/Market_sylive_order_model.php | 17 + .../market/Market_sylive_team_model.php | 11 + market/controllers/api/sylive/Activity.php | 460 ++++++++++++++---- market/controllers/api/sylive/Goods.php | 131 +++++ .../controllers/api/sylive/Organization.php | 43 +- market/controllers/api/sylive/Team.php | 157 ++++++ market/controllers/api/sylive/TeamUser.php | 184 +++++++ market/controllers/api/sylive/User.php | 19 +- market/controllers/api/system/User.php | 3 +- market/hooks/ApiAuthHook.php | 2 + 12 files changed, 952 insertions(+), 97 deletions(-) create mode 100644 common/models/market/Market_sylive_activity_team_model.php create mode 100644 common/models/market/Market_sylive_items_model.php create mode 100644 common/models/market/Market_sylive_team_model.php create mode 100644 market/controllers/api/sylive/Goods.php create mode 100644 market/controllers/api/sylive/Team.php create mode 100644 market/controllers/api/sylive/TeamUser.php diff --git a/common/models/market/Market_sylive_activity_team_model.php b/common/models/market/Market_sylive_activity_team_model.php new file mode 100644 index 00000000..9afb8f41 --- /dev/null +++ b/common/models/market/Market_sylive_activity_team_model.php @@ -0,0 +1,11 @@ +table_name, 'default'); + } +} \ No newline at end of file diff --git a/common/models/market/Market_sylive_items_model.php b/common/models/market/Market_sylive_items_model.php new file mode 100644 index 00000000..d7da815f --- /dev/null +++ b/common/models/market/Market_sylive_items_model.php @@ -0,0 +1,11 @@ +table_name, 'default'); + } +} \ No newline at end of file diff --git a/common/models/market/Market_sylive_order_model.php b/common/models/market/Market_sylive_order_model.php index 881b15f3..f8bbc6ff 100644 --- a/common/models/market/Market_sylive_order_model.php +++ b/common/models/market/Market_sylive_order_model.php @@ -32,4 +32,21 @@ class Market_sylive_order_model extends HD_Model } } + /** + * Notes:订单类型 + * Created on: 2022/10/25 14:46 + * Created by: dengbw + * @param string $cfrom + * @return array|mixed + */ + public function cfromAry($cfrom = '') + { + $arr = [0 => '门店', 1 => '团队']; + if (strlen($cfrom)) { + return $arr[$cfrom]; + } else { + return $arr; + } + } + } \ No newline at end of file diff --git a/common/models/market/Market_sylive_team_model.php b/common/models/market/Market_sylive_team_model.php new file mode 100644 index 00000000..81d52e2f --- /dev/null +++ b/common/models/market/Market_sylive_team_model.php @@ -0,0 +1,11 @@ +table_name, 'default'); + } +} \ No newline at end of file diff --git a/market/controllers/api/sylive/Activity.php b/market/controllers/api/sylive/Activity.php index 11a084c8..8fcd187b 100644 --- a/market/controllers/api/sylive/Activity.php +++ b/market/controllers/api/sylive/Activity.php @@ -16,6 +16,8 @@ class Activity extends BaseController $this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity'); $this->load->model('market/Market_sylive_activity_biz_model', 'mdSyliveActivityBiz'); $this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization'); + $this->load->model('market/Market_sylive_team_model', 'mdSyliveTeam'); + $this->load->model('market/Market_sylive_activity_team_model', 'mdSyliveActivityTeam'); } /** @@ -57,13 +59,15 @@ class Activity extends BaseController $dateRange = [$v['timeStart'], $v['timeEnd']]; $status = intval($v['status']); $activityId = intval($v['activityId']); - $bgImg = $channelImg = $sharePhoto = $shareImg = $shareTitle = $bizIds = $pay = []; - $item = ['activityId' => $activityId, 'itemImg' => [], 'title' => '', 'introduction' => '', 'price' => '', 'dateRange' => '']; + $bgImg = $channelImg = $sharePhoto = $shareImg = $shareTitle = $bizIds = $teamIds = $pay = []; + $item = ['activityId' => $activityId, 'itemImg' => [], 'title' => '', 'introduction' => '', 'price' => '', 'stock' => '', 'dateRange' => '']; + $coupon = ['activityId' => $activityId, 'img' => [], 'title' => '', 'rules' => '', 'price' => '', 'dateRange' => '']; $pay = ['way' => 1, 'price' => '', 'img' => []]; $v['shareTitle'] && $shareTitle = json_decode($v['shareTitle'], true); $jsondata = $v['jsondata'] ? json_decode($v['jsondata'], true) : []; if ($jsondata['item']) { $getItem = $jsondata['item']; + $item['stock'] = $v['stock']; $item['title'] = $getItem['title']; $item['introduction'] = $getItem['introduction']; $item['price'] = $getItem['price']; @@ -77,6 +81,20 @@ class Activity extends BaseController $item['itemImg'] = $itemImg; } } + if ($jsondata['coupon']) { + $getCoupon = $jsondata['coupon']; + $coupon['title'] = $getCoupon['title']; + $coupon['rules'] = $getCoupon['rules']; + $coupon['price'] = $getCoupon['price']; + $coupon['dateUseRange'] = $getCoupon['useTimeStart'] ? [$getCoupon['useTimeStart'], $getCoupon['useTimeEnd']] : []; + if ($getCoupon['img']) { + $itemImg = []; + foreach ($getCoupon['img'] as $k2 => $v2) { + $itemImg[] = ['uid' => $k2, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done']; + } + $coupon['img'] = $itemImg; + } + } if (intval($jsondata['pay']['way']) > 1) { $pay = $jsondata['pay']; if ($pay['img']) { @@ -107,14 +125,20 @@ class Activity extends BaseController $bizIds[] = intval($v2['bizId']); } } + $res_team = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status' => 0], 'id desc', 0, 0, 'teamId2'); + if ($res_team) { + foreach ($res_team as $k2 => $v2) { + $teamIds[] = intval($v2['teamId2']); + } + } $skey = $this->myencryption->base64url_encode("a_id=" . $activityId); $url = http_host_com('home') . "/h5/market/sylive?skey=" . $skey;//活动连接 $urlItem = http_host_com('home') . "/h5/market/sylive/act/item?skey=" . $skey;//商品连接 $list[] = [ - 'activityId' => $activityId, 'title' => $v['title'], 'channelId' => $v['channelId'], 'bizIds' => $bizIds, 'pay' => $pay, - 'introduction' => $v['introduction'], 'shareTitle' => $shareTitle, 'dateRange' => $dateRange, 'urlItem' => $urlItem - , 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'sharePhoto' => $sharePhoto, 'shareImg' => $shareImg, 'item' => $item, 'url' => $url - , 's_time' => $v['timeStart'], 'e_time' => $v['timeEnd'], 'status' => $status, 'createTime' => $v['createTime']]; + 'activityId' => $activityId, 'title' => $v['title'], 'channelId' => $v['channelId'], 'bizIds' => $bizIds, 'teamIds' => $teamIds, 'pay' => $pay, + 'introduction' => $v['introduction'], 'shareTitle' => $shareTitle, 'dateRange' => $dateRange, 'urlItem' => $urlItem, 'coupon' => $coupon, + 'bgImg' => $bgImg, 'channelImg' => $channelImg, 'sharePhoto' => $sharePhoto, 'shareImg' => $shareImg, 'item' => $item, 'url' => $url, + 's_time' => $v['timeStart'], 'e_time' => $v['timeEnd'], 'status' => $status, 'createTime' => $v['createTime']]; } } $date = ['list' => $list, 'count' => $count]; @@ -138,13 +162,11 @@ class Activity extends BaseController $channelImg = $this->input_param('channelImg'); $sharePhoto = $this->input_param('sharePhoto'); $bizIds = $this->input_param('bizIds'); + $teamIds = $this->input_param('teamIds'); $pay = $this->input_param('pay'); if (!$title) { $this->return_json('请输入活动标题'); } - if (!$bizIds) { - $this->return_json('请选择所属门店'); - } if (!$bgImg[0]['fileUrl']) { $this->return_json('请选择背景图'); } @@ -182,18 +204,34 @@ class Activity extends BaseController if (!$activityId) { $this->return_json('添加活动失败'); } - $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 ($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')]; + } + //增加活动商家 + $add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz); + } + } + if ($teamIds) { + $teamIds = implode(',', $teamIds); + $res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null], 'teamId desc', 0, 0, 'teamId,parentId'); + $add_biz = []; + if ($res_org) { + $this->mdSyliveActivityTeam->update(['status' => -1], ["teamId2 not in({$teamIds})" => null, 'activityId' => $activityId, 'status' => 0]); + foreach ($res_org as $v) { + $add_biz[] = ['activityId' => $activityId, 'teamId1' => $v['parentId'] + , 'teamId2' => $v['teamId'], 'createTime' => date('Y-m-d H:i:s')]; + } + //增加活动商家 + $add_biz && $this->mdSyliveActivityTeam->add_batch($add_biz); } - //增加活动商家 - $add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz); } $this->return_response(); } @@ -234,6 +272,7 @@ class Activity extends BaseController $channelImg = $this->input_param('channelImg'); $sharePhoto = $this->input_param('sharePhoto'); $bizIds = $this->input_param('bizIds'); + $teamIds = $this->input_param('teamIds'); $pay = $this->input_param('pay'); if (!$activityId) { $this->return_json('参数错误'); @@ -241,9 +280,6 @@ class Activity extends BaseController if (!$title) { $this->return_json('请输入活动标题'); } - if (!$bizIds) { - $this->return_json('请选择所属门店'); - } if (!$bgImg[0]['fileUrl']) { $this->return_json('请选择背景图'); } @@ -260,23 +296,48 @@ class Activity extends BaseController if (!$re) { $this->return_json('活动不存在'); } - $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) { - $re_org = $this->mdSyliveActivityBiz->get(['activityId' => $activityId, 'bizId' => $v['organizationId']]); - if (!$re_org) { - $add_biz[] = ['activityId' => $activityId, 'areaId' => $v['parentId'] - , 'bizId' => $v['organizationId'], 'createTime' => date('Y-m-d H:i:s')]; - } else if ($re_org['status'] == -1) { - $this->mdSyliveActivityBiz->update(['status' => 0], ['id' => $re_org['id']]); + 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) { + $re_org = $this->mdSyliveActivityBiz->get(['activityId' => $activityId, 'bizId' => $v['organizationId']]); + if (!$re_org) { + $add_biz[] = ['activityId' => $activityId, 'areaId' => $v['parentId'] + , 'bizId' => $v['organizationId'], 'createTime' => date('Y-m-d H:i:s')]; + } else if ($re_org['status'] == -1) { + $this->mdSyliveActivityBiz->update(['status' => 0], ['id' => $re_org['id']]); + } } + //增加活动商家 + $add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz); } - //增加活动商家 - $add_biz && $this->mdSyliveActivityBiz->add_batch($add_biz); + } else { + $this->mdSyliveActivityBiz->update(['status' => -1], ['activityId' => $activityId, 'status' => 0]); + } + if ($teamIds) { + $teamIds = implode(',', $teamIds); + $res_org = $this->mdSyliveTeam->select(["teamId in({$teamIds})" => null], 'teamId desc', 0, 0, 'teamId,parentId'); + $add_biz = []; + 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) { + $add_biz[] = ['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']]); + } + } + //增加活动商家 + $add_biz && $this->mdSyliveActivityTeam->add_batch($add_biz); + } + } else { + $this->mdSyliveActivityTeam->update(['status' => -1], ['activityId' => $activityId, 'status' => 0]); } $bgImg = $bgImg[0]['fileUrl']; $sharePhoto = $sharePhoto[0]['fileUrl'] ? $sharePhoto[0]['fileUrl'] : ''; @@ -314,6 +375,7 @@ class Activity extends BaseController $activityId = intval($this->input_param('activityId')); $title = $this->input_param('title'); $price = $this->input_param('price'); + $stock = intval($this->input_param('stock')); $itemImg = $this->input_param('itemImg'); $dateRange = $this->input_param('dateRange'); $dateUseRange = $this->input_param('dateUseRange'); @@ -340,6 +402,44 @@ class Activity extends BaseController $item['itemImg'] = $setItemImg; } $jsondata['item'] = $item; + $upDate = ['stock' => $stock, 'jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)]; + $this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]); + $this->return_response(); + } + + /** + * Notes:修改券 + * Created on: 2022/10/21 15:09 + * Created by: dengbw + */ + public function coupon_put() + { + $activityId = intval($this->input_param('activityId')); + $title = $this->input_param('title'); + $price = $this->input_param('price'); + $img = $this->input_param('img'); + $dateUseRange = $this->input_param('dateUseRange'); + $rules = $this->input_param('rules'); + if (!$activityId) { + $this->return_json('参数错误'); + } + $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); + if (!$re) { + $this->return_json('活动不存在'); + } + $jsondata = $re['jsondata'] ? json_decode($re['jsondata'], true) : []; + $useTimeStart = $dateUseRange[0] ? $dateUseRange[0] : ''; + $useTimeEnd = $dateUseRange[1] ? $dateUseRange[1] : ''; + $coupon = ['title' => $title, 'price' => $price, 'rules' => $rules, + 'useTimeStart' => $useTimeStart, 'useTimeEnd' => $useTimeEnd]; + if ($img) { + $setImg = []; + foreach ($img as $v) { + $setImg[] = $v['fileUrl']; + } + $coupon['img'] = $setImg; + } + $jsondata['coupon'] = $coupon; $upDate = ['jsondata' => json_encode($jsondata, JSON_UNESCAPED_UNICODE)]; $this->mdSyliveActivity->update($upDate, ['activityId' => $activityId]); $this->return_response(); @@ -411,7 +511,7 @@ class Activity extends BaseController $this->load->model('live/Live_polyv_session_model', 'mdPolyvSession'); $this->load->model('live/Live_polyv_viewlog_model', 'mdPolyvViewlog'); $title = ''; - $activityData1 = $activityData2 = $areaData = $bizData = $consultantData = $areaAry = $funnel = []; + $activityData1 = $activityData2 = $areaData = $bizData = $consultantData = $areaAry = $funnel = $organizationIds = []; $browse = $subscribe = $watch = $order = 0; $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); if ($re) { @@ -421,19 +521,28 @@ class Activity extends BaseController foreach ($res_biz as $k => $v) { $areaId = intval($v['areaId']); $bizId = intval($v['bizId']); + if ($areaId) {//统计全部顾问 + if (!in_array($areaId, $organizationIds)) { + $organizationIds[] = $areaId; + } + } + if ($bizId) {//统计全部顾问 + $organizationIds[] = $bizId; + $areaAry[$areaId][] = $bizId; + } $re_biz = $this->mdSyliveOrganization->get(['organizationId' => $bizId]); if ($re_biz) { - $consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId], 'distinct(cf_uid)'); - $browse = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId, 'kpi' => 'browse']); - $subscribe = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId, 'kpi' => 'subscribe']); - $watch = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId, 'kpi' => 'watch']); - $order = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'a_id' => $activityId, 'kpi' => 'order']); + $consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)'); + $browse = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'watch']); + $order = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'order']); $livePV = $watchDuration = 0; if ($channelId) { $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') ->from('lc_market_sylive_activity_kpidata as a') ->join('lc_market_sylive_user as b', "b.userId=a.uid", 'left') - ->where(['a.biz_id' => $bizId, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) + ->where(['a.biz_id' => $bizId, 'a.type' => 0, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) ->limit(10000, 0) ->get()->result_array(); if ($res_watch) { @@ -448,31 +557,31 @@ class Activity extends BaseController } } } - $bizData[] = ['areaId' => $areaId, 'bizId' => $bizId, - 'bizName' => $re_biz['organizationName'], 'consultant' => $consultant, 'browse' => $browse, 'subscribe' => $subscribe - , 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; - if (!$areaAry[$areaId]) {//大区 - $areaAry[$areaId] = 1; - } else { - $areaAry[$areaId] += 1; + $allConsultant = 0; + if ($bizId) { + $allConsultant = $this->mdSyliveUser->count(["organizationId" => $bizId, 'status>=' => 0]); } + $consultant > $allConsultant && $allConsultant = $consultant; + $bizData[] = ['areaId' => $areaId, 'bizId' => $bizId, + 'bizName' => $re_biz['organizationName'], 'consultant' => $allConsultant . '/' . $consultant, 'browse' => $browse, 'subscribe' => $subscribe + , 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } foreach ($areaAry as $k => $v) { $areaId = intval($k); $re_area = $this->mdSyliveOrganization->get(['organizationId' => $areaId]); if ($re_area) { - $consultant = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId], 'distinct(cf_uid)'); - $browse = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => 'browse']); - $subscribe = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => 'subscribe']); - $watch = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => 'watch']); - $order = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'a_id' => $activityId, 'kpi' => 'order']); + $consultant = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)'); + $browse = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'watch']); + $order = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'order']); $livePV = $watchDuration = 0; if ($channelId) { $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') ->from('lc_market_sylive_activity_kpidata as a') ->join('lc_market_sylive_user as b', "b.userId=a.uid", 'left') - ->where(['a.area_id' => $areaId, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) + ->where(['a.area_id' => $areaId, 'a.type' => 0, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) ->limit(10000, 0) ->get()->result_array(); if ($res_watch) { @@ -487,27 +596,35 @@ class Activity extends BaseController } } } - $areaData[] = ['areaName' => $re_area['organizationName'], 'biz' => $v, 'consultant' => $consultant + $allConsultant = 0; + if ($v) { + $str_organizationIds = implode(',', array_unique($v)); + $allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]); + } + $consultant > $allConsultant && $allConsultant = $consultant; + $areaData[] = ['areaName' => $re_area['organizationName'], 'biz' => count($v), 'consultant' => $allConsultant . '/' . $consultant , 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch, 'order' => $order , 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } - $res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId], 'id desc', 0, 0, 'distinct(cf_uid) as userId'); + $res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id'); foreach ($res_user as $k => $v) { $userId = intval($v['userId']); $re_user = $this->mdSyliveUser->get(['userId' => $userId]); if ($re_user) { $consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; - $browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => 'browse']); - $subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => 'subscribe']); - $watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => 'watch']); - $order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'kpi' => 'order']); + $re_org = $this->mdSyliveOrganization->get(['organizationId' => $v['biz_id']]); + $re_org && $consultantName .= "({$re_org['organizationName']})"; + $browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'watch']); + $order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'order']); $livePV = $watchDuration = 0; if ($channelId) { $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') ->from('lc_market_sylive_activity_kpidata as a') ->join('lc_market_sylive_user as b', "b.userId=a.uid", 'left') - ->where(['a.cf_uid' => $userId, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) + ->where(['a.cf_uid' => $userId, 'a.a_id' => $activityId, 'a.type' => 0, 'a.kpi' => 'watch', "unionid!=''" => null]) ->limit(10000, 0) ->get()->result_array(); if ($res_watch) { @@ -526,10 +643,10 @@ class Activity extends BaseController , 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } - $browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'browse']); - $subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'subscribe']); - $watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'watch']); - $order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'order']); + $browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'watch']); + $order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'order']); $duration = $livePV = $watchDuration = $watchDuration = $pvDuration = 0; if ($channelId) { $re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]); @@ -542,8 +659,15 @@ class Activity extends BaseController $pvDuration = round($livePV / $re_liveUV['liveUV'], 1); } } + $allConsultant = 0; + $consultant = count($res_user); + if ($organizationIds) { + $str_organizationIds = implode(',', array_unique($organizationIds)); + $allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]); + } + $consultant > $allConsultant && $allConsultant = $consultant; $activityData1 = [['name' => '参与区域数', 'value' => count($areaData)], ['name' => '参与门店数', 'value' => count($bizData)] - , ['name' => '参与顾问数', 'value' => count($res_user)]]; + , ['name' => '全部/参与顾问数', 'value' => $allConsultant . '/' . $consultant]]; $url = "/sylive/activity/statistics/piechart?activityId={$activityId}&"; $activityData2 = [['name' => '浏览数(人)', 'value' => $browse, 'url' => ''], ['name' => '预约数(人)', 'value' => $subscribe, 'url' => ''] , ['name' => '观看数(人)', 'value' => $watch, 'url' => ''], ['name' => '订单数(单)', 'value' => $order, 'url' => ''] @@ -559,9 +683,9 @@ class Activity extends BaseController $browse_actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '观看人数', 'value' => $watch], ['name' => '订单数', 'value' => $order]]; $funnel_browse = ['title' => '浏览转化漏斗', 'expected_data' => $browse_expected_data, 'actual_data' => $browse_actual_data]; - $id_in = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND kpi = 'subscribe')"; - $watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'watch', $id_in => null]); - $order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'kpi' => 'order', $id_in => null]); + $id_in = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND type = 0 AND kpi = 'subscribe')"; + $watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'watch', $id_in => null]); + $order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'order', $id_in => null]); $subscribe_per = number_format_com($subscribe / $browse * 100, 1, ''); $watch_subscribe_per = number_format_com($watch_subscribe / $subscribe * 100, 1, ''); $order_subscribe_per = number_format_com($order_subscribe / $watch_subscribe * 100, 1, ''); @@ -575,6 +699,165 @@ class Activity extends BaseController $this->return_response($data); } + /** + * Notes:活动团队统计 + * Created on: 2022/10/24 10:02 + * Created by: dengbw + * @param null $activityId + */ + public function statistics_team_get($activityId = null) + { + $activityId = intval($activityId); + if (!$activityId) { + $this->return_json('参数错误'); + } + $this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata'); + $this->load->model('market/Market_sylive_user_model', 'mdSyliveUser'); + $this->load->model('live/Live_polyv_session_model', 'mdPolyvSession'); + $this->load->model('live/Live_polyv_viewlog_model', 'mdPolyvViewlog'); + $title = ''; + $activityData1 = $activityData2 = $teamData = $consultantData = $funnel = $teamIds = []; + $browse = $subscribe = $watch = $order = 0; + $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); + if ($re) { + $title = $re['title']; + $channelId = $re['channelId']; + $res_biz = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status' => 0], 'browse desc'); + foreach ($res_biz as $k => $v) { + $area_id = intval($v['teamId1']); + $biz_id = intval($v['teamId2']); + if ($area_id) {//统计全部顾问 + if (!in_array($area_id, $teamIds)) { + $teamIds[] = $area_id; + } + } + if ($biz_id) {//统计全部顾问 + $teamIds[] = $biz_id; + } + $re_team = $this->mdSyliveTeam->get(['teamId' => $biz_id]); + if ($re_team) { + $consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId], 'distinct(cf_uid)'); + $browse = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'watch']); + $order = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'order']); + $livePV = $watchDuration = 0; + if ($channelId) { + $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') + ->from('lc_market_sylive_activity_kpidata as a') + ->join('lc_market_sylive_user as b', "b.userId=a.uid", 'left') + ->where(['a.biz_id' => $biz_id, 'a.type' => 1, 'a.a_id' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) + ->limit(10000, 0) + ->get()->result_array(); + if ($res_watch) { + $str_unionids = implode("','", array_column($res_watch, 'unionid')); + $where_pv = ['channelId' => $channelId, 'param3' => 'live']; + $where_pv["param1 in ('" . $str_unionids . "')"] = null; + $livePV = $this->mdPolyvViewlog->count($where_pv); + $re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv); + if ($re_sum['playDuration']) { + $playDuration = ceil($re_sum['playDuration'] / 60); + $watchDuration = round($playDuration / $livePV); + } + } + } + $allConsultant = 0; + if ($biz_id) { + $allConsultant = $this->mdSyliveUser->count(["teamId" => $biz_id, 'status>=' => 0]); + } + $consultant > $allConsultant && $allConsultant = $consultant; + $teamData[] = ['area_id' => $area_id, 'biz_id' => $biz_id, + 'teamName' => $re_team['teamName'], 'consultant' => $allConsultant . '/' . $consultant, 'browse' => $browse, 'subscribe' => $subscribe + , 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + } + } + $res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId, 'type' => 1], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id'); + foreach ($res_user as $k => $v) { + $userId = intval($v['userId']); + $re_user = $this->mdSyliveUser->get(['userId' => $userId]); + if ($re_user) { + $consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; + $re_team = $this->mdSyliveTeam->get(['teamId' => $v['biz_id']]); + $re_team && $consultantName .= "({$re_team['teamName']})"; + $browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'watch']); + $order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'order']); + $livePV = $watchDuration = 0; + if ($channelId) { + $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') + ->from('lc_market_sylive_activity_kpidata as a') + ->join('lc_market_sylive_user as b', "b.userId=a.uid", 'left') + ->where(['a.cf_uid' => $userId, 'a.a_id' => $activityId, 'a.type' => 1, 'a.kpi' => 'watch', "unionid!=''" => null]) + ->limit(10000, 0) + ->get()->result_array(); + if ($res_watch) { + $str_unionids = implode("','", array_column($res_watch, 'unionid')); + $where_pv = ['channelId' => $channelId, 'param3' => 'live']; + $where_pv["param1 in ('" . $str_unionids . "')"] = null; + $livePV = $this->mdPolyvViewlog->count($where_pv); + $re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv); + if ($re_sum['playDuration']) { + $playDuration = ceil($re_sum['playDuration'] / 60); + $watchDuration = round($playDuration / $livePV); + } + } + } + $consultantData[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch + , 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + } + } + $browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'watch']); + $order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'order']); + $duration = $livePV = $watchDuration = $watchDuration = $pvDuration = 0; + if ($channelId) { + $re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]); + if ($re_duration['duration']) { + $re_liveUV = $this->mdPolyvSession->sum('liveUV', ['channelId' => $channelId]); + $re_livePV = $this->mdPolyvSession->sum('livePV', ['channelId' => $channelId]); + $duration = ceil($re_duration['duration'] / 60); + $livePV = $re_livePV['livePV']; + $watchDuration = round($duration / $livePV); + $pvDuration = round($livePV / $re_liveUV['liveUV'], 1); + } + } + $allConsultant = 0; + $consultant = count($res_user); + if ($teamIds) { + $str_teamIds = implode(',', array_unique($teamIds)); + $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_teamIds})", 'status>=' => 0, 'teamId>' => 0]); + } + $consultant > $allConsultant && $allConsultant = $consultant; + $activityData1 = [['name' => '参与团队数', 'value' => count($teamData)] + , ['name' => '全部/参与团员数', 'value' => $allConsultant . '/' . $consultant]]; + $activityData2 = [['name' => '浏览数(人)', 'value' => $browse, 'url' => ''], ['name' => '预约数(人)', 'value' => $subscribe, 'url' => ''] + , ['name' => '观看数(人)', 'value' => $watch, 'url' => ''], ['name' => '订单数(单)', 'value' => $order, 'url' => ''] + , ['name' => '直播时长(分)', 'value' => $duration, 'url' => ''], ['name' => '观看数(人次)', 'value' => $livePV, 'url' => ''] + , ['name' => '人均观看(分)', 'value' => $watchDuration, 'url' => ''], ['name' => '人均观看(次)', 'value' => $pvDuration, 'url' => '']]; + } + $watch_per = number_format_com($watch / $browse * 100, 1, ''); + $order_per = number_format_com($order / $watch_per * 100, 1, ''); + $browse_expected_data = [['name' => "浏览人数(100%)", 'value' => 100], ['name' => "观看人数({$watch_per}%)", 'value' => 66.7], ['name' => "订单数({$order_per}%)", 'value' => 33.3]]; + $browse_actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '观看人数', 'value' => $watch], ['name' => '订单数', 'value' => $order]]; + $funnel_browse = ['title' => '浏览转化漏斗', 'expected_data' => $browse_expected_data, 'actual_data' => $browse_actual_data]; + $id_in = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND type=1 AND kpi = 'subscribe')"; + $watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'watch', $id_in => null]); + $order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'order', $id_in => null]); + $subscribe_per = number_format_com($subscribe / $browse * 100, 1, ''); + $watch_subscribe_per = number_format_com($watch_subscribe / $subscribe * 100, 1, ''); + $order_subscribe_per = number_format_com($order_subscribe / $watch_subscribe * 100, 1, ''); + $subscribe_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "预约人数({$subscribe_per}%)", 'value' => 75] + , ['name' => "观看人数({$watch_subscribe_per}%)", 'value' => 50], ['name' => "订单数({$order_subscribe_per}%)", 'value' => 25]]; + $subscribe_actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '预约人数', 'value' => $subscribe] + , ['name' => '观看人数', 'value' => $watch_subscribe], ['name' => '订单数', 'value' => $order_subscribe]]; + $funnel_subscribe = ['title' => '预约转化漏斗', 'expected_data' => $subscribe_expected_data, 'actual_data' => $subscribe_actual_data]; + $data = ['activityId' => $activityId, 'title' => $title, 'activityData1' => $activityData1, 'activityData2' => $activityData2, + 'teamData' => $teamData, 'consultantData' => $consultantData, 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe]; + $this->return_response($data); + } + /** * Notes:获取区域饼状数据 * Created on: 2022/10/9 17:21 @@ -692,10 +975,10 @@ class Activity extends BaseController $activityId = intval($params['activityId']); $page = $params['page']; $limit = $params['limit']; - $item_title = $params['item_title']; $uname = $params['uname']; $mobile = $params['mobile']; $status = $params['status']; + $cfrom = $params['cfrom']; $sort = $params['sort']; $order = $params['order']; !$page && $page = 1; @@ -704,6 +987,8 @@ class Activity extends BaseController if ($sort && $order) { if ($sort == 'statusName') { $sort_order = 'status ' . $order; + } else if ($sort == 'cfromName') { + $sort_order = 'cfrom ' . $order; } else { $sort_order = $sort . ' ' . $order; } @@ -714,9 +999,9 @@ class Activity extends BaseController } $where['status'] = $status; $activityId && $where['item_id'] = $activityId; - $item_title && $where['item_title'] = $item_title; $uname && $where['uname'] = $uname; $mobile && $where['mobile'] = $mobile; + strlen($cfrom) && $where['cfrom'] = $cfrom; if ($limit == 10000) { $count = 1; } else { @@ -725,12 +1010,12 @@ class Activity extends BaseController if ($count) { $res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit); foreach ($res as $v) { - $consultant = $this->consultantGet(['a_id' => $v['item_id'], 'uid' => $v['uid']]); + $consultant = $this->consultantGet(['a_id' => $v['item_id'], 'cfrom' => $v['cfrom'], 'uid' => $v['uid']]); $list[] = [ - 'id' => $v['id'], 'uname' => $v['uname'], 'mobile' => $v['mobile'], 'item_title' => $v['item_title'] + 'id' => $v['id'], 'sid' => $v['sid'], 'uname' => $v['uname'], 'mobile' => $v['mobile'], 'item_title' => $v['item_title'] , 'total_price' => $v['total_price'], 'pay_time' => $v['pay_time'] != '0000-00-00 00:00:00' ? $v['pay_time'] : '' - , 'statusName' => $this->mdSyliveOrder->statusAry($v['status']), 'createTime' => $v['createTime'] - , 'area' => $consultant['area'], 'stores' => $consultant['stores'], 'consultant' => $consultant['consultant'] + , 'statusName' => $this->mdSyliveOrder->statusAry($v['status']), 'cfromName' => $this->mdSyliveOrder->cfromAry($v['cfrom']) + , 'createTime' => $v['createTime'], 'area' => $consultant['area'], 'stores' => $consultant['stores'], 'consultant' => $consultant['consultant'] ]; } } @@ -751,13 +1036,20 @@ class Activity extends BaseController private function consultantGet($params) { $area = $stores = $consultant = ''; - $re = $this->mdSyliveActivityKpidata->get(['a_id' => $params['a_id'], 'uid' => $params['uid'], 'kpi' => 'order']); + $re = $this->mdSyliveActivityKpidata->get(['a_id' => $params['a_id'], 'uid' => $params['uid'], 'type' => $params['cfrom'], 'kpi' => 'order']); if ($re['cf_uid']) { - $res_orga = $this->mdSyliveOrganization->get(["organizationId" => $re['area_id']]); - $res_orgb = $this->mdSyliveOrganization->get(["organizationId" => $re['biz_id']]); + if ($params['cfrom'] == 1) { + $res_teama = $this->mdSyliveTeam->get(["teamId" => $re['area_id']]); + $res_teamb = $this->mdSyliveTeam->get(["teamId" => $re['biz_id']]); + $res_teama['teamName'] && $area = $res_teama['teamName']; + $res_teamb['teamName'] && $stores = $res_teamb['teamName']; + } else { + $res_orga = $this->mdSyliveOrganization->get(["organizationId" => $re['area_id']]); + $res_orgb = $this->mdSyliveOrganization->get(["organizationId" => $re['biz_id']]); + $res_orga['organizationName'] && $area = $res_orga['organizationName']; + $res_orgb['organizationName'] && $stores = $res_orgb['organizationName']; + } $re_user = $this->mdSyliveUser->get(['userId' => $re['cf_uid']]); - $res_orga['organizationName'] && $area = $res_orga['organizationName']; - $res_orgb['organizationName'] && $stores = $res_orgb['organizationName']; $re_user['uname'] && $consultant = $re_user['uname']; } return ['area' => $area, 'stores' => $stores, 'consultant' => $consultant]; diff --git a/market/controllers/api/sylive/Goods.php b/market/controllers/api/sylive/Goods.php new file mode 100644 index 00000000..06900e1b --- /dev/null +++ b/market/controllers/api/sylive/Goods.php @@ -0,0 +1,131 @@ +load->model('market/Market_sylive_items_model', 'mdSyliveItems'); + } + + /** + * Notes:商品管理列表 + * Created on: 2022/9/20 14:48 + * Created by: dengbw + */ + public function page_get() + { + $activityId = intval($this->input_param('activityId')); + $page = $this->input_param('page'); + $limit = $this->input_param('limit'); + $title = $this->input_param('title'); + $sort = $this->input_param('sort'); + $order = $this->input_param('order'); + !$page && $page = 1; + !$limit && $limit = 10; + $sort_order = 'id desc'; + if ($sort && $order) { + $sort_order = $sort . ' ' . $order; + } + $where['status>'] = 0; + $activityId && $where['a_id'] = $activityId; + $title && $where['title'] = $title; + $count = $this->mdSyliveItems->count($where); + $list = []; + if ($count) { + $res = $this->mdSyliveItems->select($where, $sort_order, $page, $limit); + foreach ($res as $v) { + $list[] = $v; + } + } + $date = ['list' => $list, 'count' => $count]; + $this->return_response_list($date); + } + + /** + * Notes:添加商品 + * Created on: 2022/10/21 16:46 + * Created by: dengbw + */ + public function index_post() + { + $a_id = intval($this->input_param('a_id')); + $title = $this->input_param('title'); + $imgs = $this->input_param('imgs'); + $descrip = $this->input_param('descrip'); + $price = $this->input_param('price'); + $stock = $this->input_param('stock'); + $sort = $this->input_param('sort'); + if (!$a_id) { + $this->return_json('参数错误'); + } + if (!$title) { + $this->return_json('请输入商品标题'); + } + $addDate = ['a_id' => $a_id, 'title' => $title, 'price' => $price, 'stock' => $stock, 'sort' => $sort + , 'descrip' => $descrip, 'c_time' => time()]; + if ($imgs) { + $setImgs = []; + foreach ($imgs as $v) { + $setImgs[] = $v['fileUrl']; + } + $addDate['imgs'] = $setImgs; + } + $id = $this->mdSyliveItems->add($addDate); + if (!$id) { + $this->return_json('添加商品失败'); + } + $this->return_response(); + } + + /** + * Notes:修改商品 + * Created on: 2022/10/21 14:48 + * Created by: dengbw + */ + public function index_put() + { + } + + /** + * Notes:删除商品 + * Created on: 2022/10/21 16:10 + * Created by: dengbw + * @param null $id + */ + public function index_delete($id = null) + { + if (!$id) { + $this->return_json('参数错误'); + } + $this->mdSyliveItems->update(['status' => -1], ['id' => $id]); + $this->return_response(); + } + + /** + * Notes:批量删除商品 + * Created on: 2022/10/21 17:11 + * Created by: dengbw + */ + public function batch_delete() + { + $ids = $this->inputs; + if (!$ids) { + $this->return_json('参数错误'); + } + $str_ids = implode(',', $ids); + if ($str_ids) { + $this->mdSyliveItems->update(['status' => -1], ["id in($str_ids)" => null]); + } + $this->return_response(); + } + +} \ No newline at end of file diff --git a/market/controllers/api/sylive/Organization.php b/market/controllers/api/sylive/Organization.php index d03f54f2..0367307f 100644 --- a/market/controllers/api/sylive/Organization.php +++ b/market/controllers/api/sylive/Organization.php @@ -48,13 +48,40 @@ class Organization extends BaseController $res[$k]['organizationId'] = intval($v['organizationId']); $res[$k]['parentId'] = intval($v['parentId']); $res[$k]['sortNumber'] = intval($v['sortNumber']); - $city = []; + $city = $logo = []; if ($v['countyId']) { $city[] = $v['provinceId']; $city[] = $v['cityId']; $city[] = $v['countyId']; } $res[$k]['city'] = $city; + if ($v['logo']) { + $logo[] = ['uid' => 1, 'fileUrl' => $v['logo'], 'url' => build_qiniu_image_url($v['logo']), 'status' => 'done']; + } + $res[$k]['logo'] = $logo; + } + $this->return_response_list($res); + } + + /** + * Notes:查找上级机构 + * Created on: 2022/10/24 15:24 + * Created by: dengbw + */ + public function parent_get() + { + $res = []; + if ($_SESSION['brandName']) {//只找该品牌机构 + $re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]); + if ($re_org['organizationId']) { + $res[] = ['organizationId' => intval($re_org['organizationId']), 'organizationName' => $re_org['organizationName']]; + } + } else { + $parentId = intval($this->input_param('parentId')); + $sort_order = 'sortNumber asc,organizationId desc'; + $where['status>='] = 0; + $where['parentId'] = $parentId; + $res = $this->mdSyliveOrganization->select($where, $sort_order,0,0,'organizationId,organizationName'); } $this->return_response_list($res); } @@ -73,6 +100,7 @@ class Organization extends BaseController $sortNumber = intval($this->input_param('sortNumber')); $comments = $this->input_param('comments'); $city = $this->input_param('city'); + $logo = $this->input_param('logo'); if ($_SESSION['brandName'] && !$parentId) {//品牌机构必顺选择上级机构 $this->return_json('请选择上级机构'); } @@ -88,9 +116,10 @@ class Organization extends BaseController $this->return_json('选择的上级机构不能保存,请重新选择'); } } + $logo = $logo[0]['fileUrl'] ? $logo[0]['fileUrl'] : ''; !$comments && $comments = ''; $addDate = ['parentId' => $parentId, 'organizationName' => $organizationName, 'organizationFullName' => $organizationFullName - , 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments + , 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments, 'logo' => $logo , 'createTime' => date('Y-m-d H:i:s')]; if ($city) { $addDate['provinceId'] = intval($city[0]); @@ -119,11 +148,15 @@ class Organization extends BaseController $sortNumber = intval($this->input_param('sortNumber')); $comments = $this->input_param('comments'); $city = $this->input_param('city'); + $logo = $this->input_param('logo'); + $logo = $logo[0]['fileUrl'] ? $logo[0]['fileUrl'] : ''; !$comments && $comments = ''; if ($_SESSION['brandName']) {//品牌机构 $re_org = $this->mdSyliveOrganization->get(['organizationId' => $organizationId]); - if ($re_org && $re_org['parentId'] == 0) { - $this->return_json('无此机构修改权限,请联系管理员'); + if ($re_org && $re_org['parentId'] == 0) {//一级品牌不可修改字段 + $parentId = 0; + $organizationType = 1; + $organizationName = $re_org['organizationName']; } } if (!$organizationId) { @@ -143,7 +176,7 @@ class Organization extends BaseController } !$comments && $comments = ''; $upDate = ['parentId' => $parentId, 'organizationName' => $organizationName, 'organizationFullName' => $organizationFullName - , 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments]; + , 'organizationType' => $organizationType, 'sortNumber' => $sortNumber, 'comments' => $comments, 'logo' => $logo]; if ($city) { $upDate['provinceId'] = intval($city[0]); $upDate['cityId'] = intval($city[1]); diff --git a/market/controllers/api/sylive/Team.php b/market/controllers/api/sylive/Team.php new file mode 100644 index 00000000..80967d44 --- /dev/null +++ b/market/controllers/api/sylive/Team.php @@ -0,0 +1,157 @@ +load->model('market/Market_sylive_team_model', 'mdSyliveTeam'); + } + + /** + * Notes:获取团队 + * Created on: 2022/9/16 11:11 + * Created by: dengbw + */ + public function index_get() + { + $unTeamType = $this->input_param('unTeamType'); + $where['status>='] = 0; + $unTeamType && $where['teamType<>'] = $unTeamType; + $sort_order = 'sortNumber asc,teamId desc'; + if ($_SESSION['brandName']) {//只找该品牌机构 + $this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization'); + $re_org = $this->mdSyliveOrganization->get(['organizationName' => $_SESSION['brandName'], 'parentId' => 0, 'status' => 0]); + if ($re_org['organizationId']) { + $res_team = $this->mdSyliveTeam->select(['status>=' => 0, 'organizationId' => $re_org['organizationId']], 'parentId asc,sortNumber asc', 0, 0, 'teamId'); + if ($res_team) { + $teamIds = []; + foreach ($res_team as $k => $v) { + $teamIds[] = $v['teamId']; + } + $res_all = $this->mdSyliveTeam->select($where, 'parentId asc,sortNumber asc', 0, 0, 'teamId,parentId'); + foreach ($res_all as $k => $v) { + if (in_array($v['parentId'], $teamIds)) { + $teamIds[] = $v['teamId']; + } + } + $str_teamIds = implode(',', array_unique($teamIds)); + $where["teamId in({$str_teamIds})"] = null; + } else { + $where['teamId'] = -1; + } + } else { + $where['teamId'] = -1; + } + } + $res = $this->mdSyliveTeam->select($where, $sort_order); + foreach ($res as $k => $v) { + $res[$k]['teamId'] = intval($v['teamId']); + $res[$k]['parentId'] = intval($v['parentId']); + $res[$k]['sortNumber'] = intval($v['sortNumber']); + $res[$k]['organizationId'] = $v['organizationId'] ? $v['organizationId'] : ''; + $city = $logo = []; + if ($v['cityId']) { + $city[] = $v['provinceId']; + $city[] = $v['cityId']; + } + $res[$k]['city'] = $city; + } + $this->return_response_list($res); + } + + /** + * Notes:添加团队 + * Created on: 2022/9/19 16:43 + * Created by: dengbw + */ + public function index_post() + { + $parentId = intval($this->input_param('parentId')); + $teamName = $this->input_param('teamName'); + $sortNumber = intval($this->input_param('sortNumber')); + $comments = $this->input_param('comments'); + $city = $this->input_param('city'); + $teamType = $this->input_param('teamType'); + $organizationId = $this->input_param('organizationId'); + if (!$teamName) { + $this->return_json('请输入团队名称'); + } + if (!$parentId && !$organizationId) { + $this->return_json('请选择所属团队'); + } + !$comments && $comments = ''; + $addDate = ['parentId' => $parentId, 'teamName' => $teamName, 'sortNumber' => $sortNumber, 'comments' => $comments + , 'teamType' => $teamType, 'organizationId' => $organizationId, 'createTime' => date('Y-m-d H:i:s')]; + if ($city) { + $addDate['provinceId'] = intval($city[0]); + $addDate['cityId'] = intval($city[1]); + } + $id = $this->mdSyliveTeam->add($addDate); + if (!$id) { + $this->return_json('添加团队失败'); + } + $this->return_response(); + } + + /** + * Notes:修改团队 + * Created on: 2022/9/19 17:29 + * Created by: dengbw + */ + public function index_put() + { + $teamId = intval($this->input_param('teamId')); + $parentId = intval($this->input_param('parentId')); + $teamName = $this->input_param('teamName'); + $sortNumber = intval($this->input_param('sortNumber')); + $comments = $this->input_param('comments'); + $city = $this->input_param('city'); + $teamType = $this->input_param('teamType'); + $organizationId = $this->input_param('organizationId'); + !$comments && $comments = ''; + if (!$teamId) { + $this->return_json('参数错误'); + } + if (!$teamName) { + $this->return_json('请输入团队名称'); + } + if (!$parentId && !$organizationId) { + $this->return_json('请选择所属团队'); + } + !$comments && $comments = ''; + $upDate = ['parentId' => $parentId, 'teamName' => $teamName, 'sortNumber' => $sortNumber, 'comments' => $comments + , 'teamType' => $teamType, 'organizationId' => $organizationId]; + if ($city) { + $upDate['provinceId'] = intval($city[0]); + $upDate['cityId'] = intval($city[1]); + } + $this->mdSyliveTeam->update($upDate, ['teamId' => $teamId]); + $this->return_response(); + } + + /** + * Notes:删除团队 + * Created on: 2022/9/19 11:08 + * Created by: dengbw + * @param null $teamId + */ + public function index_delete($teamId = null) + { + $teamId = intval($teamId); + if (!$teamId) { + $this->return_json('参数错误'); + } + $this->mdSyliveTeam->update(['status' => -1], ['teamId' => $teamId]); + $this->return_response(); + } + +} \ No newline at end of file diff --git a/market/controllers/api/sylive/TeamUser.php b/market/controllers/api/sylive/TeamUser.php new file mode 100644 index 00000000..102bb5ec --- /dev/null +++ b/market/controllers/api/sylive/TeamUser.php @@ -0,0 +1,184 @@ +load->model('market/Market_sylive_user_model', 'mdSyliveUser'); + } + + /** + * Notes:用户管理列表 + * Created on: 2022/9/20 14:48 + * Created by: dengbw + */ + public function page_get() + { + $page = $this->input_param('page'); + $limit = $this->input_param('limit'); + $uname = $this->input_param('uname'); + $nickname = $this->input_param('nickname'); + $sort = $this->input_param('sort'); + $order = $this->input_param('order'); + $teamId = intval($this->input_param('teamId')); + !$page && $page = 1; + !$limit && $limit = 10; + $sort_order = 'userId desc'; + if ($sort && $order) { + if ($sort == 'sexName') { + $sort_order = 'sex ' . $order; + } else { + $sort_order = $sort . ' ' . $order; + } + } + $list = []; + $where['status>='] = 0; + $teamId && $where['teamId'] = $teamId; + $uname && $where['uname'] = $uname; + $nickname && $where['nickname'] = $nickname; + $count = $this->mdSyliveUser->count($where); + if ($count) { + $res = $this->mdSyliveUser->select($where, $sort_order, $page, $limit); + foreach ($res as $v) { + $sexName = $this->mdSyliveUser->sexAry($v['sex']); + $status = intval($v['status']); + $list[] = [ + 'userId' => $v['userId'], 'uname' => $v['uname'], 'nickname' => $v['nickname'], 'mobile' => $v['mobile'] + , 'teamId' => $teamId, 'status' => $status, 'sex' => $v['sex'], 'sexName' => $sexName, 'createTime' => $v['createTime']]; + } + } + $date = ['list' => $list, 'count' => $count]; + $this->return_response_list($date); + } + + /** + * Notes:添加用户 + * Created on: 2022/9/21 16:46 + * Created by: dengbw + */ + public function index_post() + { + $mobile = $this->input_param('mobile'); + $teamId = intval($this->input_param('teamId')); + $sex = intval($this->input_param('sex')); + $uname = $this->input_param('uname'); + if (!$mobile) { + $this->return_json('请输入手机号'); + } + if (!$teamId) { + $this->return_json('请选择所属团队'); + } + if (!$uname) { + $this->return_json('请输入姓名'); + } + $re = $this->mdSyliveUser->get(['mobile' => $mobile, 'status<>' => -1]); + if ($re && ($re['teamId'] || $re['organizationId'])) { + $this->return_json('手机号已存在'); + } + $addDate = ['teamId' => $teamId, 'sex' => $sex, 'uname' => $uname, 'status' => 0, 'organizationId' => 0]; + if ($re['userId']) { + $this->mdSyliveUser->update($addDate, ['userId' => $re['userId']]); + $this->return_response([], '绑定用户成功'); + } else { + $addDate['mobile'] = $mobile; + $addDate['createTime'] = date('Y-m-d H:i:s'); + $id = $this->mdSyliveUser->add($addDate); + if (!$id) { + $this->return_json('添加用户失败'); + } + $this->return_response(); + } + } + + /** + * Notes:修改用户 + * Created on: 2022/9/21 14:48 + * Created by: dengbw + */ + public function index_put() + { + $userId = intval($this->input_param('userId')); + $teamId = intval($this->input_param('teamId')); + $sex = intval($this->input_param('sex')); + $uname = $this->input_param('uname'); + if (!$userId) { + $this->return_json('参数错误'); + } + if (!$teamId) { + $this->return_json('请选择所属团队'); + } + if (!$uname) { + $this->return_json('请输入姓名'); + } + $upDate = ['teamId' => $teamId, 'sex' => $sex, 'uname' => $uname]; + $this->mdSyliveUser->update($upDate, ['userId' => $userId]); + $this->return_response(); + } + + /** + * Notes:修改状态 + * Created on: 2022/9/21 16:10 + * Created by: dengbw + */ + public function status_put() + { + $userId = $this->input_param('userId'); + $status = $this->input_param('status'); + if (!$userId) { + $this->return_json('参数错误'); + } + $this->mdSyliveUser->update(['status' => $status], ['userId' => $userId]); + $this->return_response(); + } + + /** + * Notes:删除用户 + * Created on: 2022/9/21 16:10 + * Created by: dengbw + * @param null $userId + */ + public function index_delete($userId = null) + { + if (!$userId) { + $this->return_json('参数错误'); + } + $this->mdSyliveUser->update(['status' => -1], ['userId' => $userId]); + $this->return_response(); + } + + /** + * Notes:栓验字段 + * Created on: 2022/9/21 15:52 + * Created by: dengbw + */ + public function existence_get() + { + $field = $this->input_param('field'); + $value = $this->input_param('value'); + $id = $this->input_param('id'); + if (!$id) { + $where = [$field => $value, 'status<>' => -1]; + $re = $this->mdSyliveUser->get($where); + if ($re) { + if ($field == 'mobile') { + if ($re['teamId'] || $re['organizationId']) { + $this->return_json('已存在', 0); + } + } else { + $this->return_json('已存在', 0); + } + } + } + $this->return_json('不存在', 1); + } + +} \ No newline at end of file diff --git a/market/controllers/api/sylive/User.php b/market/controllers/api/sylive/User.php index 68e80856..bc088b4f 100644 --- a/market/controllers/api/sylive/User.php +++ b/market/controllers/api/sylive/User.php @@ -86,11 +86,11 @@ class User extends BaseController if (!$uname) { $this->return_json('请输入姓名'); } - $re = $this->mdSyliveUser->get(['mobile' => $mobile]); - if ($re['organizationId']) { + $re = $this->mdSyliveUser->get(['mobile' => $mobile, 'status<>' => -1]); + if ($re && ($re['teamId'] || $re['organizationId'])) { $this->return_json('手机号已存在'); } - $addDate = ['organizationId' => $organizationId, 'sex' => $sex, 'uname' => $uname]; + $addDate = ['organizationId' => $organizationId, 'sex' => $sex, 'uname' => $uname, 'status' => 0, 'teamId' => 0]; if ($re['userId']) { $this->mdSyliveUser->update($addDate, ['userId' => $re['userId']]); $this->return_response([], '绑定用户成功'); @@ -172,11 +172,16 @@ class User extends BaseController $value = $this->input_param('value'); $id = $this->input_param('id'); if (!$id) { - $where = [$field => $value]; - $field == 'mobile' && $where['organizationId>'] = 0; - $re = $this->mdSyliveUser->get([$field => $value]); + $where = [$field => $value, 'status<>' => -1]; + $re = $this->mdSyliveUser->get($where); if ($re) { - $this->return_json('已存在', 0); + if ($field == 'mobile') { + if ($re['teamId'] || $re['organizationId']) { + $this->return_json('已存在', 0); + } + } else { + $this->return_json('已存在', 0); + } } } $this->return_json('不存在', 1); diff --git a/market/controllers/api/system/User.php b/market/controllers/api/system/User.php index e6b9c579..d7291511 100644 --- a/market/controllers/api/system/User.php +++ b/market/controllers/api/system/User.php @@ -260,7 +260,8 @@ class User extends BaseController $value = $this->input_param('value'); $id = $this->input_param('id'); if (!$id) { - $re = $this->mdSysAdmin->get([$field => $value]); + $where = [$field => $value, 'status<>' => -1]; + $re = $this->mdSysAdmin->get($where); if ($re) { $this->return_json('已存在', 0); } diff --git a/market/hooks/ApiAuthHook.php b/market/hooks/ApiAuthHook.php index 05b7adcb..62a08843 100644 --- a/market/hooks/ApiAuthHook.php +++ b/market/hooks/ApiAuthHook.php @@ -88,6 +88,8 @@ class ApiAuthHook $authority = 'system:dictionary:' . $authority_set; } else if (strstr($route, '/sylive/user')) {//机构用户权限 $authority = 'sylive:organization:' . $authority_set; + } else if (strstr($route, '/sylive/teamUser')) {//团队用户权限 + $authority = 'sylive:team:' . $authority_set; } $this->CI->load->model('market/Market_sys_menu_model'); $re_menu = $this->CI->Market_sys_menu_model->get(["menuId in({$menuIds})" => null, 'status' => 0