From 3a634e99d7103f564c5aefa5b6ad01c8a019793e Mon Sep 17 00:00:00 2001 From: dengbw Date: Tue, 8 Nov 2022 19:28:01 +0800 Subject: [PATCH] market_goods_1108 --- .../market/Market_sylive_order_model.php | 19 +- market/controllers/api/sylive/Activity.php | 115 +----------- market/controllers/api/sylive/Goods.php | 80 +++++++-- market/controllers/api/sylive/Order.php | 168 ++++++++++++------ 4 files changed, 205 insertions(+), 177 deletions(-) diff --git a/common/models/market/Market_sylive_order_model.php b/common/models/market/Market_sylive_order_model.php index f8bbc6ff..aba202ce 100644 --- a/common/models/market/Market_sylive_order_model.php +++ b/common/models/market/Market_sylive_order_model.php @@ -33,7 +33,7 @@ class Market_sylive_order_model extends HD_Model } /** - * Notes:订单类型 + * Notes:订单来源 * Created on: 2022/10/25 14:46 * Created by: dengbw * @param string $cfrom @@ -49,4 +49,21 @@ class Market_sylive_order_model extends HD_Model } } + /** + * Notes:订单类型 + * Created on: 2022/11/07 14:46 + * Created by: dengbw + * @param string $type + * @return array|mixed + */ + public function typeAry($type = '') + { + $arr = [0 => '权益', 1 => '商品']; + if (strlen($type)) { + return $arr[$type]; + } else { + return $arr; + } + } + } \ No newline at end of file diff --git a/market/controllers/api/sylive/Activity.php b/market/controllers/api/sylive/Activity.php index 6cd32dcc..7eaadb7b 100644 --- a/market/controllers/api/sylive/Activity.php +++ b/market/controllers/api/sylive/Activity.php @@ -261,10 +261,11 @@ class Activity extends BaseController if (!$activityId) { $this->return_json('参数错误'); } - $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); + $re = $this->mdSyliveActivity->get(['activityId' => $activityId], 'activityId,title'); if (!$re) { $this->return_json('活动不存在'); } + $this->return_response($re); } @@ -517,116 +518,4 @@ class Activity extends BaseController $this->return_response(); } - /** - * Notes:活动订单列表 - * Created on: 2022/9/29 9:53 - * Created by: dengbw - */ - public function order_get() - { - $date = $this->orderList($this->inputs); - $this->return_response_list($date); - } - - /** - * Notes:导出活动订单数据 - * Created on: 2022/10/10 15:26 - * Created by: dengbw - */ - public function order_export_get() - { - $this->inputs['page'] = 1; - $this->inputs['limit'] = 10000; - $date = $this->orderList($this->inputs); - $this->return_response_list($date); - } - - private function orderList($params) - { - $this->load->model('market/Market_sylive_order_model', 'mdSyliveOrder'); - $this->load->model('market/Market_sylive_user_model', 'mdSyliveUser'); - $this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata'); - $activityId = intval($params['activityId']); - $page = $params['page']; - $limit = $params['limit']; - $uname = $params['uname']; - $mobile = $params['mobile']; - $status = $params['status']; - $cfrom = $params['cfrom']; - $sort = $params['sort']; - $order = $params['order']; - !$page && $page = 1; - !$limit && $limit = 10; - $sort_order = 'id desc'; - if ($sort && $order) { - if ($sort == 'statusName') { - $sort_order = 'status ' . $order; - } else if ($sort == 'cfromName') { - $sort_order = 'cfrom ' . $order; - } else { - $sort_order = $sort . ' ' . $order; - } - } - $list = []; - if (!strlen($status)) { - $status = 1; - } - $where['status'] = $status; - $activityId && $where['itemId'] = $activityId; - $uname && $where['uname LIKE "%' . trim($uname) . '%"'] = null; - $mobile && $where['mobile LIKE "%' . trim($mobile) . '%"'] = null; - strlen($cfrom) && $where['cfrom'] = $cfrom; - if ($limit == 10000) { - $count = 1; - } else { - $count = $this->mdSyliveOrder->count($where); - } - if ($count) { - $res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit); - foreach ($res as $v) { - $consultant = $this->consultantGet(['activityId' => $v['itemId'], 'cfrom' => $v['cfrom'], 'userId' => $v['userId']]); - $list[] = [ - 'id' => $v['id'], 'sid' => $v['sid'], 'uname' => $v['uname'], 'mobile' => $v['mobile'], 'itemTitle' => $v['itemTitle'] - , 'totalPrice' => $v['totalPrice'], 'payTime' => $v['payTime'] != '0000-00-00 00:00:00' ? $v['payTime'] : '' - , 'statusName' => $this->mdSyliveOrder->statusAry($v['status']), 'cfromName' => $this->mdSyliveOrder->cfromAry($v['cfrom']) - , 'createTime' => $v['createTime'], 'area' => $consultant['area'], 'stores' => $consultant['stores'], 'consultant' => $consultant['consultant'] - ]; - } - } - if ($limit == 10000) { - return $list; - } else { - return ['list' => $list, 'count' => $count]; - } - } - - /** - * Notes:获取顾问信息 - * Created on: 2022/10/8 11:29 - * Created by: dengbw - * @param $params - * @return string - */ - private function consultantGet($params) - { - $area = $stores = $consultant = ''; - $re = $this->mdSyliveActivityKpidata->get(['activityId' => $params['activityId'], 'userId' => $params['userId'], 'type' => $params['cfrom'], 'kpi' => 'order']); - if ($re['cfUserId']) { - if ($params['cfrom'] == 1) { - $res_teama = $this->mdSyliveTeam->get(["teamId" => $re['areaId']]); - $res_teamb = $this->mdSyliveTeam->get(["teamId" => $re['bizId']]); - $res_teama['teamName'] && $area = $res_teama['teamName']; - $res_teamb['teamName'] && $stores = $res_teamb['teamName']; - } else { - $res_orga = $this->mdSyliveOrganization->get(["organizationId" => $re['areaId']]); - $res_orgb = $this->mdSyliveOrganization->get(["organizationId" => $re['bizId']]); - $res_orga['organizationName'] && $area = $res_orga['organizationName']; - $res_orgb['organizationName'] && $stores = $res_orgb['organizationName']; - } - $re_user = $this->mdSyliveUser->get(['userId' => $re['cfUserId']]); - $re_user['uname'] && $consultant = $re_user['uname']; - } - return ['area' => $area, 'stores' => $stores, 'consultant' => $consultant]; - } - } \ No newline at end of file diff --git a/market/controllers/api/sylive/Goods.php b/market/controllers/api/sylive/Goods.php index e7261631..7b4f9f83 100644 --- a/market/controllers/api/sylive/Goods.php +++ b/market/controllers/api/sylive/Goods.php @@ -31,19 +31,32 @@ class Goods extends BaseController $order = $this->input_param('order'); !$page && $page = 1; !$limit && $limit = 10; - $sort_order = 'id desc'; + $sort_order = 'itemId desc'; if ($sort && $order) { $sort_order = $sort . ' ' . $order; } - $where['status>'] = 0; + $where['status>='] = 0; + $title && $where['title LIKE "%' . trim($title) . '%"'] = null; $activityId && $where['activityId'] = $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; + $banner = []; + $dateRange = ''; + $imgs = $v['imgs'] ? json_decode($v['imgs'], true) : []; + if ($imgs['banner']) { + foreach ($imgs['banner'] as $k2 => $v2) { + $banner[] = ['uid' => $k2 + 1, 'fileUrl' => $v2, 'url' => build_qiniu_image_url($v2), 'status' => 'done']; + } + } + $timeStart = $v['timeStart'] != '0000-00-00 00:00:00' ? $v['timeStart'] : ''; + $v['timeStart'] && $dateRange[] = $v['timeStart']; + $v['timeEnd'] && $dateRange[] = $v['timeEnd']; + $list[] = ['itemId' => $v['itemId'], 'activityId' => $v['activityId'], 'title' => $v['title'], 'banner' => $banner + , 'dateRange' => $dateRange, 'descrip' => $v['descrip'], 'price' => $v['price'], 'stock' => $v['stock'] + , 'timeStart' => $timeStart, 'sort' => $v['sort'], 'status' => intval($v['status']), 'createTime' => $v['createTime']]; } } $date = ['list' => $list, 'count' => $count]; @@ -72,18 +85,18 @@ class Goods extends BaseController $this->return_json('请输入商品标题'); } $addDate = ['activityId' => $activityId, 'title' => $title, 'price' => $price, 'stock' => $stock, 'sort' => $sort - , 'descrip' => $descrip, 'c_time' => time()]; + , 'descrip' => $descrip, 'createTime' => date('Y-m-d H:i:s')]; $dateRange[0] && $addDate['timeStart'] = $dateRange[0]; $dateRange[1] && $addDate['timeEnd'] = $dateRange[1]; $imgs = []; if ($banner) { - $banner = []; + $imgs_banner = []; foreach ($banner as $v) { - $banner[] = $v['fileUrl']; + $imgs_banner[] = $v['fileUrl']; } - $banner && $imgs['banner'] = $banner; + $imgs_banner && $imgs['banner'] = $imgs_banner; } - $imgs && $addDate['imgs'] = json_encode($imgs, JSON_UNESCAPED_UNICODE); + $imgs && $upDate['imgs'] = json_encode($imgs, JSON_UNESCAPED_UNICODE); $id = $this->mdSyliveItems->add($addDate); if (!$id) { $this->return_json('添加商品失败'); @@ -98,6 +111,35 @@ class Goods extends BaseController */ public function index_put() { + $itemId = intval($this->input_param('itemId')); + $title = $this->input_param('title'); + $banner = $this->input_param('banner'); + $descrip = $this->input_param('descrip'); + $price = $this->input_param('price'); + $stock = $this->input_param('stock'); + $sort = $this->input_param('sort'); + $dateRange = $this->input_param('dateRange'); + if (!$itemId) { + $this->return_json('参数错误'); + } + if (!$title) { + $this->return_json('请输入商品标题'); + } + $upDate = ['title' => $title, 'price' => $price, 'stock' => $stock, 'sort' => $sort + , 'descrip' => $descrip]; + $dateRange[0] && $addDate['timeStart'] = $dateRange[0]; + $dateRange[1] && $addDate['timeEnd'] = $dateRange[1]; + $imgs = []; + if ($banner) { + $imgs_banner = []; + foreach ($banner as $v) { + $imgs_banner[] = $v['fileUrl']; + } + $imgs_banner && $imgs['banner'] = $imgs_banner; + } + $imgs && $upDate['imgs'] = json_encode($imgs, JSON_UNESCAPED_UNICODE); + $this->mdSyliveItems->update($upDate, ['itemId' => $itemId]); + $this->return_response(); } /** @@ -111,7 +153,7 @@ class Goods extends BaseController if (!$id) { $this->return_json('参数错误'); } - $this->mdSyliveItems->update(['status' => -1], ['id' => $id]); + $this->mdSyliveItems->update(['status' => -1], ['itemId' => $id]); $this->return_response(); } @@ -128,9 +170,25 @@ class Goods extends BaseController } $str_ids = implode(',', $ids); if ($str_ids) { - $this->mdSyliveItems->update(['status' => -1], ["id in($str_ids)" => null]); + $this->mdSyliveItems->update(['status' => -1], ["itemId in($str_ids)" => null]); } $this->return_response(); } + /** + * Notes:修改状态 + * Created on: 2022/9/8 16:10 + * Created by: dengbw + */ + public function status_put() + { + $itemId = intval($this->input_param('itemId')); + $status = $this->input_param('status'); + if (!$itemId) { + $this->return_json('参数错误'); + } + $this->mdSyliveItems->update(['status' => $status], ['itemId' => $itemId]); + $this->return_response(); + } + } \ No newline at end of file diff --git a/market/controllers/api/sylive/Order.php b/market/controllers/api/sylive/Order.php index 6b38ad58..e4f84229 100644 --- a/market/controllers/api/sylive/Order.php +++ b/market/controllers/api/sylive/Order.php @@ -15,30 +15,59 @@ class Order extends BaseController parent::__construct(); $this->load->model('market/Market_sylive_order_model', 'mdSyliveOrder'); $this->load->model('market/Market_sylive_user_model', 'mdSyliveUser'); + $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_kpidata_model', 'mdSyliveActivityKpidata'); } /** * Notes:订单管理列表 - * Created on: 2022/9/20 14:48 + * Created on: 2022/11/08 14:48 * Created by: dengbw */ public function page_get() { - $page = $this->input_param('page'); - $limit = $this->input_param('limit'); - $itemTitle = $this->input_param('itemTitle'); - $mobile = $this->input_param('mobile'); - $name = $this->input_param('name'); - $status = $this->input_param('status'); - $sid = $this->input_param('sid'); - $sort = $this->input_param('sort'); - $order = $this->input_param('order'); + $date = $this->orderList($this->inputs); + $this->return_response_list($date); + } + + /** + * Notes:导出订单数据 + * Created on: 2022/11/08 15:26 + * Created by: dengbw + */ + public function export_get() + { + $this->inputs['page'] = 1; + $this->inputs['limit'] = 10000; + $date = $this->orderList($this->inputs); + $this->return_response_list($date); + } + + private function orderList($params) + { + $activityId = intval($params['activityId']); + $page = $params['page']; + $limit = $params['limit']; + $uname = $params['uname']; + $mobile = $params['mobile']; + $status = $params['status']; + $cfrom = $params['cfrom']; + $type = $params['type']; + $sort = $params['sort']; + $order = $params['order']; + $bizId = $params['bizId']; + $teamId = $params['teamId']; !$page && $page = 1; !$limit && $limit = 10; $sort_order = 'id desc'; if ($sort && $order) { if ($sort == 'statusName') { $sort_order = 'status ' . $order; + } else if ($sort == 'typeName') { + $sort_order = 'type ' . $order; + } else if ($sort == 'cfromName') { + $sort_order = 'cfrom ' . $order; } else { $sort_order = $sort . ' ' . $order; } @@ -48,58 +77,93 @@ class Order extends BaseController $status = 1; } $where['status'] = $status; - $itemTitle && $where['itemTitle'] = $itemTitle; - $sid && $where['sid'] = $sid; - $str_user_ids = 0; - if ($name || $mobile) { - $where_user['status>='] = 0; - $name && $where_user["(uname LIKE '%{$name}%' OR mobile LIKE '%{$name}%')"] = null; - $mobile && $where_user['mobile'] = $mobile; - $res_user = $this->mdSyliveUser->select($where_user, 'userId desc', 0, 0, 'userId'); - $res_user && $str_user_ids = implode(',', array_unique(array_column($res_user, 'userId'))); - $where["u_id in($str_user_ids)"] = null; - } - $count = $this->mdSyliveOrder->count($where); - if ($count) { - $res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit); - $str_user_ids = implode(',', array_unique(array_column($res, 'uid'))); - $map_users = $this->mdSyliveUser->map('userId', 'uname,nickname,mobile', ["userId in({$str_user_ids})" => null]); - foreach ($res as $v) { - $name = $map_users[$v['uid']]['uname'] ? $map_users[$v['uid']]['uname'] : $map_users[$v['uid']]['nickname']; - $mobile = $map_users[$v['uid']]['mobile']; - $list[] = [ - 'id' => $v['id'], 'sid' => $v['sid'],'name' => $name, 'mobile' => $mobile, 'itemTitle' => $v['itemTitle'] - , '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']]; + $activityId && $where['itemId'] = $activityId; + $uname && $where['uname LIKE "%' . trim($uname) . '%"'] = null; + $mobile && $where['mobile LIKE "%' . trim($mobile) . '%"'] = null; + strlen($cfrom) && $where['cfrom'] = $cfrom; + strlen($type) && $where['type'] = $type; + $cfrom == 1 && $bizId = 0; + if ($bizId) { + $res_org = $this->mdSyliveOrganization->get(["organizationId" => $bizId]); + if ($res_org) { + if ($res_org['organizationType'] == 3) {//门店 + $where['bizId'] = $bizId; + } else if ($res_org['organizationType'] == 2) {//大区 + $where['areaId'] = $bizId; + } + } + } elseif ($teamId) { + $res_team = $this->mdSyliveTeam->get(["teamId" => $bizId]); + if ($res_team) { + if ($res_team['teamType'] == 2) {//团队 + $where['bizId'] = $bizId; + } else if ($res_team['teamType'] == 1) {//总部 + $where['areaId'] = $bizId; + } } } - $date = ['list' => $list, 'count' => $count]; - $this->return_response_list($date); + if ($limit == 10000) { + $count = 1; + } else { + $count = $this->mdSyliveOrder->count($where); + } + if ($count) { + $res = $this->mdSyliveOrder->select($where, $sort_order, $page, $limit); + foreach ($res as $v) { + $consultant = $this->consultantGet(['activityId' => $v['itemId'], 'userId' => $v['userId'] + , 'areaId' => $v['areaId'], 'bizId' => $v['bizId'], 'cfrom' => $v['cfrom'], 'cfUserId' => $v['cfUserId']]); + $list[] = [ + 'id' => $v['id'], 'sid' => $v['sid'], 'uname' => $v['uname'], 'mobile' => $v['mobile'], 'itemTitle' => $v['itemTitle'] + , 'totalPrice' => $v['totalPrice'], 'payTime' => $v['payTime'] != '0000-00-00 00:00:00' ? $v['payTime'] : '' + , 'typeName' => $this->mdSyliveOrder->typeAry($v['type']) + , 'statusName' => $this->mdSyliveOrder->statusAry($v['status']), 'cfromName' => $this->mdSyliveOrder->cfromAry($v['cfrom']) + , 'createTime' => $v['createTime'], 'area' => $consultant['area'], 'stores' => $consultant['stores'], 'consultant' => $consultant['consultant'] + ]; + } + } + if ($limit == 10000) { + return $list; + } else { + return ['list' => $list, 'count' => $count]; + } } /** - * Notes:修改订单 - * Created on: 2022/9/21 14:48 + * Notes:获取顾问信息 + * Created on: 2022/10/8 11:29 * Created by: dengbw + * @param $params + * @return string */ - public function index_put() + private function consultantGet($params) { - $userId = intval($this->input_param('userId')); - $organizationId = intval($this->input_param('organizationId')); - $sex = intval($this->input_param('sex')); - $uname = $this->input_param('uname'); - if (!$userId) { - $this->return_json('参数错误'); + $area = $stores = $consultant = ''; + $areaId = intval($params['areaId']); + $bizId = intval($params['bizId']); + $cfUserId = intval($params['cfUserId']); + if (!$bizId) { + $re = $this->mdSyliveActivityKpidata->get(['activityId' => $params['activityId'], 'userId' => $params['userId'] + , 'type' => $params['cfrom'], 'kpi' => 'order']); + if ($re) { + $areaId = $re['areaId']; + $bizId = $re['bizId']; + $cfUserId = $re['cfUserId']; + } } - if (!$organizationId) { - $this->return_json('请选择所属机构'); + if ($params['cfrom'] == 1) { + $res_teama = $this->mdSyliveTeam->get(["teamId" => $areaId]); + $res_teamb = $this->mdSyliveTeam->get(["teamId" => $bizId]); + $res_teama['teamName'] && $area = $res_teama['teamName']; + $res_teamb['teamName'] && $stores = $res_teamb['teamName']; + } else { + $res_orga = $this->mdSyliveOrganization->get(["organizationId" => $areaId]); + $res_orgb = $this->mdSyliveOrganization->get(["organizationId" => $bizId]); + $res_orga['organizationName'] && $area = $res_orga['organizationName']; + $res_orgb['organizationName'] && $stores = $res_orgb['organizationName']; } - if (!$uname) { - $this->return_json('请输入姓名'); - } - $upDate = ['organizationId' => $organizationId, 'sex' => $sex, 'uname' => $uname]; - $this->mdSyliveOrder->update($upDate, ['userId' => $userId]); - $this->return_response(); + $re_user = $this->mdSyliveUser->get(['userId' => $cfUserId]); + $re_user['uname'] && $consultant = $re_user['uname']; + return ['area' => $area, 'stores' => $stores, 'consultant' => $consultant]; } } \ No newline at end of file