request->token; $sign = UserSignLog::where([['user_id', '=', $token['uid']], ['date', '=', date('Y-m-d')], ['root_id', '=', $token['root_org']]])->find(); if ($sign) { return json(['code' => self::error_msg, 'msg' => '签到失败,请勿重复签到']); } // 连续签到天数 $day = UserSignLog::where([['user_id', '=', $token['uid']], ['date', '=', date('Y-m-d', strtotime('yesterday'))], ['root_id', '=', $token['root_org']]])->value('day'); $sign = UserSignLog::create([ 'user_id' => $token['uid'], 'date' => date('Y-m-d'), 'day' => $day ? $day + 1 : 1, 'root_id' => $token['root_org'] ]); //累计勋章 Console::call('medal', ['sign', (string)$token['employee_id'], (string)$token['root_org']]); return json(['code' => self::success, 'msg' => '签到成功', 'sign' => $sign->day]); } /** * 用户收藏记录 */ public function collect($page, $limit) { $data = UserCollect::with(['content'])->where('user_id', $this->request->token['uid'])->order('addtime desc') // ->page($page,$limit) ->select()->toArray(); $data = array_filter($data, function ($v) { if (isset($v['content']['del']) && $v['content']['del'] == 0) { return true; } elseif (isset($v['content']['delete_time']) && $v['content']['delete_time'] == 0) { return true; } else { return false; } }); $data = array_slice($data, ($page - 1) * $limit, $limit); return json(['code' => self::success, 'data' => $data]); } /* * 获客线索数量 */ public function getCustomerCount() { $conditon = [['employee_id', '=', $this->request->token['employee_id']]]; $total = CustomerClue::where($conditon)->count(); $conditon[] = ['addtime', 'like', date('Y-m-d') . '%']; $today = CustomerClue::where($conditon)->count(); return json(['code' => 0, 'msg' => '获取成功', 'total' => $total, 'today' => $today]); } /** * 线索列表 */ public function customernew($page, $limit, $state = '', $phone = '') { $token = $this->request->token; $condition[] = ['employee_id', '=', $token['employee_id']]; $state === '' ?: setCondition($state, 'state', '=', $condition); // setCondition($means, 'means', 'in', $condition); if ($phone == 'has') $condition[] = ['phone', 'NOTNULL', null]; elseif ($phone == 'hasno') $condition[] = ['phone', 'NULL', null]; $data = CustomerClue::field('id,uid,phone,addtime,updatetime,state')->with(['user'])->withCount(['subscribe' => function ($query) use ($token) { $query->where('root_id', $token['root_org']); }, 'footprints'])->where($condition)->order('updatetime desc')->page($page, $limit)->select(); foreach ($data as $k => $v) { if ($v['nickname'] == '微信用户'){ $data[$k]['nickname'] = '游客'; } $data[$k]['updatetime'] = $v['updatetime'] ? explode(' ', $v['updatetime']) : explode(' ', $v['addtime']); if(empty($v['phone'])){ $v['phone'] = QuoteRecord::where(['employee_id'=>$token['employee_id'], 'uid'=>$v['uid']])->value('phone'); } } return json(['code' => self::success, 'msg' => '获取成功', 'user' => $data]); } //线索详情 public function clue_detail() { $token = $this->request->token; $data = $this->request->only(['id']); $clue_data = CustomerClue::with(['user'])->where([['id', '=', $data['id']], ['employee_id', '=', $token['employee_id']]])->field('id,uid,phone,addtime,updatetime,state')->find(); if (!empty($clue_data)) { return json(['code' => 0, 'msg' => '获取成功', 'data' => $clue_data]); } else { return json(['code' => 1, 'msg' => '获取失败', 'data' => null]); } } /** * 客户访问记录(👣) */ public function footprints($id) { $token = $this->request->token; $clue = CustomerClue::where([['id', '=', $id], ['employee_id', '=', $token['employee_id']]])->find(); if (empty($clue)) return json(['code' => self::success, 'data' => [], 'msg' => '获取成功']); // 查询条件设置 $condition = [ ['addtime', '>=', $clue->addtime], ['uid', '=', $clue->uid], // ['employee_id', '=', $this->request->token['employee_id']], ['org_id', 'in', orgSubIds($token['root_org'])] ]; $data = Footprints::where($condition)->field('id,pipe_type,reg_info,visit_due_time,addtime,uid')->order('addtime desc')->select(); if ($data) { //装修案例预约记录 $w2[] = ['uid', 'in', array_column($data->toArray(), 'uid')]; $w2[] = ['root_id', '=', $token['root_org']]; $sub = CustomerSubscribe::where($w2)->field('sucai_id,uid')->select()->toArray(); foreach ($data as $k => $v) { $data[$k]['group_view'] = []; $data[$k]['subscribe'] = 0; $data[$k]['phone'] = ''; if ($v['pipe_type'] == 'materialCase') { $data[$k]['subscribe'] = 0; foreach ($sub as $k2 => $v2) { $json = json_decode($v->getData('reg_info'), true); if ($v2['uid'] == $v['uid'] && $v2['sucai_id'] == $json['id']) { $data[$k]['subscribe'] = 1; break; } } }elseif(in_array($v['pipe_type'],['groupVr','housetypeVr'])) { $json = json_decode($v->getData('reg_info'), true); $group_view = isset($json['view_foots']) ? $json['view_foots'] : []; if ($group_view) { $vids = VrView::where([['id','in',array_column($group_view,'vid')]])->column('view_title','id'); foreach ($group_view as $key => $value) { $group_view[$key]['title'] = isset($vids[$value['vid']]) ? ($vids[$value['vid']] ?: '未命名场景') : '未命名场景'; } } $data[$k]['group_view'] = $group_view; $data[$k]['phone'] = isset($json['phone']) ? $json['phone'] : ''; } } } return json(['code' => self::success, 'data' => $data, 'msg' => '获取成功']); } /** * 线索无效 */ public function invalidClue($id) { $clue = CustomerClue::where([['id', '=', $id], ['employee_id', '=', $this->request->token['employee_id']]])->find(); if (empty($clue)) return json(['code' => self::success, 'msg' => '操作失败']); $clue->state = 2; $clue->save(); return json(['code' => self::success, 'msg' => '操作成功']); } /** * 更新个人二维码 */ public function qrcode($qr) { $data['qrcode'] = $qr; $data['media_id'] = input('media_id', ''); $data['weixin_media'] = input('weixin_media', ''); Employee::where('id', $this->request->token['employee_id'])->update($data); return json(['code' => self::success, 'msg' => '修改成功']); } /** * 更新个人头像 */ public function up_headimg() { $data['headimg'] = input('headimg', '', 'trim'); if (empty($data['headimg'])) return json(['code' => 1, 'msg' => '图片为空']); $ali_oss_bindurl = 'https://' . config('app.ali_oss_bindurl') . '/'; $headimgurl = $ali_oss_bindurl . $data['headimg'] . '?x-oss-process=image/resize,w_132'; User::where('id', $this->request->token['uid'])->update(['headimgurl' => $headimgurl]); return json(['code' => self::success, 'msg' => '修改成功']); } /** * 更新形象照 */ public function image_photo() { $image_photo = input('image_photo', '', 'trim'); Employee::where('id', $this->request->token['employee_id'])->save(['image_photo' => $image_photo]); Designer::where('employee_id', '=', $this->request->token['employee_id'])->save(['headimgurl' => $image_photo]); return json(['code' => self::success, 'msg' => '修改成功']); } /** * 设置员工个人信息 */ public function edit_employee() { $param = $this->request->only(['position', 'wx', 'nickname', 'name']); $find = Employee::find($this->request->token['employee_id']); $find->user->nickname = $param['nickname']; $find->position = $param['position']; $find->wx = $param['wx']; if($param['name']) $param['initials'] = strtoupper(substr(hanzi2pinyin($param['name']),0,1)); $find->name = $param['name']; $find->user->save(); $result = $find->save(); if ($result) { return json(['code' => self::success, 'msg' => '修改成功']); } else { return json(['code' => self::error_msg, 'msg' => '修改失败']); } } /** * 获取加入的企业 */ public function company() { $token = $this->request->token; $mini_setting = appletConfiguration(); // 用token中的openid获取用户的uid列表 $uidList = User::where([$mini_setting['mini_openid'] => $token['openid']])->whereOr([$mini_setting['unionid'] => $token['unionid']])->column('id'); $employees = Employee::where([['uid', 'in', $uidList], ['state', '=', '在职'], ['disable', '=', 0]])->column('root_id, is_manager, org_id', 'root_id'); $orgs = Org::where([['id', 'in', array_column($employees, 'org_id')]])->column('id,name', 'id'); $notifyList = Miniprogram::where([['root_id', 'in', array_column($employees, 'root_id')]])->column('root_id,notify', 'root_id'); //2023-03-21店面可以在不同的小程序中使用 去掉条件, ['mini', '=', $token['mini']] $companyList = Company::with(['brand'])->where([['root_id', 'in', array_column($employees, 'root_id')]])->select()->visible(['company_name', 'root_id', 'status', 'end_date','logo'])->toArray(); foreach ($companyList as &$item) { $item['client_type'] = isset($notifyList[$item['root_id']]) ? $notifyList[$item['root_id']]['notify'] : ''; $item['is_manager'] = isset($employees[$item['root_id']]) ? $employees[$item['root_id']]['is_manager'] : 0; $item['org_name'] = (isset($employees[$item['root_id']]) && isset($orgs[$employees[$item['root_id']]['org_id']])) ? $orgs[$employees[$item['root_id']]['org_id']]['name'] : ''; if ($item['status'] == 1) { $item['off'] = 1; $item['off_remark'] = '账号被禁用'; } elseif ($item['end_date'] < date('Y-m-d')) { $item['off'] = 1; $item['off_remark'] = '账号已过期'; } else { $item['off'] = 0; $item['off_remark'] = '账号正常'; } if(!empty($item['logo']) && !empty($item['brand'])){ $item['brand']['logo']=$item['logo']; } } return json(['code' => 0, 'data' => $companyList]); } /** * 设计师增加个人作品 */ public function designer_add_works() { $param = $this->request->only(['id'=>0,'title', 'style_id'=>0,'housetype_id'=>0, 'square', 'money','type','desc'=>'','vr_case'=>'']); $token = $this->request->token; if (strlen($param['title']) > 50) { return json(['code' => self::error_msg, 'msg' => '作品名称过长']); } $cover_img = $vrstr = null; if (!empty($param['vr_case']) && $param['type'] == 2){ $builmod = new Building($this->app); $vrlist = explode(',',$param['vr_case']); foreach($vrlist as $val){ $vrstr.= $builmod->vrlink_set($val).','; } $vrstr = trim($vrstr,','); } if (!empty($param['desc']) && $param['type'] == 1){ $imgs = explode(',',$param['desc']); $cover_img = $imgs[0]; } $add = [ 'title' => $param['title'], 'housetype_id' => $param['housetype_id'], 'square' => $param['square'], 'money' => $param['money'], 'type' => $param['type'], 'desc' => $param['desc'], 'cover_img'=> $cover_img, 'vr_case' => $vrstr, 'style_id' =>$param['style_id'] ]; if($param['id']){ $check = DesignerCollectionWorks::where([['root_id','=',$token['root_org']],['employee_id','=',$token['employee_id']],['id','=',$param['id']]])->find(); if(empty($check)) return json(['code'=>1,'msg'=>'数据不存在']); $add['id'] = $param['id']; DesignerCollectionWorks::update($add); }else{ $add['employee_id'] = $token['employee_id']; $add['root_id'] = $token['root_org']; $add['designer_id'] = $token['org_type'] == 2 ? $token['employee_id'] : 0; $ms = DesignerCollectionWorks::create($add); } return json(['code'=>0,'msg'=>'编辑成功']); } /** * 设计师个人作品详情 */ public function designer_worksdet() { $param = $this->request->only(['id']); $token = $this->request->token; $data = DesignerCollectionWorks::with(['decostyle','housetype'])->where([['root_id','=',$token['root_org']],['employee_id','=',$token['employee_id']],['id','=',$param['id']]])->find(); if(empty($data)) return json(['code'=>1,'msg'=>'数据不存在']); return json(['code'=>0,'data'=>$data,'msg'=>'获取成功']); } /** * 设计师作品集列表 */ public function designer_worklist() { $param = $this->request->only(['page'=>1,'limit'=>10]); $token = $this->request->token; $list = DesignerCollectionWorks::with(['decostyle','housetype'])->where([['root_id','=',$token['root_org']],['employee_id','=',$token['employee_id']]])->page($param['page'],$param['limit'])->select()->toArray(); foreach($list as $key=>$val){ if($val['type'] == 2 && !empty($val['vr_case'])){ $list[$key]['cover_img'] = !empty($val['vr_case'][0]['vr_img']) ? $val['vr_case'][0]['vr_img'] : ''; } } return json(['code'=>0,'data'=>$list,'msg'=>'获取成功']); } }