whereLike('consignee',$get['name'])->find(); $where[] = ['user_id','=',$phone['user_id']]; } //注册时间 if(isset($get['start_time']) && $get['start_time']!=''){ $where[] = ['create_time','>=',strtotime($get['start_time'])]; } if(isset($get['end_time']) && $get['end_time']!=''){ $where[] = ['create_time','<=',strtotime($get['end_time'])]; } $user_count = Db::name('user_address') ->where($where) ->where('admin_id',0) ->field('password,pay_password,salt',true) ->order('id desc') ->count(); $user_list = Db::name('user_address') ->where($where) ->where('admin_id',0) ->field('password,pay_password,salt',true) ->page($get['page'],$get['limit']) ->order('id desc') ->select(); foreach($user_list as &$item){ $staff=Db::name('admin')->where('id',$item['admin_id'])->find(); if($staff){ $item['name']= $staff['name']; } $item['qudao']=Db::name('staffchannel')->where('id', $item['brand_id'])->column('name'); $custom=Db::name('custom')->where('custom_id',$item['id'])->order('id desc')->find(); $item['custom']=Db::name('custom')->where('custom_id', $item['id'])->order('id desc')->limit(1)->column('connect'); if($custom){ $item['create_timess']=date("Y年m月d日 H:i",$custom['create_time']); }else{ $item['create_timess']="-"; } } return ['count'=>$user_count , 'lists'=>$user_list]; } /** * 我的客户列表 * @param $get * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function userlist($get){ $where = []; $where[] = ['admin_id', '=', session('admin_info.id')]; if(isset($get['id']) && $get['id'] != ''){ $where[] = ['id','=',$get['id']]; } //根据客户电话查询 if(isset($get['phone']) && $get['phone'] != ''){ $where[] = ['telephone', 'like', '%' . $get['phone'] . '%']; } //根据客户姓名查询 if(isset($get['name']) && $get['name'] != ''){ $where[] = ['contact', 'like', '%' . $get['name'] . '%']; } if(isset($get['area']) && $get['area'] != ''){ $where[] = ['district_id','=',$get['area']]; } //客户标签检索 if(isset($get['label_id']) && $get['label_id'] != ''){ $where[] = ['label_id','=',$get['label_id']]; } //根据客户的时间去查询内容 if(isset($get['pet']) && $get['pet'] != ''){ $where[] = ['pet','=',$get['pet']]; } if(isset($get['hbl']) && $get['hbl'] != ''){ $where[] = ['hbl','=',$get['hbl']]; } //注册时间 if(isset($get['start_time']) && $get['start_time']!=''){ $where[] = ['createtime','>=',strtotime($get['start_time'])]; } if(isset($get['end_time']) && $get['end_time']!=''){ $where[] = ['createtime','<=',strtotime($get['end_time'])]; } $user_count = Db::name('user_address') ->where($where) ->field('password,pay_password,salt',true) ->order('id desc') ->count(); $user_list = Db::name('user_address') ->where($where) ->field('password,pay_password,salt',true) ->page($get['page'],$get['limit']) ->order('id desc') ->select(); foreach ($user_list as &$item){ //跟进人信息 $staff=Db::name('admin')->where('id',$item['admin_id'])->find(); $item['name']= $staff['name']; $custom=Db::name('custom')->where('admin_id',$item['admin_id'])->order('id desc')->find(); if($custom){ $item['create_time']=date("Y年m月d日 H:i",$custom['create_time']); } $item['qudao']=Db::name('staffchannel')->where('id', $item['brand_id'])->column('name'); $staff=Db::name('admin')->where('id',$item['admin_id'])->find(); $item['name']= $staff['name']; $item['qudao']=Db::name('staffchannel')->where('id', $item['brand_id'])->column('name'); $custom=Db::name('custom')->where('custom_id',$item['id'])->order('id desc')->find(); $item['custom']=Db::name('custom')->where('custom_id', $item['id'])->order('id desc')->limit(1)->column('connect'); if($custom){ $item['create_timess']=date("Y年m月d日 H:i",$custom['create_time']); }else{ $item['create_timess']="-"; } $label=Db::name('user_label')->where('id',$item['label_id'])->find(); if($label){ $item['user_label']=$label['name']; }else{ $item['user_label']='-'; } } return ['count'=>$user_count , 'lists'=>$user_list]; } /** * Notes: 订单备注 * @param $post * @param string $type * @return int|string * @throws \think\Exception * @throws \think\exception\PDOException * @author 张无忌(2021/2/1 18:50) */ public static function user_remarks($post, $type="get") { if ($type==='get') { return Db::name('user_address')->field('id,user_remarks') ->where(['id'=>$post['id']]) ->findOrEmpty(); } else { return Db::name('user_address') ->where(['id'=>$post['id']]) ->update(['user_remarks'=>$post['user_remarks']]); } } /** * Notes: 管理员备注 * @param $post * @param string $type * @return int|string * @throws \think\Exception * @throws \think\exception\PDOException * @author 张无忌(2021/2/1 18:50) */ public static function admin_remarks($post, $type="get") { if ($type==='get') { return Db::name('user_address')->field('id,admin_remarks') ->where(['id'=>$post['id']]) ->findOrEmpty(); } else { return Db::name('user_address') ->where(['id'=>$post['id']]) ->update(['admin_remarks'=>$post['admin_remarks']]); } } /** * Notes: 保洁师备注信息 * @param $post * @param string $type * @return int|string * @throws \think\Exception * @throws \think\exception\PDOException * @author 杨左(2021/2/1 18:50) */ public static function staff_remarks($post, $type="get") { if ($type==='get') { return Db::name('user_address')->field('id,staff_remarks') ->where(['id'=>$post['id']]) ->findOrEmpty(); } else { return Db::name('user_address') ->where(['id'=>$post['id']]) ->update(['staff_remarks'=>$post['staff_remarks']]); } } //客户档案的编辑 public static function edit($post){ $data=[ 'contact' =>$post['name'], 'telephone' =>$post['phone'], 'sex' =>$post['sex'], 'province_id' =>$post['first_category_id'], 'city_id' =>$post['second_category_id'], 'district_id' =>$post['third_category_id'], 'lng' =>$post['store_latitude'], 'lat' =>$post['store_longitude'], 'areas' =>$post['areas'], 'brand_id' =>$post['brand_id'], 'pet' =>$post['pet'], 'hbl' =>$post['hbl'], 'address' =>$post['address'], 'admin_id' =>session('admin_info.id'), 'updatetime' =>time(), 'createtime' =>time(), ]; return Db::name('user_address')->where('id',$post['id'])->data($data)->update(); } /** * order: 哆啦猫客户来源渠道 * Desc: 查询分类列表 */ public static function info($id) { return Db::name('staffchannel')->where('id',$id)->find(); } /** * order: 哆啦猫客户来源渠道 * Desc: 客户的渠道列表查询 */ public static function infolist(){ return Db::name('staffchannel')->where('deletetime','NULL')->select(); } public static function ordertypeedit($post){ $now = time(); $data['createtime'] = $now; $data['updatetime'] = $now; $data['name']=$post['name']; $data['sort']=$post['sort']; $data['pid']=$post['pid']; return Db::name('staffchannel') ->where('id',$post['id']) ->update($data); } //查看客户档案的信息 public static function getCustom($id,$getdata = false,$expenditure = false){ $custom = Db::name('user_address')->where('id',$id)->find(); //获取客户的基本信息 if($custom){ $user=Db::name('user')->where('id',$custom['user_id'])->find(); if($user){ $custom['abs_avatar'] = UrlServer::getFileUrl($user['avatar']); $custom['birthday'] = date('Y-m-d',$user['birthday']); $custom['nickname']=$user['nickname']; }else{ $custom['nickname']='-'; $custom['birthday'] ='-'; $custom['abs_avatar'] ='-'; } } if($expenditure){ //本月的消费金额 $month_amount = Db::name('order') ->where(['mobile'=>$custom['telephone'],'pay_status'=>Pay::ISPAID]) ->whereTime('create_time', 'month') ->sum('order_amount'); //本月的订单笔数 $month_num = Db::name('order') ->where(['mobile'=>$custom['telephone'],'pay_status'=>Pay::ISPAID]) ->whereTime('create_time', 'month') ->count(); $month_number = Db::name('order') ->where(['mobile'=>$custom['telephone'],'pay_status'=>Pay::ISPAID]) ->sum('order_amount'); //累计消费笔数 $total_num =Db::name('order') ->where(['mobile'=>$custom['telephone'],'pay_status'=>Pay::ISPAID]) ->sum('order_amount'); $avg_amount = Db::name('order') ->where(['mobile'=>$custom['telephone'],'pay_status'=>Pay::ISPAID]) ->avg('order_amount'); $custom['month_amount'] = '¥'.round($month_amount,2); $custom['month_num'] = round($month_num,2); $custom['total_num'] = round($total_num,2); $custom['total_order_amount']=$month_number; $custom['avg_amount'] = '¥'.round($avg_amount,2); } return $custom; //档案下单页面 } public static function Customlist($get){ switch ($get['type']){ case 0://下单明细 $custom=Db::name('user_address')->where('id',$get['user_id'])->find(); $count = Db::name('order')->alias('o') ->where(['mobile'=>$custom['telephone']]) ->where('order_status','not in',[Order::STATUS_CLOSE,Order::STATUS_WAIT_PAY]) ->count(); $list =Db::name('order')->alias('o') ->where(['mobile'=>$custom['telephone']]) ->page($get['page'],$get['limit']) ->order('id desc') ->field('o.id,order_sn,total_num,pay_time,total_amount,order_amount,discount_amount, o.create_time,consignee,province,city,district,o.address,mobile,code,number') ->select(); foreach ($list as &$item) { $item['total_nums']='1'; $item['create_time']=date("Y-m-d H:i:s",$item['create_time']); $item['code_number']=$item['number']-$item['code']; //计算待服务次数 $item['codes_number']=$item['number']-$item['code_number']; //计算已服务次数 } break; case 1://积分明细 $account_log =new AccountLog(); $count = $account_log ->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::integral_change]) ->count(); $list = $account_log ->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::integral_change]) ->page($get['page'],$get['limit']) ->order('id desc') ->select(); break; case 2://签到明细 $account_log =new AccountLog(); $count = $account_log ->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::sign_in_integral]) ->count(); $list = $account_log ->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::sign_in_integral]) ->page($get['page'],$get['limit']) ->order('id desc') ->select(); break; case 3://余额明细 $account_log = new AccountLog(); $count = $account_log ->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::money_change]) ->count(); $list = $account_log ->where(['user_id'=>$get['user_id'],'source_type'=>AccountLog::money_change]) ->page($get['page'],$get['limit']) ->order('id desc') ->select(); break; case 4://推广明细 $count = 1; $first_leader = Db::name('user')->where(['id'=>$get['user_id']])->value('first_leader'); $list = []; if($first_leader){ $user = new User(); $list = $user ->where(['id'=>$first_leader]) ->field('id,sn,nickname,mobile,avatar,level,sex,create_time,total_order_amount,user_money,user_integral') ->order('id desc') ->select(); $level_list = Db::name('user_level')->where(['del'=>0])->column('name','id'); foreach ($list as &$item) { $item['avatar'] = UrlServer::getFileUrl($item['avatar']); $item['level_name'] = '-'; if(isset($level_list[$item['level']])){ $item['level_name'] = $level_list[$item['level']]; } } } break; case 5://房屋的地址 $count = Db::name('user_address') ->where(['user_id'=>$get['user_id'],'del'=>0]) ->count(); $list = Db::name('user_address') ->where(['user_id'=>$get['user_id'],'del'=>0]) ->order('id desc') ->select(); break; case 6://投诉建议的内容 $count = Db::name('user_report') ->where(['user_id'=>$get['user_id']]) ->count(); $list = Db::name('user_report') ->where(['user_id'=>$get['user_id']]) ->order('id desc') ->select(); foreach ($list as &$item){ $item['create_time']=date("Y-m-d H:i:s",$item['create_time']); } break; case 7://回访记录 $count = Db::name('user_follow') ->where(['user_id'=>$get['user_id']]) ->count(); $list = Db::name('user_follow') ->where(['user_id'=>$get['user_id']]) ->order('id desc') ->select(); foreach ($list as &$item){ $item['create_time']=date("Y-m-d H:i:s",$item['create_time']); $staff=Db::name('staff')->where('id',$item['staff_id'])->find(); $item['name']=$staff['name']; $item['phone']=$staff['mobile']; } break; } return ['count'=>$count , 'lists'=>$list]; } //删除客户的档案 public static function del($post){ return Db::name('user_address')->where('id',$post['id'])->delete(); } //客户来源渠道 public static function staff_channel(){ $lists = Db::name('staffchannel') ->where('deletetime','NULL') ->order(['sort' => 'desc', 'id' => 'asc']) ->select(); $pids = Db::name('staffchannel') ->column('pid'); foreach ($lists as &$item){ $item['createtime']=date("Y-m-d H:i:s",$item['createtime']); $item['updatetime']=date("Y-m-d H:i:s",$item['updatetime']); } return linear_to_tree($lists); } /** * order: 客户来源列表 * Desc: 现实客户渠道来源列表 */ public static function Menu($id =1){ $lists = Db::name('staffchannel') ->where('deletetime','NULL') ->select(); if ($id) { $remove_ids = self::getChildIds($lists, $id); $remove_ids[] = $id; foreach ($lists as $key => $row) { if (in_array($row['id'], $remove_ids)) { unset($lists[$key]); } } $lists = array_values($lists); } return multilevel_linear_sort($lists, '|-'); } private static function getChildIds($lists, $id) { $ids = []; foreach ($lists as $key => $row) { if ($row['pid'] == $id) { $ids[] = $row['id']; $child_ids = self::getChildIds($lists, $row['id']); foreach ($child_ids as $child_id) { $ids[] = $child_id; } } } return $ids; } public static function channel_add($post){ $now = time(); $data['createtime'] = $now; $data['updatetime'] = $now; $data['name']=$post['name']; $data['sort']=$post['sort']; $data['pid']=$post['pid']; $datas = Db::name('staffchannel')->insertGetId($data); return $datas; } }