request->token; $name = Setting::where(['root_id' => $token['root_org'], 'name' => 'agentSettingName'])->value('content'); return json(['code' => 0, 'msg' => '获取成功', 'name' => $name]); } /** * 弹框邀请说明 */ public function inviteShow() { $token = $this->request->token; $setdata = Setting::where([['root_id', '=', $token['root_org']], ['name', 'in', ['agentInviteShow', 'agentBackgroundImg']]])->column('content', 'name'); $img = !empty($setdata['agentInviteShow']) ? 'https://' . config('app.ali_oss_bindurl') . '/' . $setdata['agentInviteShow'] : ''; $img1 = !empty($setdata['agentBackgroundImg']) ? 'https://' . config('app.ali_oss_bindurl') . '/' . $setdata['agentBackgroundImg'] : ''; $imgarr = ['agentInviteShow' => $img, 'agentBackgroundImg' => $img1]; return json(['code' => 0, 'msg' => '获取成功', 'show' => !empty($setdata['agentInviteShow']) ? 'true' : 'false', 'content' => $imgarr]); } //经纪人报名 public function add_agents() { $token = $this->request->token; $data = $this->request->only(['name' => '', 'phone', 'employee_id', 'wechat' => '', 'type']); if (empty($data['employee_id'])) { return json(['code' => 1, 'msg' => '所属员工id为空']); } if (empty($data['type'])) return json(['code' => 1, 'msg' => '经纪人类型错误']); $empdata = Employee::where([['root_id', '=', $token['root_org']], ['id', '=', $data['employee_id']]])->field('org_id,name')->find()->toArray(); if (empty($empdata)) return json(['code' => 1, 'msg' => '员工信息不存在']); if ($token['isEmployee']) return json(['code' => 1, 'msg' => '员工不能成为经纪人']); //if(!empty($empdata['uid']) && $empdata['uid'] == $token['uid']) return json(['code' => 1, 'msg' => '员工不能成为经纪人']); $where[] = ['root_id', '=', $token['root_org']]; $where[] = ['uid', '=', $token['uid']]; $check = AgentUser::where($where)->find(); if ($check) return json(['code' => 1, 'msg' => '已经报名']); $add = array( 'agent_name' => empty($data['name']) ? '游客' : $data['name'], 'agent_employee_id' => $data['employee_id'], 'agent_phone' => $data['phone'], 'type' => $data['type'], 'is_review' => 1, 'root_id' => $token['root_org'], 'uid' => $token['uid'], 'org_id' => $empdata['org_id'], 'wechat' => $data['wechat'] ); // 足迹 $token = $this->request->token; if (!empty($token['uid']) && !$token['isEmployee']) { $footerArr = [ 'agent_name' => $data['name'], 'agent_phone' => $data['phone'], ]; event(new FootPrints($token['uid'], $token['share_employee'] ?? 0, $token['share_org'] ?? 0, $footerArr, 'agents')); } $ms = AgentUser::insertGetId($add); if ($ms) { return json(['code' => 0, 'msg' => '报名成功', 'data' => $ms]); } else { return json(['code' => 1, 'msg' => '报名失败', 'data' => '']); } } //查询经纪人是否已经报过名 public function sel_sign_up() { $token = $this->request->token; $empdata = AgentUser::where([['uid', '=', $token['uid']], ['root_id', '=', $token['root_org']]])->find(); if (empty($empdata)) { return json(['code' => 0, 'msg' => '报名信息不存在']); } else { if ($empdata['is_review'] == 1) { return json(['code' => 1, 'msg' => '请等待审核']); } else { return json(['code' => 2, 'msg' => '已经报名成功审核通过']); } } } //活动详情 public function activity_detail($id) { $token = request()->token; $data = Activity::where(['id' => $id, 'del' => 0, 'root_id' => $token['root_org']])->field('id,cover,title,content,type,start_date,end_date,end_date as timestate,view,money,cate,address,poster,show')->find(); //是否收藏 $collectedIds = UserCollect::where(['user_id' => $token['uid'], 'content_type' => 'activity', 'content_id' => $id])->count(); $data['collected'] = $collectedIds > 0 ? true : false; Activity::where('id', $id)->inc('view')->update(); $qrcode = ActivitySign::where([['aid', '=', $id], ['uid', '=', $token['uid']]])->value('qrcode'); $ali_oss_bindurl = config('app.ali_oss_bindurl'); $url = 'https://' . $ali_oss_bindurl . '/'; $data['qrcode'] = $qrcode ? $url . $qrcode : ''; return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']); } //通过活动报名的客户 public function add_activity_customer() { $token = $this->request->token; $param = $this->request->only(['phone', 'sex', 'agent_id', 'aid']); $agtdata = AgentUser::where('id', $param['agent_id'])->find(); if (empty($agtdata)) return json(['code' => 1, 'msg' => '所属经纪人信息为空']); if ($token['uid'] == $agtdata['id']) return json(['code' => 1, 'msg' => '您的身份是经纪人,不能参加活动']); if ($token['isEmployee']) return json(['code' => 1, 'msg' => '您的身份是业务员,不能参加活动']); //活动已经结束无法报名 $info = Activity::where('id', $param['aid'])->find(); if (empty($info)) return json(['code' => 1, 'msg' => '活动不存在']); if ($info['del'] == 1 || $info['show'] == 0 || date('Y-m-d') > $info['end_date']) { return json(['code' => 1, 'msg' => '活动结束或已下架,无法报名']); } // 设计师能否报备、获取客户 $root_id = $agtdata['root_id']; $de_where[] = ['root_id', '=', $root_id]; $de_where[] = ['name', '=', 'designer_get_customer']; $info_de_where = Setting::where($de_where)->findOrEmpty(); $org_type = Org::where('id', '=', $agtdata['org_id'])->value('org_type'); if (!$info_de_where->isEmpty() && $org_type == 2) { if ((int)$info_de_where['content'] != 1) { return json(['code' => 1, 'msg' => '请联系业务员进行报名']); } } $data['employee_id'] = $agtdata['agent_employee_id']; $data['org_id'] = $agtdata['org_id']; $data['state'] = 0; $data['level'] = 'C'; $data['agents_id'] = $agtdata['id']; $data['agent_source_type'] = 2; $data['uid'] = $token['uid']; $data['name'] = ModelUser::where('id', $token['uid'])->value('nickname') ?: ''; $data['sex'] = !empty($param['sex']) ? $param['sex'] : 1; $orgids = orgSubIds(!empty($token['root_org']) ? $token['root_org'] : $agtdata['root_id']); // 新建档,检测手机号是否重复 $pharr = [$param['phone']]; $tips = (new AgentsLogic())->checkPepeat($pharr, $orgids, $data['employee_id'], '', 'sign'); if (!empty($tips)) return $tips; //检测用户是否已经建过档 $aw[] = ['uid', '=', $token['uid']]; $aw[] = ['org_id', 'in', $orgids]; $customer = Customer::where($aw)->find(); if (!empty($customer)) { return json(['code' => 1, 'msg' => '报名失败,你已经报备过']); } //插入经济人提报的客户 $data['phone'] = cypherphone(trim($param['phone'])); Db::startTrans(); try { $ms = Customer::insertGetId($data); $empuid = Employee::where('id', $agtdata['agent_employee_id'])->value('uid'); $visitlog = CustomerVisitLog::where([['customer_id', '=', $ms], ['state', 'in', CustomerVisitLog::changeState('待确认', 'chaos')]])->find(); if (!$visitlog) { $save = []; $save['customer_id'] = $ms; $save['type'] = ''; $save['remark'] = !empty($data['remark']) ? $data['remark'] : '通过经纪人分享的活动报名的客户'; $save['employee_id'] = $agtdata['agent_employee_id']; $save['user_id'] = $empuid; $save['state'] = 1; //$save['aid'] = $param['aid']; CustomerVisitLog::insertGetId($save); } // if($agtdata['type']==2){ // $rule_type='wanghong_integral'; // $itg_rule=CreditsSetting::where([['code','=',$rule_type],['root_id','=',$agtdata['root_id']]])->value('value'); // //$itg_rule=json_decode($itg_rule,true); // $state='网红活动录入客户'; // $add = array( // 'agent_id' => $agtdata['id'], // 'type' => 4, // 'integral' => $itg_rule ?$itg_rule :1, // 'addtime' => time(), // 'state' => $state, // 'customer_id' => $ms, // 'status'=>1 // ); // AgentIntegral::insert($add); // } //生成报名二维码 //二维码内容,活动id,报名人uid $qrcode_con = $param['aid'] . '&' . $ms . '&' . $token['uid']; $cate = Activity::where('id', $param['aid'])->value('cate'); $qrcode_con = $qrcode_con . '&' . $cate; $name = uniqid() . '.jpg'; $path = 'activityqrcode/' . $name; $img = qrcode($qrcode_con, 'upload/' . $name); $res = ossUpload($path, 'upload/' . $name); @unlink('upload/' . $name); //删除本地文件 ActivitySign::insertGetId([ 'aid' => $param['aid'], 'root_id' => $orgids, 'uid' => $token['uid'], 'share_uid' => $empuid, 'share_employee_id' => $agtdata['agent_employee_id'], 'qrcode' => $path, 'qrcode_con' => $qrcode_con, 'addtime' => date('Y-m-d H:i:s') ]); $ali_oss_bindurl = config('app.ali_oss_bindurl'); $url = 'https://' . $ali_oss_bindurl . '/' . $path; Db::commit(); } catch (\Exception $e) { Db::rollback(); var_dump($e->getMessage()); return json(['code' => 1, 'msg' => '报名数据失败.']); } if ($ms) { return json(['code' => 0, 'msg' => '报名成功.', 'url' => $url]); } else { return json(['code' => 1, 'msg' => '报名失败.']); } } //核销规则 public function wiped_rule() { $token = $this->request->token; $param = $this->request->only(['agent_id']); if (empty($param['agent_id'])) return json(['code' => 1, 'msg' => '经纪人参数错误']); $agtdata = AgentUser::where([['root_id', '=', $token['root_org']], ['id', '=', $param['agent_id']]])->find(); if (empty($agtdata)) return json(['code' => 1, 'msg' => '经纪人不存在']); $hxtype = 'reduce_integral'; $hxdata = CreditsSetting::where([['code', '=', $hxtype], ['root_id', '=', $agtdata['root_id']]])->value('value'); if (empty($hxdata)) return json(['code' => 0, 'data' => '1积分等于0元', 'msg' => '请求成功']); $hx = json_decode($hxdata, true); $data = $hx['jifen'] . '积分等于' . $hx['money'] . '元'; return json(['code' => 0, 'data' => $data, 'msg' => '请求成功']); } /** * 分享任务、分享内容(展示我分享过的) */ public function share_article() { $param = $this->request->only(['page' => 1, 'limit' => 10, 'from' => '', 'type' => 1,'employee_id']); $token = $this->request->token; //$agtdata = $this->request->agtdata; if(empty($param['employee_id'])) return json(['code'=>1,'msg'=>'员工id为空']); $where = [ ['root_id', '=', $token['root_org']], ['employee_id', '=', $param['employee_id']], ['disable', '=', 0], ['from','=',1] ]; $data = AgentShareContent::where($where)->order('addtime desc')->order('addtime desc')->page($param['page'], $param['limit'])->select()->toArray(); foreach ($data as &$item) { //分享量 $item['share_num'] = ShareLog::where([['type', '=', $item['type']], ['data_id', '=', $item['data_id']], ['agent_id', '<>', 'NULL']])->count(); //线索 $item['clue_num'] = CustomerClue::where([['pipe_type', '=', $item['type']], ['pipe_id', '=', $item['data_id']], ['agent_id', '<>', 0]])->count(); //是否未分享 //$item['new'] = in_array($item['id'], $content_id) ? false : true; switch ($item['type']) { case 'Article': $find = Article::where([ ['root_id', '=', $token['root_org']], ['delete_time', '=', 0], ['publish', '=', 1], ['id', '=', $item['data_id']] ])->field('id,title,cover_img')->find(); $item['content_id'] = $find['id']; $item['title'] = $find['title']; $item['cover'] = $find['cover_img']; break; case 'MaterialCase': $find = MaterialCase::where([ ['root_id', '=', $token['root_org']], ['del', '=', 0], ['publish', '=', 1], ['id', '=', $item['data_id']] ])->field('id,title,cover_img')->find(); $item['content_id'] = $find['id']; $item['title'] = $find['title']; $item['cover'] = $find['cover_img']; break; case 'Video': $find = Video::where([ ['root_id', '=', $token['root_org']], ['delete_time', '=', 0], ['publish', '=', 1], ['id', '=', $item['data_id']] ])->field('id,title,video_url')->find(); $item['content_id'] = $find['id']; $item['title'] = $find['title']; $item['cover'] = $find['video_url']; break; case 'CompanyStrength': $find = CompanyStrength::where([ ['root_id', '=', $token['root_org']], ['del', '=', 0], ['publish', '=', 1], ['id', '=', $item['data_id']] ])->field('id,title,cover,pics,difference')->find(); $item['content_id'] = $find['id']; $item['title'] = $find['title']; $item['cover'] = $find['cover']; $item['pics'] = $find['pics']; $item['difference'] = $find['difference']; break; case 'MaterialEvidence': $find = MaterialEvidence::where([ ['root_id', '=', $token['root_org']], ['del', '=', 0], ['publish', '=', 1], ['id', '=', $item['data_id']] ])->field('id,title,pics,difference')->find(); $item['content_id'] = $find['id']; $item['title'] = $find['title']; $item['cover'] = $find['pics']; $item['difference'] = $find['difference']; break; case 'Building': $find = Building::where([ ['root_id', '=', $token['root_org']], ['del', '=', 0], ['id', '=', $item['data_id']] ])->field('id,community_id,name,cover')->find(); $item['content_id'] = $find['id']; $item['title'] = $find['name']; $item['cover'] = $find['cover']; break; case 'AgentArticle': $find = AgentArticle::where([ ['root_id', '=', $token['root_org']], ['id', '=', $item['data_id']] ])->field('id,title,file,type')->find(); $item['content_id'] = $find['id']; $item['title'] = $find['title']; $item['cover'] = $find['file']; $item['file_type'] = $find['type']; break; default: break; } } //查询分享的奖励规则 $rule_data = AgentType::where([['root_id', '=', $token['root_org']], ['id', '=', $param['type']]])->value('count'); $rule_list = !empty($rule_data) ? json_decode($rule_data, true) : ''; $reward_rules = []; if (!empty($rule_list)) { $reward_rules[] = '1 推荐一个客户' . $rule_list['putong_integral'] . '积分'; $reward_rules[] = '2 分享一条内容' . $rule_list['ptagentshare_integral'] . '积分'; $reward_rules[] = '3 分享内容获得一条线索' . $rule_list['produceclue_integral'] . '积分'; $reward_rules[] = '4 客户到店' . $rule_list['daodian_integral'] . '积分'; $reward_rules[] = '5 客户签单' . $rule_list['jiaoding_integral'] . '积分'; $reward_rules[] = '6 客户转单' . $rule_list['qiandan_integral'] . '积分'; } //$reward_rules = !empty($rule_list) ? '分享一条内容'.$rule_list['ptagentshare_integral'].'积分' : ''; $list = ['list' => $data, 'reward_rules' => $reward_rules]; return json(['code' => 0, 'data' => $list]); } /** * 公司上传内容列表 */ public function company_artlist() { //$agtdata = $this->request->agtdata; $token = $this->request->token; $param = $this->request->only(['page' => 1, 'limit' => 10,'type']); $where = [ ['root_id', '=', $token['root_org']], ['from', '=', 2], ['disable', '=', 0] ]; $vrObj = new Vr(); $list = AgentArticle::where($where)->field('id,title,file,type,content,addtime,vr_group_ids')->page($param['page'], $param['limit'])->select()->toArray(); $show_url = config('app.vr_show_domain'); foreach ($list as $key => $val) { //分享量 $list[$key]['share_num'] = ShareLog::where([['type', '=', 'AgentArticle'], ['data_id', '=', $val['id']], ['agent_id', '<>', 'NULL']])->count(); //线索 $list[$key]['clue_num'] = CustomerClue::where([['pipe_type', '=', 'AgentArticle'], ['pipe_id', '=', $val['id']], ['agent_id', '<>', 0]])->count(); $list[$key]['files'] = ''; if ($val['type'] == 2) $list[$key]['cover'] = !empty($val['file'][0]) ? $val['file'][0] : ''; if ($val['type'] == 3) { $list[$key]['files'] = !empty($val['file'][0]) ? str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val['file'][0]) : ''; $list[$key]['cover'] = !empty($val['file'][0]) ? $vrObj->getFirstImg(str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $val['file'][0])) : ''; } if ($val['type'] == 4) { $group = VrGroup::where('id', $val['vr_group_ids'])->field('pic_path')->findOrEmpty(); $list[$key]['cover'] = $group->isEmpty() ? '' : $group->pic_path; } $list[$key]['vr_group_url'] = ''; if ($val['type'] == 4) { $group = VrGroup::where('id', $val['vr_group_ids'])->field('pic_path,sid')->findOrEmpty(); if (!$group->isEmpty()) { $list[$key]['vr_group_url'] = $show_url . $group->sid; $list[$key]['file_img'] = $group->pic_path; } $data['file_img'] = $group->isEmpty() ? '' : $group->pic_path; } } //查询分享的奖励规则 $rule_data = AgentType::where([['root_id', '=', $token['root_org']], ['id', '=', $param['type']]])->value('count'); $rule_list = !empty($rule_data) ? json_decode($rule_data, true) : ''; $reward_rules = []; if (!empty($rule_list)) { $reward_rules[] = '1 推荐一个客户' . $rule_list['putong_integral'] . '积分'; $reward_rules[] = '2 分享一条内容' . $rule_list['ptagentshare_integral'] . '积分'; $reward_rules[] = '3 分享内容获得一条线索' . $rule_list['produceclue_integral'] . '积分'; $reward_rules[] = '4 客户到店' . $rule_list['daodian_integral'] . '积分'; $reward_rules[] = '5 客户签单' . $rule_list['jiaoding_integral'] . '积分'; $reward_rules[] = '6 客户转单' . $rule_list['qiandan_integral'] . '积分'; } $list = ['list' => $list, 'reward_rules' => $reward_rules]; return json(['code' => 0, 'data' => $list, 'msg' => '获取成功']); } /** * 分享任务详情 */ public function share_article_details() { $id = $this->request->param('id'); $from = $this->request->param('from'); $employee_id = $this->request->param('employee_id'); $token = $this->request->token; //$agtdata = $this->request->agtdata; $where = [ ['root_id', '=', $token['root_org']], ['id', '=', $id], ['disable', '=', 0] ]; if (empty($from)) $where[] = ['employee_id', '=', $employee_id]; $data = AgentArticle::where($where)->field('id,title,file,content,talkskill,type,vr_group_ids')->find(); //var_dump($data);exit; $vrObj = new Vr(); $data['file_img'] = $data['files'] = ''; $show_url = config('app.vr_show_domain'); if ($data['type'] == 3) { $data['files'] = !empty($data['file'][0]) ? str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $data['file'][0]) : ''; $data['file_img'] = !empty($data['file'][0]) ? $vrObj->getFirstImg(str_replace('https://' . config('app.ali_oss_bindurl') . '/', '', $data['file'][0])) : ''; } $data['vr_group_url'] = ''; if ($data['type'] == 4) { $group = VrGroup::where('id', $data['vr_group_ids'])->field('pic_path,sid')->findOrEmpty(); if (!$group->isEmpty()) { $data['vr_group_url'] = $show_url . $group->sid; $data['file_img'] = $group->pic_path; } $data['file_img'] = $group->isEmpty() ? '' : $group->pic_path; } return json(['code' => 0, 'data' => $data]); } /** * 经纪人端是否展示【推荐分享】板块(后台设置开关) */ public function show_recommend_share() { $token = $this->request->token; $setdata = Setting::where([['root_id', '=', $token['root_org']], ['name', '=', 'agentEmployeeAdd']])->value('content'); $setdata = $setdata ?: 'true'; return json(['code' => 0, 'data' => $setdata]); } /** * 未成为经纪人时获取员工的uid */ public function get_empuid($employee_id) { $token = $this->request->token; $uid = Employee::where([['root_id','=',$token['root_org']],['id','=',$employee_id],['state','in','在职'],['uid','>',0]])->value('uid'); return json(['code' => 0, 'data' => $uid,'msg'=>'获取成功']); } }