diff --git a/app/manager/controller/UserFollow.php b/app/manager/controller/UserFollow.php new file mode 100644 index 0000000..95f1139 --- /dev/null +++ b/app/manager/controller/UserFollow.php @@ -0,0 +1,308 @@ +getOne(['id' => $this->userinfo['OperaterID']]); + if (!$manager_info['IsRoot']) { + $where['ManagerId'] = $this->userinfo['OperaterID']; + $sort_where['ManagerId'] = $this->userinfo['OperaterID']; + $cost_where .= " ManagerId=" . $this->userinfo['OperaterID'] . ' '; + } + + if (isset($_GET['PageIndex'])) { + $page = ($_GET['PageIndex'] - 1) * 50; + } + if (isset($_GET['search'])) { + $search = $_GET['search']; + if (!empty($search['profile'])) { + $where['follow_status'] = $search['profile']; + } + if (!empty($search['keyWord'])) { + $where['LoginCode'] = ['like', '%' . $search['keyWord'] . '%']; + } + $flag = date("d", time()) == date("t", time()); + $date1 = date("Y-m-01", strtotime("-1 month")); + $date2 = $flag ? date("Y-m-t H:i:s", strtotime("-1 month")) : date("Y-m-d H:i:s", strtotime("-1 month")); + $date3 = date("Y-m-01", time()); + $date4 = date("Y-m-d H:i:s", time()); + if (!empty($search['last_month']['s_time'])) { + $date1 = $search['last_month']['s_time']; + $date2 = $search['last_month']['e_time']; + $is_screen = true; + } elseif (!empty($search['new_month']['s_time'])) { + $date3 = $search['new_month']['s_time']; + $date4 = $search['new_month']['e_time']; + $is_screen = true; + } + + //上月 + $time_where1 .= " UpdateTime>='" . $date1 . "' and UpdateTime<='" . $date2 . "' "; + //本月 + $time_where2 .= " UpdateTime>='" . $date3 . "' and UpdateTime<='" . $date4 . "' "; + + if (!empty($search['money1'])) { + $is_screen = true; + switch ($search['cost_type']) { + case 0: + $time_where3 = ''; + break; + case 1: + $time_where3 .= " product_order.UpdateTime>='" . $date1 . "' and product_order.UpdateTime<='" . $date2 . "' "; + break; + case 2: + $time_where3 .= " product_order.UpdateTime>='" . $date3 . "' and product_order.UpdateTime<='" . $date4 . "' "; + break; + } + $cost_where .= "having money >=" . $search['money1'] . " and money <=" . $search['money2'] . ' '; + $user_search_id = $product_order_model->getScreenCost($time_where3, $cost_where, "$page,50"); + } + if (!empty($search['sortLable'])) { + $is_screen = true; + switch ($search['sortLable']) { + case 'all_amount': + $user_search_id = $product_order_model->getSort($sort_where, $search['sortOrder'], "$page,50"); + break; + case 'PrevMonthAmount': + $user_search_id = $product_order_model->getMonthSort($sort_where, $search['sortOrder'], "$page,50"); + break; + case 'MonthAmount': + $user_search_id = $product_order_model->getMonthSort($sort_where, $search['sortOrder'], "$page,50", false); + break; + case 'account_count': + $user_search_id = $product_account_model->getSort($sort_where, $search['sortOrder'], "$page,50", 1); + break; + case 'account_used': + $user_search_id = $product_account_model->getSort($sort_where, $search['sortOrder'], "$page,50", 3); + break; + case 'account_expire': + $user_search_id = $product_account_model->getSort($sort_where, $search['sortOrder'], "$page,50", 2); + break; + } + } + } + + if ($is_screen && empty($user_search_id)) { + \result([ + 'list' => [], + 'count' => 0, + 'types' => [], + ]); + } + + //将筛选出来额的userid进行处理 + if (!empty($user_search_id)) { + foreach ($user_search_id as $v) { + $user_search_id_list[] = $v['UserId']; + } + $where['Id'] = ['in', $user_search_id_list]; + } + $user_list = $user_model->getListPage($where, 'Id,follow_status,LoginCode,CreateTime,Wx,QQ', 'id desc', "$page,50"); + $list = []; + $user_id_list = []; + + //获取用户列表 + foreach ($user_list as $info) { + + $info['last_pay_time'] = '无消费'; + $pay_time = $user_score_model->getNewOne('UpdateTime', ['UserId' => $info['Id'], 'ScoreType' => $user_score_enum::$Pay]); + if ($pay_time) { + $info['last_pay_time'] = $pay_time['UpdateTime']; + } + $info['follow_status'] = $user_enum::$FollowStatus[$info['follow_status']]; + $info['UserName'] = substr($info['LoginCode'], 0, 3) . '***' . substr($info['LoginCode'], -3); + $info['all_amount'] = 0; + $info['PrevMonthAmount'] = 0; + $info['MonthAmount'] = 0; + $info['AddAmount'] = 0; + $info['persent'] = '0%'; + $info['account_count'] = 0; + $info['account_used'] = 0; + $info['account_expire'] = 0; + $list[$info['Id']] = $info; + $user_id_list[] = $info['Id']; + } + //获取总消费金额 + $all_cost = $product_order_model->getAllCost($user_id_list); + foreach ($all_cost as $info) { + $list[$info['UserId']]['all_amount'] = $info['money']; + } + //获取上一个月、本月消费 + $last_month_cost = $product_order_model->getPreMonthCost($user_id_list, $time_where1); + $new_month_cost = $product_order_model->getPreMonthCost($user_id_list, $time_where2); + foreach ($last_month_cost as $info) { + $list[$info['UserId']]['PrevMonthAmount'] = $info['money']; + $list[$info['UserId']]['AddAmount'] = -$info['money']; + } + //消费统计比对 + foreach ($new_month_cost as $info) { + $list[$info['UserId']]['MonthAmount'] = $info['money']; + $list[$info['UserId']]['AddAmount'] = $info['money'] - $list[$info['UserId']]['PrevMonthAmount']; + if ($list[$info['UserId']]['PrevMonthAmount'] != 0) { + $list[$info['UserId']]['persent'] = round(($info['money'] - $list[$info['UserId']]['PrevMonthAmount']) / $list[$info['UserId']]['PrevMonthAmount'] * 100, 2) . '%'; + } else { + $list[$info['UserId']]['persent'] = '100%'; + } + } + //帐号计算 + $account_use_where = ['DeleteTag' => 0, 'UserID' => ['in', $user_id_list], 'EndTime' => ['>', date('Y-m-d H:i:s')], 'AccountType' => ['<>', $product_account_enum::$Test]]; + $account_expire_where = ['DeleteTag' => 0, 'UserID' => ['in', $user_id_list], 'EndTime' => ['<=', date('Y-m-d H:i:s')], 'AccountType' => ['<>', $product_account_enum::$Test]]; + $account_used = $product_account_model->getUesdAccount($account_use_where); + $account_expire = $product_account_model->getUesdAccount($account_expire_where); + foreach ($account_used as $info) { + $list[$info['UserId']]['account_used'] = $info['used_count']; + } + foreach ($account_expire as $info) { + $list[$info['UserId']]['account_expire'] = $info['used_count']; + $list[$info['UserId']]['account_count'] = $info['used_count'] + $list[$info['UserId']]['account_used']; + } + + if (!empty($search['sortLable'])) { + $sort = $search['sortOrder'] ? SORT_ASC : SORT_DESC; + $field = array_column($list, $search['sortLable']); + array_multisort($field, $sort, $list); + } + + $data = [ + 'list' => array_merge($list), + 'count' => $user_model->getCount($where)['count'], + 'types' => $user_enum->getFormatList($user_enum::$FollowStatus), + ]; + \result($data); + } + + /** + * @description: 获取跟进记录 + * @param {*} + * @return {*} + */ + public function getFollowRecord() + { + if (!isset($_GET['id'])) { + die; + } + $id = $_GET['id']; + $follow_rcord = new FollowRecord; + $list = $follow_rcord->getNewRecord(['user_id' => $id]); + \result($list); + } + + /** + * @description: 更改跟进状态 + * @param {*} + * @return {*} + */ + public function changeFolowStatus() + { + $data = json_decode(file_get_contents("php://input"), true)['data']; + $follow_rcord = new FollowRecord; + $user_model = new User; + $user_enum = new UserEnum; + if ($user_model->updateOne(['Id' => $data['user_id']], ['follow_status' => $data['status']])) { + $info = []; + $info['user_id'] = $data['user_id']; + $info['op_user'] = $this->userinfo['OperaterID']; + $info['record'] = $data['old_status'] . '=>' . $user_enum::$FollowStatus[$data['status']]; + $info['remark'] = $data['remark']; + $follow_rcord->add($info); + } + \result(); + } + + /** + * @description: 获取用户信息 + * @param {*} + * @return {*} + */ + public function getUserInfo() + { + if (!isset($_GET['id'])) { + die; + } + $id = $_GET['id']; + $user_model = new User; + \result($user_model->getOne(['Id' => $id], 'LoginCode as UserName,Wx,QQ')); + } + + /** + * @description: 获取用户消费记录 + * @param {*} + * @return {*} + */ + public function getCostList() + { + if (!isset($_GET['id'])) { + die; + } + $id = $_GET['id']; + $index = $_GET['index']; + $user_score_model = new UserScore; + \result($user_score_model->getUserCost($id, $index)); + } + + /** + * @description: 获取用户帐号 + * @param {*} + * @return {*} + */ + public function getAccountList() + { + if (!isset($_GET['id'])) { + die; + } + $id = $_GET['id']; + $index = $_GET['index']; + $product_account_model = new ProductAccount; + \result($product_account_model->getUserAccount($id, $index)); + } +} diff --git a/app/manager/model/FollowRecord.php b/app/manager/model/FollowRecord.php new file mode 100644 index 0000000..df196c1 --- /dev/null +++ b/app/manager/model/FollowRecord.php @@ -0,0 +1,23 @@ +where($where)->order()->limit('3')->fetchAll(); + } +} diff --git a/app/manager/model/ProductAccount.php b/app/manager/model/ProductAccount.php new file mode 100644 index 0000000..8f69dee --- /dev/null +++ b/app/manager/model/ProductAccount.php @@ -0,0 +1,91 @@ +field('UserId, sum(ConnectCount) used_count')->where($where)->group(['UserId'])->fetchAll(); + } + + /** + * @description: 获取用户帐号信息 + * @param {*} + * @return {*} + */ + public function getUserAccount($user_id, $index) + { + $product_account_enum = new ProductAccountEnum; + $where = []; + $wheres = []; + switch($index){ + case 1: + $where = ['DeleteTag' => 0, 'AccountType' => ['<>', $product_account_enum::$Test]]; + break; + case 2: + $where = ['DeleteTag' => 0, 'EndTime' => ['>', date('Y-m-d H:i:s')], 'AccountType' => ['<>', $product_account_enum::$Test]]; + break; + case 3: + $where = ['DeleteTag' => 0, 'EndTime' => ['<=', date('Y-m-d H:i:s')], 'AccountType' => ['<>', $product_account_enum::$Test]]; + break; + } + return $this->field('ProductName,PackageName,Account,StartTime,EndTime,UpdateTime') + ->where(['UserId' => $user_id]) + ->where($where) + ->order('Id desc') + ->fetchAll(); + } + + /** + * @description: 按照排序条件进行查询 + * @param {*} + * @return {*} + */ + public function getSort($where = [],$order = 1, $limit = '50',$index) + { + $order_type = 'account_count'; + if($order == '0'){ + $order_type = 'account_count desc'; + } + $product_account_enum = new ProductAccountEnum; + $wheres = []; + switch($index){ + case 1: + $wheres = "product_account.DeleteTag=0 and AccountType<>".$product_account_enum::$Test; + break; + case 2: + $wheres = "product_account.DeleteTag=0 and AccountType<>".$product_account_enum::$Test." and product_account.EndTime>'".date('Y-m-d H:i:s')."'"; + break; + case 3: + $wheres = "product_account.DeleteTag=0 and AccountType<>".$product_account_enum::$Test." and product_account.EndTime<='".date('Y-m-d H:i:s')."'"; + break; + } + return $this->field('product_account.UserId,sum(product_account.ConnectCount) account_count') + ->join('user ON product_account.UserId=user.Id') + ->where($where) + ->where($wheres) + ->group(['product_account.UserId']) + ->order($order_type) + ->limit($limit) + ->fetchAll(); + } +} diff --git a/app/manager/model/ProductOrder.php b/app/manager/model/ProductOrder.php index 8156eba..8bcc922 100644 --- a/app/manager/model/ProductOrder.php +++ b/app/manager/model/ProductOrder.php @@ -1,17 +1,17 @@ field('UserId,sum(PaymentAmount) as money') - ->where(['OrderState'=>['in',ProductOrderEnum::$PayComplete]]) - ->group(['UserId']) - ->order('money') - ->fetchAll(); + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]]) + ->group(['UserId']) + ->order('money') + ->fetchAll(); } /** @@ -35,30 +36,141 @@ class ProductOrder extends Model * @param {*} * @return {*} */ - public function getMonthCost($user_id){ + public function getMonthCost($user_id) + { $last_month = date("Y-m-d H:i:s", strtotime("-1 month")); $new_month = date("Y-m-d H:i:s", time()); return $this->field('UserId,sum(PaymentAmount) as money') - ->where(['OrderState'=>['in',ProductOrderEnum::$PayComplete],'UpdateTime' => ['<', $new_month]]) - ->where(['UpdateTime' => ['>', $last_month]]) - ->where(['UserId' => ['in',$user_id]]) - ->group(['UserId']) - ->order('money') - ->fetchAll(); + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete], 'UpdateTime' => ['<', $new_month]]) + ->where(['UpdateTime' => ['>', $last_month]]) + ->where(['UserId' => ['in', $user_id]]) + ->group(['UserId']) + ->order('money') + ->fetchAll(); } /** - * @description: 获取所有支付成功用户近一个月在筛选范围的支付总金额 + * @description: 获取所有支付成功用户的支付总金额 * @param {*} * @return {*} */ - public function getScreenMonthCost($screen){ + public function getAllCost($user_id) + { + return $this->field('UserId,sum(PaymentAmount) as money') + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]]) + ->where(['UserId' => ['in', $user_id]]) + ->group(['UserId']) + ->fetchAll(); + } + + /** + * @description: 获取所有支付成功用户上一个月在筛选范围的支付总金额 + * @param {*} + * @return {*} + */ + public function getScreenMonthCost($screen) + { $last_month = date("Y-m-01", strtotime("-1 month")); $new_month = date("Y-m-t", strtotime("-1 month")); return $this->field('UserId,sum(PaymentAmount) as money') - ->where(['OrderState'=>['in',ProductOrderEnum::$PayComplete],'UpdateTime' => ['<', $new_month]]) - ->where(['UpdateTime' => ['>', $last_month]]) - ->group(['UserId'],'having money>'.$screen['money1'].' and money<'.$screen['money2']) - ->fetchAll(); + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete], 'UpdateTime' => ['<', $new_month]]) + ->where(['UpdateTime' => ['>', $last_month]]) + ->group(['UserId'], 'having money>' . $screen['money1'] . ' and money<' . $screen['money2']) + ->fetchAll(); + } + + /** + * @description: 获取所有支付成功用户上一个月或者本月支付金额 + * @param {*} flag = true 上一个月 + * @return {*} false 本月 + */ + public function getPreMonthCost($user_id, $where) + { + return $this->field('UserId,sum(PaymentAmount) as money') + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]]) + ->where($where) + ->where(['UserId' => ['in', $user_id]]) + ->group(['UserId']) + ->order('money') + ->fetchAll(); + } + + /** + * @description: 获取用户所有的帐号记录 + * @param {*} + * @return {*} + */ + public function getUserAccount($user_id) + { + return $this->field('UserName,ProductName,PackageName,PaymentAmount,Accounts,UpdateTime') + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete], 'UserId' => $user_id]) + ->order('Id desc') + ->fetchAll(); + } + + /** + * @description: 按照排序条件进行查询 + * @param {*} + * @return {*} + */ + public function getSort($where = [],$order = 1, $limit = '50') + { + $order_type = 'money'; + if($order == '0'){ + $order_type = 'money desc'; + } + return $this->field('product_order.UserId,sum(product_order.PaymentAmount) as money') + ->join('user ON product_order.UserId=user.Id') + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]]) + ->where($where) + ->group(['product_order.UserId']) + ->order($order_type) + ->limit($limit) + ->fetchAll(); + } + + /** + * @description: 按照排序条件进行查询上一个月或者本月支付金额 + * @param {*} flag = true 上一个月 + * @return {*} flag = false 本月 + */ + public function getMonthSort($where = [],$order = 1, $limit = '50', $flag = true) + { + $order_type = 'money'; + if($order == '0'){ + $order_type = 'money desc'; + } + if ($flag) { + $last_month = date("Y-m-01 H:i:s", strtotime("-1 month")); + $new_month = date("Y-m-t H:i:s", strtotime("-1 month")); + } else { + $last_month = date("Y-m-01 H:i:s", time()); + $new_month = date("Y-m-d H:i:s", time()); + } + return $this->field('product_order.UserId,sum(product_order.PaymentAmount) as money') + ->join('user ON product_order.UserId=user.Id') + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]]) + ->where($where) + ->where("product_order.UpdateTime >'".$last_month."'") + ->where("product_order.UpdateTime <'".$new_month."'") + ->group(['product_order.UserId']) + ->order($order_type) + ->limit($limit) + ->fetchAll(); + } + + /** + * @description: 获取所有支付成功用户筛选金额 + * @param {*} + * @return {*} + */ + public function getScreenCost($where,$having, $limit = '50') + { + return $this->field('UserId,sum(PaymentAmount) as money') + ->join('user ON product_order.UserId=user.Id') + ->where(['OrderState' => ['in', ProductOrderEnum::$PayComplete]]) + ->where($where) + ->group(['UserId'],$having) + ->fetchAll(); } } diff --git a/app/manager/model/User.php b/app/manager/model/User.php index 098cd68..559d155 100644 --- a/app/manager/model/User.php +++ b/app/manager/model/User.php @@ -4,8 +4,8 @@ * @version: * @Author: kangkang * @Date: 2020-10-16 14:44:02 - * @LastEditors: kangkang - * @LastEditTime: 2020-11-16 15:22:30 + * @LastEditors: Please set LastEditors + * @LastEditTime: 2020-11-20 15:59:59 */ namespace app\manager\model; @@ -26,6 +26,16 @@ class User extends Model return $this->field('ManagerId,ManagerName,count(1) as count_num')->group(['ManagerId'])->fetchAll(); } + /** + * @description: 获取所有客户经理客户 + * @param {*} + * @return {*} + */ + public function getAllManagerUser($where = []) + { + return $this->field('Id,CreateTime')->where($where)->fetchAll(); + } + /** * @description: 查询符合筛选条件的所有用户数量 * @param {*} @@ -36,7 +46,13 @@ class User extends Model return $this->field('ManagerId,ManagerName,count(1) as count_num')->where($where)->group(['ManagerId'])->fetchAll(); } - public function setManager($where,$data,$limit){ + /** + * @description: 为客户经理分配用户 + * @param {*} + * @return {*} + */ + public function setManager($where, $data, $limit) + { return $this->where($where)->limit($limit)->update($data); } diff --git a/app/manager/model/UserScore.php b/app/manager/model/UserScore.php new file mode 100644 index 0000000..b022a63 --- /dev/null +++ b/app/manager/model/UserScore.php @@ -0,0 +1,49 @@ +',$last_month]; + break; + case 3: + $last_month = date("Y-m-01 H:i:s", time()); + $new_month = date("Y-m-d H:i:s", time()); + $where['UpdateTime'] = ['<',$new_month]; + $wheres['UpdateTime'] = ['>',$last_month]; + break; + } + return $this->field('ScoreTypeName,ScoreValue,RestAmount1,RestAmount2,UpdateTime') + ->where(['UserId' => $user_id]) + ->where($where) + ->where($wheres) + ->order('Id desc') + ->fetchAll(); + } +} diff --git a/enum/account/ProductAccount.php b/enum/account/ProductAccount.php new file mode 100644 index 0000000..4818f1a --- /dev/null +++ b/enum/account/ProductAccount.php @@ -0,0 +1,29 @@ + '新开', + 2 => '批量新开', + 3 => '续费', + 4 => '批量续费', + 100 => '原系统认证', + 200 => '测试账号' + ]; + + public static $New = 1; + public static $News = 2; + public static $AgainBuy = 3; + public static $AgainBuys = 4; + public static $Origin = 100; + public static $Test = 200; +} diff --git a/enum/user/User.php b/enum/user/User.php index 6a6ae9e..adb9eb3 100644 --- a/enum/user/User.php +++ b/enum/user/User.php @@ -5,7 +5,7 @@ * @Author: kangkang * @Date: 2020-10-22 15:35:49 * @LastEditors: kangkang - * @LastEditTime: 2020-11-16 11:42:15 + * @LastEditTime: 2020-11-18 17:38:12 */ namespace enum\user; @@ -26,6 +26,11 @@ class User 11 => '已完成', ]; + /** + * @description: 格式化方便选择处理 + * @param {*} + * @return {*} + */ public static function getFormatList($arr) { $format_list = []; @@ -37,4 +42,15 @@ class User return $format_list; } + /** + * @description: 通过值获取状态 + * @param {*} + * @return {*} + */ + public static function getStatusByName($arr,$str) + { + $data = array_flip($arr); + return $data[$str]; + } + }