123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932 |
- <?php
- declare(strict_types=1);
- namespace app\index\controller;
- use app\event\FootPrints;
- use app\event\Msg;
- use app\model\Building as BuildingModel;
- use app\model\BuildingConstruction;
- use app\model\BuildingHousetype;
- use app\model\BuildingProgress;
- use app\model\BuildingUrge;
- use app\model\Company;
- use app\model\Construction;
- use app\model\ConstructionRecord;
- use app\model\ConstructionStep;
- use app\model\Designer;
- use app\model\DesignerReserve;
- use app\model\Org;
- use app\model\QuoteRecord as QuoteRecordModel;
- use app\model\Setting;
- use toolkits\Aec;
- use think\facade\View;
- use app\model\ActivityOrder;
- use app\model\CustomerClue;
- use app\model\Employee;
- use app\model\Footprints as ModelFootprints;
- use app\model\Miniprogram;
- use app\model\User;
- use app\model\AgentUser;
- use app\model\Customer;
- use think\facade\Db;
- use app\model\CreditsSetting;
- use app\logics\AgentsLogic;
- use app\model\AgentIntegral;
- use openssl\Aes;
- use think\facade\Cache;
- use wx\offiaccount\JsSdk;
- use think\helper\Str;
- use wx\offiaccount\User as OffiaccountUser;
- use app\model\CustomerVisitLog;
- use xiaohongwu\Vr;
- use app\model\BuildingMaterialCase;
- use app\model\MaterialCase;
- use app\model\UserCollect;
- use app\model\Decostyle;
- use app\model\BuildingDevelopCase;
- use app\model\ActivitySign;
- use app\model\CustomersSubscribe;
- use app\model\Activity;
- use app\model\Community;
- use app\model\Construction as ConstructionModel;
- class Index extends Wxbase
- {
- public function initialize()
- {
- $request = request();
- $action = $request->action();
- $nocheck = ['visitDueTime', 'houseroom_list', 'housetype_list', 'progress', 'material_case', 'dev_case_list', 'dev_case_detail'];
- if (in_array($action, $nocheck)) return;
- //if ($action == 'visitDueTime') return;
- $r = $request->param('r');
- $user = session('user');
- if (!empty($user) && $user['root_id'] != $r) {
- $this->copyUser($user, $r);
- } else {
- $this->user = session('user');
- }
- $n = $request->param('n');
- $code = $request->param('code');
- if (!empty($code) && empty($this->user)) {
- $this->codeForInfo($code);
- }
- $noauth = ['content','dev_case_details','vr','progress_detail','housetype'];
- if (in_array($action,$noauth) && empty($n)) return;
- if (empty($this->user) && empty($code)) {
- $this->redirectForCode();
- }
- }
- private function redirectForCode()
- {
- $request = request();
- $param = $request->get();
- $appid = config('app.official_appid');
- // 跳转授权页面
- unset($param['code']);
- unset($param['state']);
- if ($request->action() == 'content') unset($param['n']);
- if ($request->action() == 'vr') unset($param['n']);
- $redirectUrl = url($request->baseUrl(), $param, false, true);
- $wxUser = new OffiaccountUser();
- $wxUser->redirectForCode($appid, $redirectUrl);
- }
- /**
- * 通过code获取用户信息并定向
- *
- * @return void
- */
- private function codeForInfo($code)
- {
- $request = request();
- $param = $request->param();
- $get = $request->get();
- $wxUser = new OffiaccountUser();
- $appid = config('app.official_appid');
- $data = $wxUser->getAccessTokenByCode($appid, config('app.official_secret'), $code);
- if (isset($data['errcode']) && in_array($data['errcode'], [40029, 40163, 41008, 42003])) { // code已经被使用
- echo "<script>history.go(-1);</script>";
- exit;
- } elseif (isset($data['errcode'])) {
- trace('授权获取用户信息', 'error');
- trace($data, 'error');
- echo $data['errmsg'];
- exit;
- }
- // 查询用户信息是否存在
- $user = User::whereOr([[['openid', '=', $data['openid']], ['root_id', '=', $param['r']]], [['unionid', '=', $data['unionid']], ['root_id', '=', $param['r']]]])->order('updatetime desc')->findOrEmpty();
- if ($user->isEmpty() || empty($user->unionid) || empty($user->headimgurl) || $user->nickname=='游客') {
- $userInfo = $wxUser->getH5UserInfo($data['access_token'], $data['openid']);
- if (isset($userInfo['errcode'])) {
- trace('拉取用户信息', 'error');
- trace($data, 'error');
- echo '请求失败';
- exit;
- }
- $user->save([
- 'nickname' => $userInfo['nickname'],
- 'sex' => $userInfo['sex'],
- 'headimgurl' => $userInfo['headimgurl'],
- 'province' => $userInfo['province'],
- 'city' => $userInfo['city'],
- 'country' => $userInfo['country'],
- 'openid' => $userInfo['openid'],
- 'unionid' => $userInfo['unionid'] ?? '',
- 'root_id' => $param['r'],
- 'updatetime' => date('Y-m-d H:i:s')
- ]);
- } else {
- $user->updatetime = date('Y-m-d H:i:s');
- if (empty($user->unionid)) $user->unionid = $data['unionid'];
- $user->save();
- }
- $this->user = $user->toArray();
- session('user', $this->user);
- session('openid', $data['openid']);
- }
- /**
- * 建立线索关系
- */
- private function addClue($employee_id, $agent_id = null)
- {
- // 判断是否是员工
- $isEmployee = Employee::where([['uid', '=', $this->user['id']], ['root_id', '=', $this->user['root_id']], ['state', 'in', ['在职', '待审核']]])->find();
- if ($isEmployee) return false;
- $employee = Employee::find($employee_id);
- if (empty($employee)) return false;
- $data = [
- 'employee_id' => $employee_id,
- 'uid' => $this->user['id'],
- 'org_id' => $employee->org_id
- ];
- // 建立线索关系
- $had = CustomerClue::where($data)->find();
- if (!$had) {
- //如果是经纪人分享
- if (!empty($agent_id)) $data['agent_id'] = $agent_id;
- CustomerClue::create($data);
- } else {
- $had->updatetime = date('Y-m-d H:i:s');
- $had->save();
- }
- return $had;
- }
- /**
- * 用户分享内容
- */
- public function content($p)
- {
- // 设置分享链接
- $jssdk = new JsSdk();
- $appid = config('app.official_appid');
- if (cache('?jsapi_ticket')) {
- $ticket = cache('jsapi_ticket');
- } else {
- // 获取普通access_token
- if (!$token = Cache::get('zqxg_offi_access_token')) {
- $token = getAccessToken($appid, config('app.official_secret'));
- Cache::set('zqxg_offi_access_token', $token, 7100);
- }
- $ticket = $jssdk->getJsApiTicket($token);
- cache('jsapi_ticket', $ticket, 7200);
- }
- $signPackage = $jssdk->getSignPackage($ticket);
- $signPackage['appid'] = $appid;
- View::assign('wxconfig', $signPackage);
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $pArr);
- // 分享内容获取
- $data = $this->getContent(intval($pArr['id']), $pArr['type']);
- if (empty($data)) abort(404, '页面不存在');
- $employee_id = isset($pArr['employee_id']) ? intval($pArr['employee_id']) : 0;
- $leftToEmpId = Employee::where(['id' => $employee_id, 'state' => '离职'])->value('left_to_empid');
- if ($leftToEmpId) $employee_id = $leftToEmpId;
- $data['share_employee'] = Employee::with(['user' => function ($query) {
- $query->field('id,headimgurl');
- }])->where(['id' => $employee_id])->field('id,uid,name,phone,qrcode,org_id')->find();
- //判断是否是经纪人分享
- $agent_id = isset($pArr['agent_id']) ? intval($pArr['agent_id']) : null;
- $data['agent_id'] = $agent_id;
- View::assign('data', $data);
- View::assign('p', $p);
- $r = input('r');
- View::assign('r', $r);
- $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
- View::assign('getPhone', false);
- if (!empty($this->user)) {
- // 分享关系创建
- if (!empty($data['share_employee'])) {
- $clue = $this->addClue($employee_id, $agent_id);
- if (!empty($clue) && $clue->phone)
- View::assign('getPhone', true);
- event(new FootPrints($this->user['id'], $data['share_employee']['id'], $data['share_employee']['org_id'], $data, lcfirst($pArr['type'])));
- $foot = ModelFootprints::where(['uid' => $this->user['id'], 'employee_id' => $data['share_employee']['id'], 'pipe_type' => lcfirst($pArr['type']), 'org_id' => $data['share_employee']['org_id']])->field('id,addtime')->order('addtime desc')->find();
- if ($foot) $visit = $foot->toArray();
- }
- View::assign('authorize', true);
- $check = ModelFootprints::where(['uid' => $this->user['id'], 'pipe_type' => 'designer'])->findOrEmpty();
- // $check = DesignerReserve::where([['uid','=',$this->user['id']],['pipe_type','=','materialCase']])->findOrEmpty();
- View::assign('is_reserve', $check->isEmpty() ? 0 : 1);
- } else {
- View::assign('authorize', false);
- View::assign('is_reserve', 0);
- }
- View::assign('visit', $visit);
- $ali_oss_bindurl = config('app.ali_oss_bindurl');
- $url = 'https://' . $ali_oss_bindurl . '/';
- View::assign('url', $url);
- return View::fetch('index/' . Str::snake($pArr['type'], '_'));
- }
- private function getContent($id, $classType)
- {
- if($classType == 'company') $classType = 'CompanyVrshow';
- $class = 'app\\model\\' . $classType;
- if (!class_exists($class)) return null;
- $obj = new $class();
- $data = $obj->find($id);
- if (empty($data)) {
- return null;
- }
- if ($classType == 'Activity' && !empty($this->user)) {
- // 判断是否交定
- $hadPay = ActivityOrder::where(['user_id' => $this->user['id'], 'activity_id' => $data['id'], 'state' => 1])->count();
- if ($hadPay) $data['had_pay'] = 1;
- else $data['had_pay'] = 0;
- //是否报名
- $sign = ActivitySign::where([['uid', '=', $this->user['id']], ['aid', '=', $data['id']]])->findOrEmpty();
- $data['activity_sign'] = !$sign->isEmpty();
- $data['sign_qrcode'] = $sign->qrcode;
- } elseif ($classType == 'Construction') {
- // 查询施工步骤
- $steps = ConstructionStep::where(['root_id' => $data->root_id])->field('id,order,name')->order('order')->select();
- // 查询施工情况
- $records = ConstructionRecord::with(['step'])->where(['construction_id' => $data->id])->field('id,construction_id,step_id,img,content,addtime,vr,video,video_cover,type')->order('step_id')->select();
- $vrObj = new Vr();
- foreach ($records as $k => $v) {
- if (!empty($v['vr']) && $v['type'] == 'vr') {
- $vrUrlList = explode(',', $v['vr']);
- $vrData = [];
- foreach ($vrUrlList as $url) {
- $vrData[] = [
- 'vrUrl' => urlencode($url),
- 'vrfirstImg' => $vrObj->getFirstImg($url)
- ];
- }
- $records[$k]['vr'] = $vrData;
- }
- }
- // 施工进度
- $maxStep = 0;
- foreach ($records as $r) {
- if ($maxStep == 0) $maxStep = $r->step->order;
- elseif ($maxStep < $r->step->order) $maxStep = $r->step->order;
- }
- View::assign('steps', $steps);
- View::assign('maxStep', $maxStep);
- View::assign('records', $records);
- } elseif ($classType == 'Building') {
- $data = BuildingModel::find($id);
- //关联在施工地数量
- $area_list = BuildingHousetype::where('building_id', '=', $id)->order('area asc')->limit(3)->column('area');
- // $data['area_list'] = implode('/', array_values(array_unique(array_filter($area_list))));
- $data['area_list'] = array_values(array_unique(array_filter($area_list)));
- //小区户型
- $housetype = BuildingHousetype::where('building_id', '=', $id)->withCount(['materialCase'])->select()->each(function ($item) {
- if (!empty($item['vr_link'])) {
- $item->vr_link = urlencode($item['vr_link']);
- }
- });
- $data['housetype'] = $housetype->toArray();
- $vrObj = new Vr();
- $data['vr_link_cover'] = '';
- if (!empty($data['vr_link'])) {
- $data['vr_link_cover'] = $vrObj->getFirstImg($data['vr_link']);
- $data['vr_link'] = urlencode($data['vr_link']);
- }
- $data['housetype_count'] = $housetype->count();
- //$vrObj = new Vr();
- $domain = request()->domain();
- $progress_list = BuildingProgress::where('building_id', '=', $id)->order('addtime desc')->select()->toArray();
- foreach ($progress_list as &$item) {
- if (empty($item['vr'])) {
- $item['vr'] = [];
- } else {
- $vrUrlList = explode(',', $item['vr']);
- $vrData = [];
- foreach ($vrUrlList as $url) {
- $vrData[] = [
- 'vrUrl' => urlencode($url),
- 'vrfirstImg' => $vrObj->getFirstImg($url)
- ];
- }
- $item['vr'] = $vrData;
- }
- $item['progress_cont_link'] = $domain . '/index/index/progress_detail.html?r=' . $item['root_id'] . '&id=' . $item['id'];
- }
- $data['progress'] = $progress_list;
- //在施工地
- $construction_ids = BuildingConstruction::where('building_id', '=', $id)->column('construction_id');
- $construction = Construction::with(['style', 'housetype'])->where([['id', 'in', $construction_ids]])->select()->toArray();
- // 查询施工步骤
- $steps = ConstructionStep::where(['root_id' => $data->root_id])->field('id,order,name')->order('order')->select();
- foreach ($construction as &$item) {
- $item['step_list'] = $steps;
- // 查询施工情况
- $records = ConstructionRecord::with(['step'])->where(['construction_id' => $item['id']])->field('id,step_id,img,content,addtime')->order('step_id')->select();
- // 施工进度
- $maxStep = 0;
- foreach ($records as $r) {
- if ($maxStep == 0) $maxStep = $r->step->order;
- elseif ($maxStep < $r->step->order) $maxStep = $r->step->order;
- }
- $item['maxStep'] = $maxStep;
- }
- $data['construction'] = $construction;
- } elseif ($classType == 'MaterialCase') {
- $data->designer = Employee::with(['designer', 'user'])->where('id', $data['designer_id'])->find();
- if ($data->designer) {
- $data->designer->headimgurl = User::where('id', '=', $data['designer']['uid'])->value('headimgurl');
- }
- $data->img_content = $data->img_content ? json_decode($data->img_content, true) : [];
- } elseif($classType == 'AgentArticle'){
- $data->files = !empty($data['file'][0]) ? str_replace('https://'.config('app.ali_oss_bindurl').'/','',$data['file'][0]) : '';
- }
- $company = Company::where('root_id', '=', $data['root_id'])->field(['id', 'company_name', 'logo', 'company_address', 'root_id'])->find();
- $companyType = Miniprogram::where(['root_id' => $company->root_id])->value('notify');
- $data['company_name'] = $company['company_name'];
- $data['company_logo'] = $company['logo'];
- $data['company_address'] = str_replace(array("\r\n", "\r", "\n"), "", $company['company_address']);
- $data['company_type'] = $companyType;
- //增加浏览次数
- $is_employee = false;
- if (!empty($this->user)) {
- $e_where[] = ['uid', '=', $this->user['id']];
- $e_where[] = ['state', 'in', ['在职', '待审核']];
- if ($this->user['root_id']) {
- $e_where[] = ['root_id', '=', $this->user['root_id']];
- }
- $isEmployee = Employee::where($e_where)->findOrEmpty();
- if (!$isEmployee->isEmpty()) $is_employee = true;
- }
- if (isset($data['view_times']) && !$is_employee) {
- $data->view_times++;
- $data->allowField(['view_times'])->save();
- }
- if (isset($data['hot']) && !$is_employee) {
- $data->hot++;
- $data->allowField(['hot'])->save();
- }
- return $data;
- }
- public function invite()
- {
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $al = request()->param('al');
- $decrypt_arr = explode('&', $aec->decrypt($al));
- $manager = str_replace('is_manager=', '', $decrypt_arr[2]);
- $orgid = str_replace('orgid=', '', $decrypt_arr[0]);
- $orgobj = Org::find($orgid);
- View::assign('manager', $manager == 'false' ? '员工' : '管理员');
- View::assign('orginfo', $orgobj->info);
- View::assign('al', $al);
- return View::fetch();
- }
- public function invitor() //手机端管理者邀请链接生成界面
- {
- //$aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- //
- //$al = input('al');
- //$decrypt_arr = explode('&', $aec->decrypt($al));
- //$orgid = str_replace('orgid=', '', $decrypt_arr[0]);
- //$orgobj = Org::find($orgid);
- //View::assign('orginfo', $orgobj->info);
- //View::assign('orgid', $orgid);
- return View::fetch();
- }
- // public function register()
- // {
- // $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- // $params = request()->param(['al', 'phone', 'name']);
- // $decrypt_arr = explode('&', $aec->decrypt($params['al']));
- // $orgid = str_replace('orgid=', '', $decrypt_arr[0]);
- // $role = str_replace('role=', '', $decrypt_arr[1]);
- // $is_manager = str_replace('is_manager=', '', $decrypt_arr[2]);
- // $is_manager = ($is_manager == 'false') ? 0 : 1;
- // $openid = session('openid');
- // $result = EmployeeLogic::addemployee($params['name'], $params['phone'], $orgid, $openid, $role, $is_manager);
- // if ($result) {
- // return ['code' => 0, 'msg' => '成功提交', 'data' => $result];
- // } else {
- // return ['code' => 1, 'msg' => '提交失败'];
- // }
- // }
- /**
- * 用户报名
- */
- public function signup($p)
- {
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $token);
- $class = 'app\\model\\' . $token['type'];
- $id = intval($token['id']);
- if (!class_exists($class)) return;
- $obj = new $class();
- $objData = $obj->find($id);
- if (empty($objData)) abort(404, '页面不存在');
- $employee_id = isset($token['employee_id']) ? intval($token['employee_id']) : 0;
- $root_id = '';
- if (!empty($employee_id)) {
- $employee = Employee::find($employee_id);
- $org_id = $employee->org_id;
- $root_id = $employee->root_id;
- }
- $e_where[] = ['uid', '=', $this->user['id']];
- $e_where[] = ['state', 'in', ['在职', '待审核']];
- if ($root_id) {
- $e_where[] = ['root_id', '=', $root_id];
- }
- $isEmployee = Employee::where($e_where)->findOrEmpty();
- if (!$isEmployee->isEmpty()) return json(['code' => 1, 'msg' => '员工无需报名']);
- $data = $this->request->only(['name', 'remark', 'mobile']);
- $data = array_filter($data);
- $data['data'] = $objData->toArray();
- $data['uid'] = $this->user['id'];
- $type = input('type', '', 'trim');
- // 新增vr下的报名,vr下报名不限制次数,产品小胖
- $vr_type = ['constructionVr', 'buildingVr', 'materialCaseVr'];
- if (!in_array($type, $vr_type)) {
- // 检测防止重复提交
- $hadList = ModelFootprints::where([['uid', '=', $data['uid']], ['employee_id', '=', $employee_id], ['pipe_type', '=', 'share'], ['reg_info', 'like', '{"mobile":"' . $data['mobile'] . '","data":{"id":' . $data['data']['id'] . ',%']])->select();
- if ($hadList) {
- $keys = array_keys($data['data']);
- foreach ($hadList as $i) {
- $info = json_decode($i->getData('reg_info'), true);
- $data = $info['data'];
- $exitKey = array_keys($data);
- $cha = array_diff($keys, $exitKey);
- if (empty($cha)) {
- if ($token['type'] == "Building") {
- return json(['code' => 1, 'msg' => '您已询问装修成功,请勿重复询问']);
- } elseif ($token['type'] == "MaterialCase") {
- return json(['code' => 1, 'msg' => '您已预约成功,请勿重复预约']);
- } else {
- return json(['code' => 1, 'msg' => '您已报名成功,请勿重复报名']);
- }
- }
- }
- }
- }
- // vr页面报名数据处理
- $vrData = [];
- switch ($type) {
- case 'materialCaseVr':
- $vrData['title'] = '案例"' . $objData['title'] . '"VR';
- $vrData['id'] = $id;
- break;
- case 'buildingVr':
- $vrData['title'] = '热装楼盘"' . $objData['name'] . '"VR';
- $vrData['id'] = $id;
- break;
- case 'constructionVr':
- $vrData['title'] = '在施工地"' . $objData['name'] . '"VR';
- $vrData['id'] = $id;
- break;
- default:
- break;
- }
- if (in_array($type, $vr_type)) {
- $data['data'] = $vrData;
- }
- $share_type = 'share';
- if ($token['type'] == "Building") {
- $share_type = 'askedfitup';
- $data['phone'] = $data['mobile'];
- if (empty($data['phone'])) return json(['code' => 1, 'msg' => '手机号为空']);
- }
- $type = $type ? $type : $share_type;
- //跳过统一添加足迹的控制器数组
- $noaddfoot = ['material_case'];
- // 添加足迹
- if (!empty($data['uid']) && !in_array($type, $noaddfoot)) {
- event(new FootPrints($data['uid'], $employee_id, $org_id ?? 0, $data, $share_type));
- }
- switch ($type) {
- case 'activity':
- if ($root_id && $employee_id && $data['mobile']) {
- // 客户跟进保护规则
- $orgs = orgSubIds($root_id);
- $c_where[] = ['phone|phone1|phone2', '=', cypherphone($data['mobile'])];
- $c_where[] = ['org_id', 'in', $orgs];
- $c_where[] = ['employee_id', '<>', 'null'];
- $c_where[] = ['employee_id', '<>', $employee_id];
- $have_customer = Customer::where($c_where)->select()->toArray();
- $customer_ids = array_column($have_customer, 'id');
- if (!empty($customer_ids)) {
- $yylf_state = CustomerVisitLog::changeState('预约量房', 'chaos');
- $lf_state = CustomerVisitLog::changeState('已量房', 'chaos');
- $yydc_state = CustomerVisitLog::changeState('预约活动', 'chaos');
- $dc_state = CustomerVisitLog::changeState('已到场', 'chaos');
- $yydd_state = CustomerVisitLog::changeState('预约到店', 'chaos');
- $dd_state = CustomerVisitLog::changeState('已到店', 'chaos');
- $sub_setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'subscribe_protected']])->findOrEmpty();
- if (!$sub_setting->isEmpty()) {
- $setting_content = json_decode($sub_setting['content'], true);
- foreach ($setting_content as $k_s => $v_s) {
- if (!empty($v_s['state']) && !empty($v_s['day']) && $v_s['state'] == 1) {
- $continue = false;
- $sub_state = 0;
- $errmsg = '您已有预约,无需重复预约';
- $check_log = false;
- $check_where = [];
- switch ($k_s) {
- case 'liangfang':
- $sub_state = 3;
- $visit_state = 1;
- $check_log = true;
- $check_where[] = ['customer_id', 'in', $customer_ids];
- $check_where[] = ['addtime', '>', date('Y-m-d H:i:s', time() - 24 * 3600 * $v_s['day'])];
- $check_where[] = ['employee_id', 'in', array_column($have_customer, 'employee_id')];
- $check_where[] = ['state', 'in', $lf_state];
- break;
- case 'yliangfang': //预约量房
- $sub_state = 3;
- $visit_state = 0;
- break;
- case 'daodian':
- $sub_state = 1;
- $visit_state = 1;
- $check_log = true;
- $check_where[] = ['customer_id', 'in', $customer_ids];
- $check_where[] = ['addtime', '>', date('Y-m-d H:i:s', time() - 24 * 3600 * $v_s['day'])];
- $check_where[] = ['employee_id', 'in', array_column($have_customer, 'employee_id')];
- $check_where[] = ['state', 'in', $dd_state];
- break;
- case 'ydaodian':
- $sub_state = 1;
- $visit_state = 0;
- break;
- case 'daochang':
- $sub_state = 2;
- $visit_state = 1;
- $check_log = true;
- $check_where[] = ['customer_id', 'in', $customer_ids];
- $check_where[] = ['addtime', '>', date('Y-m-d H:i:s', time() - 24 * 3600 * $v_s['day'])];
- $check_where[] = ['employee_id', 'in', array_column($have_customer, 'employee_id')];
- $check_where[] = ['state', 'in', $dc_state];
- break;
- case 'ydaochang':
- $sub_state = 2;
- $visit_state = 0;
- break;
- default:
- $continue = true;
- break;
- }
- if ($continue) continue;
- // 查询保护时间段内添加的预约量房记录
- unset($v_where);
- $v_where[] = ['customer_id', 'in', $customer_ids];
- $v_where[] = ['addtime', '>', date('Y-m-d H:i:s', time() - 24 * 3600 * $v_s['day'])];
- $v_where[] = ['employee_id', 'in', array_column($have_customer, 'employee_id')];
- $v_where[] = ['type', '=', $sub_state];
- $v_where[] = ['state', '=', $visit_state];
- $sub_list = CustomersSubscribe::where($v_where)->select()->toArray();
- if (!empty($sub_list)) {
- return json(['code' => 1, 'msg' => $errmsg]);
- }
- if ($check_log) {
- $log_list = CustomerVisitLog::where($check_where)->select()->toArray();
- if (!empty($log_list)) {
- return json(['code' => 1, 'msg' => $errmsg]);
- }
- }
- }
- }
- }
- }
- }
- //报名活动成功后建档
- if ($token['type'] == 'Activity' && $root_id && $data['uid'] && $id && $data['mobile'] && $employee_id) {
- $data['aid'] = $id;
- $data['employee_id'] = $employee_id;
- $data['root_id'] = $root_id;
- $this->activitySign($data);
- }
- $new = $this->user['nickname'] . '报名了' . $objData['title'] . '活动,请及时处理';
- if ($employee_id) {
- event(new Msg($employee_id, $new, 'activity', $id));
- }
- break;
- case 'material_case':
- if ($objData['designer_id']) {
- $designer = Employee::where('id', $objData['designer_id'])->find();
- if (!$designer->isEmpty()) {
- $new = $this->user['nickname'] . '预约了' . $designer['name'] . '设计师,请及时跟进';
- if ($employee_id) {
- event(new Msg($employee_id, $new, 'material_case'));
- // 通知到设计师
- /*$d_msg = "“" . $employee['nickname'] . "”名下的“" . $this->user['nickname] . "”预约了您,请及时沟通";
- event(new Msg($objData['designer_id'], $d_msg, 'designer'));*/
- }
- $designer_data['designer_id'] = $objData['designer_id'];
- $designer_data['uid'] = $this->user['id'];
- $designer_data['employee_id'] = $employee_id;
- $designer_data['pipe_type'] = 'materialCase';
- $designer_data['data_id'] = $id;
- $designer_data['root_id'] = $designer['root_id'];
- DesignerReserve::create($designer_data);
- $d_where[] = ['id', '=', $objData['designer_id']];
- $d_where[] = ['root_id', '=', $designer['root_id']];
- $root_id = $designer['root_id'];
- $designer_find = Employee::with(['designer' => function ($query) use ($root_id) {
- $query->where('root_id', $root_id)->visible(['headimgurl', 'employee_id', 'desc', 'good_at', 'position', 'work_years', 'addtime', 'good_house', 'design_concept', 'vcr', 'id designer_id'])->bind(['desc', 'good_at', 'position', 'work_years', 'addtime', 'good_house', 'design_concept', 'vcr', 'name', 'headimgurl']);
- }])->where($d_where)->field('name title,id,show,id designer_id,root_id')->findOrEmpty();
- $designer_find['share_pipe_type'] = 'materialCase';
- $designer_find['share_data_id'] = $id;
- $designer_find['mobile'] = !empty($data['mobile']) ? $data['mobile'] : '未获取';
- event(new FootPrints($data['uid'], $employee_id, $org_id ?? 0, $designer_find, 'designer'));
- } else {
- $new = $this->user['nickname'] . '预约了设计师,请及时跟进';
- if ($employee_id) {
- event(new Msg($employee_id, $new, 'material_case'));
- }
- }
- } else {
- $designer_find['share_pipe_type'] = 'materialCase';
- $designer_find['share_data_id'] = $id;
- $designer_find['mobile'] = !empty($data['mobile']) ? $data['mobile'] : '';
- event(new FootPrints($data['uid'], $employee_id ?? 0, $org_id ?? 0, $designer_find, 'designer'));
- }
- break;
- case 'video':
- $new = $this->user['nickname'] . '预约了装修服务,请及时跟进';
- if ($employee_id) {
- event(new Msg($employee_id, $new, 'video'));
- }
- break;
- default:
- break;
- }
- return json(['code' => 0, 'msg' => '报名成功']);
- }
- /**
- * 活动报名成功后,建档,邀约
- */
- private function activitySign($data)
- {
- $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
- $phone = $aec->encrypt($data['mobile']);
- //建档
- $orgs = Org::where([['path', 'like', $data['root_id'] . '-%']])->column('id');
- $customer = Customer::where([['phone|phone1|phone2', '=', $phone], ['org_id', 'in', $orgs], ['employee_id', '=', $data['employee_id']]])->findOrEmpty();
- $employee = Employee::where('id', $data['employee_id'])->field('id,uid,org_id')->find();
- $aw[] = ['phone|phone1|phone2', '=', $phone];
- $aw[] = ['org_id', 'in', $orgs];
- $aw[] = ['is_resource','=',0];
- $customer_list = Customer::where($aw)->select()->toArray();
- $have_customer = [];
- foreach($customer_list as $k => $v) {
- if ($v['employee_id'] > 0 && $v['employee_id'] != $data['employee_id']) {
- $have_customer[] = $v;
- }
- }
- $empcrm_repeat[] = ['root_id', '=', $data['root_id']];
- $empcrm_repeat[] = ['name', '=', 'empcrm_customer_repeat'];
- $repeat_setting = Setting::where($empcrm_repeat)->findOrEmpty();
- //判断同部门
- if (!$repeat_setting->isEmpty()) {
- $repeat_org = explode(',', $repeat_setting['content']);
- if (!in_array($employee['org_id'], $repeat_org)) {
- $repeat_org = [$employee['org_id']];
- }
- } else {
- $repeat_org = [$employee['org_id']];
- }
- // 需要验证
- if (!empty($have_customer)) {
- foreach ($have_customer as $ex) {
- if (in_array($ex['org_id'], $repeat_org)) {
- $have_emp = Employee::where('id', '=', $ex['employee_id'])->value('name');
- return json(['code' => 1, 'msg' => '您已是' . $have_emp . '的客户,请联系他预约']);
- }
- }
- }
- if ($customer->isEmpty()) {
- $save = [];
- $save['uid'] = $data['uid'];
- $save['employee_id'] = $data['employee_id'];
- $save['clue_id'] = CustomerClue::where([['uid', '=', $data['uid']], ['org_id', 'in', $orgs], ['employee_id', '=', $data['employee_id']]])->value('id') ?: 0;
- $save['phone'] = $phone;
- $save['name'] = $data['name'] ?: User::where('id', $data['uid'])->value('nickname');
- $save['state'] = 0;
- $save['org_id'] = $employee->org_id;
- $save['remark'] = 'h5活动报名建档';
- $save['sex'] = 1;
- $cid = Customer::insertGetId($save);
- } else {
- $cid = $customer->id;
- }
- //邀约活动
- $save = [];
- $save['customer_id'] = $cid;
- $save['type'] = 3;
- $save['next_contact_date'] = date('Y-m-d');
- $save['remark'] = '活动邀约';
- $save['employee_id'] = $data['employee_id'];
- $save['user_id'] = $data['uid'];
- $save['state'] = 6;
- $save['aid'] = $data['aid'];
- CustomerVisitLog::insertGetId($save);
- // $update['state'] = 0;//不改变客户之前的状态
- $update['uid'] = $data['uid'];
- $update['aid'] = $data['aid'];
- $update['revisit_time'] = date('Y-m-d');
- $update['last_contact_date'] = date('Y-m-d');
- $update['updatetime'] = date('Y-m-d H:i:s');
- Customer::where('id', $cid)->update($update);
- //预约表添加数据
- $subscribe = [
- 'customer_id' => $cid,
- 'subscribe_date' => date('Y-m-d'),
- 'employee_id' => $data['employee_id'],
- 'type' => 2,
- 'aid' => (int)$data['aid'],
- 'org_id' => $employee->org_id
- ];
- CustomersSubscribe::insertGetId($subscribe);
- //二维码内容,活动id,报名人uid
- $qrcode_con = $data['aid'] . '&' . $cid . '&' . $data['uid'];
- $cate = Activity::where('id', $data['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' => $data['aid'],
- 'root_id' => $data['root_id'],
- 'uid' => $data['uid'],
- 'share_uid' => $employee->uid,
- 'share_employee_id' => $data['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;
- return $url;
- }
- /**
- * 获取装修设计方案报名
- */
- public function getDecorationDesign($p)
- {
- // 解析获取分享人信息
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $token);
- // 查询员工信息
- $employee_id = isset($token['employee_id']) ? intval($token['employee_id']) : 0;
- $root_id = '';
- if (!empty($employee_id)) {
- $employee = Employee::find($employee_id);
- $org_id = $employee->org_id;
- $root_id = $employee->root_id;
- }
- $e_where[] = ['uid', '=', $this->user['id']];
- $e_where[] = ['state', 'in', ['在职', '待审核']];
- if ($root_id) {
- $e_where[] = ['root_id', '=', $root_id];
- }
- $isEmployee = Employee::where($e_where)->findOrEmpty();
- if (!$isEmployee->isEmpty()) return json(['code' => 1, 'msg' => '员工无需报名']);
- // 检测防止重复提交
- $hadList = ModelFootprints::where([['uid', '=', $this->user['id']], ['employee_id', '=', $employee_id], ['pipe_type', '=', 'getDecorationDesign']])->count();
- if ($hadList) {
- return json(['code' => 1, 'msg' => '您已报名成功,请勿重复报名']);
- }
- // 初始化类型
- $msgType = [
- 'Article' => ['拓客图文', 'title'],
- 'MaterialCase' => ['案例', 'title'],
- 'Building' => ['热装楼盘', 'name'],
- 'Construction' => ['在施工地', 'name'],
- 'MaterialEvidence' => ['客户好评', 'title'],
- 'Video' => ['拓客视频', 'title'],
- 'CompanyStrength' => ['公司实力', 'title']
- ];
- // 判断类型是否正确
- if (!isset($msgType[$token['type']])) return json(['code' => 1, 'msg' => '类型不存在']);
- // 获取分享内容
- $class = 'app\\model\\' . $token['type'];
- $id = intval($token['id']);
- $obj = new $class();
- $objData = $obj->find($id);
- if (empty($objData)) return json(['code' => 1, 'msg' => '内容不存在']);
- // 获取报名信息
- $data = $this->request->only(['community', 'area', 'bedroom', 'mobile']);
- $data = array_filter($data);
- $data['data'] = $objData->toArray();
- $data['uid'] = $this->user['id'];
- event(new FootPrints($data['uid'], $employee_id, $org_id ?? 0, $data, 'getDecorationDesign'));
- $msg = $this->user['nickname'] . '在' . $msgType[$token['type']][0] . '《' . $objData[$msgType[$token['type']][1]] . '》中申请获取装修方案,请及时处理';
- event(new Msg($employee_id, $msg, Str::snake($token['type'])));
- // 更新线索电话
- $condition = [
- 'employee_id' => $employee_id,
- 'uid' => $this->user['id'],
- 'org_id' => $org_id ?? 0
- ];
- // 建立线索关系
- $had = CustomerClue::where($condition)->find();
- if (empty($had->phone)) {
- $had->phone = $data['mobile'];
- $had->save();
- }
- return json(['code' => 0, 'msg' => '报名成功']);
- }
- /**
- * 报价
- */
- public function quote($p)
- {
- $params = $this->request->only(['area', 'room', 'hall', 'bathroom', 'phone']);
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $token);
- $params['uid'] = $this->user['id'];
- $params['employee_id'] = isset($token['employee_id']) ? intval($token['employee_id']) : 0;
- $root_id = '';
- if (!empty($params['employee_id'])) {
- $employee = Employee::find($params['employee_id']);
- $org_id = $employee->org_id;
- $root_id = $employee->root_id;
- }
- $params['root_id'] = $root_id;
- $e_where[] = ['uid', '=', $this->user['id']];
- $e_where[] = ['state', 'in', ['在职', '待审核']];
- if ($root_id) {
- $e_where[] = ['root_id', '=', $root_id];
- }
- $isEmployee = Employee::where($e_where)->findOrEmpty();
- if (!$isEmployee->isEmpty()) return json(['code' => 1, 'msg' => '员工无需报价']);
- $id = QuoteRecordModel::insertGetId($params);
- $info = QuoteRecordModel::find($id);
- event(new FootPrints($this->user['id'], $params['employee_id'], $org_id ?? 0, $info, 'quote'));
- return json(['code' => 0, 'msg' => '恭喜您成功获取报价,稍后会有服务顾问跟您联系']);
- }
- /**
- * 楼盘催更新
- */
- public function urge()
- {
- $building_id = input('building_id', '', 'intval');
- $employee_id = input('employee_id', '', 'intval');
- $phone = input('mobile');
- $uid = $this->user['id'];
- $data['building_id'] = $building_id;
- $data['urge_uid'] = $uid;
- $data['employee_id'] = $employee_id;
- $data['root_id'] = Employee::where('id', $employee_id)->value('root_id');
- $result = BuildingUrge::create($data);
- if ($result) {
- $user = User::find($uid);
- $user_name = '客户';
- $user_phone = $phone ? $phone : '未获取';
- if (!empty($user)) {
- $user_name = $user['nickname'];
- }
- $building = BuildingModel::find($building_id);
- if (!empty($building)) {
- event(new Msg($employee_id, $user_name . '于' . date('Y-m-d H:i:s') . ' 催更' . $building['name'] . '施工进展。', 'building', $building_id));
- if (!empty($uid)) {
- $org_id = Employee::where('id', '=', $employee_id)->value('org_id');
- $building['phone'] = $user_phone;
- event(new FootPrints($uid, $employee_id, $org_id, $building, 'building_urge'));
- }
- }
- return json(['code' => 0, 'msg' => '催更成功']);
- } else {
- return json(['code' => 1, 'msg' => '操作失败']);
- }
- }
- public function construction()
- {
- $id = input('construction_id', '', 'intval');
- $p = input('p', '', 'trim');
- $data = $this->getContent($id, 'Construction');
- // 设置分享链接
- $jssdk = new JsSdk();
- $appid = config('app.official_appid');
- if (cache('?jsapi_ticket')) {
- $ticket = cache('jsapi_ticket');
- } else {
- // 获取普通access_token
- if (!$token = Cache::get('zqxg_offi_access_token')) {
- $token = getAccessToken($appid, config('app.official_secret'));
- Cache::set('zqxg_offi_access_token', $token, 7100);
- }
- $ticket = $jssdk->getJsApiTicket($token);
- cache('jsapi_ticket', $ticket, 7200);
- }
- $signPackage = $jssdk->getSignPackage($ticket);
- $signPackage['appid'] = $appid;
- View::assign('wxconfig', $signPackage);
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $pArr);
- // 分享内容获取
- if (empty($data)) abort(404, '页面不存在');
- $employee_id = isset($pArr['employee_id']) ? intval($pArr['employee_id']) : 0;
- $leftToEmpId = Employee::where(['id' => $employee_id, 'state' => '离职'])->value('left_to_empid');
- if ($leftToEmpId) $employee_id = $leftToEmpId;
- $r = input('r');
- View::assign('r', $r);
- View::assign('p', $p);
- View::assign('getPhone', false);
- $data['share_employee'] = Employee::with(['user' => function ($query) {
- $query->field('id,headimgurl');
- }])->where(['id' => $employee_id])->field('id,uid,name,phone,qrcode,org_id')->find();
- $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
- if (!empty($this->user)) {
- // 分享关系创建
- if (!empty($data['share_employee'])) {
- $clue = $this->addClue($employee_id);
- if (!empty($clue) && $clue->phone)
- View::assign('getPhone', true);
- event(new FootPrints($this->user['id'], $data['share_employee']['id'], $data['share_employee']['org_id'], $data, lcfirst($pArr['type'])));
- $foot = ModelFootprints::where(['uid' => $this->user['id'], 'employee_id' => $data['share_employee']['id'], 'pipe_type' => lcfirst($pArr['type']), 'org_id' => $data['share_employee']['org_id']])->field('id,addtime')->order('addtime desc')->find();
- if ($foot) $visit = $foot->toArray();
- }
- View::assign('authorize', true);
- } else {
- View::assign('authorize', false);
- }
- View::assign('visit', $visit);
- View::assign('data', $data);
- return View::fetch();
- }
- //用户通过经纪人分享的活动报名
- public function agent_actsing()
- {
- $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 ($this->user['id'] == $agtdata['uid']) return json(['code' => 1, 'msg' => '您的身份是经纪人,不能参加活动']);
- $isEmployee = Employee::where(['uid' => $this->user['id']])->find();
- if ($isEmployee) 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'] = $this->user['id'];
- $data['name'] = $this->user['nickname'];
- $data['sex'] = !empty($param['sex']) ? $param['sex'] : 1;
- $orgids = orgSubIds(!empty($this->user['root_id']) ? $this->user['root_id'] : $agtdata['root_id']);
- // 新建档,检测手机号是否重复
- $pharr = [$param['phone']];
- $tips = (new AgentsLogic())->checkPepeat($pharr, $orgids);
- if (!empty($tips)) return $tips;
- //检测用户是否已经建过档
- $aw[] = ['uid', '=', $this->user['id']];
- $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 . '&' . $this->user['id'];
- $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' => $this->user['id'],
- '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' => '报名成功.']);
- } else {
- return json(['code' => 1, 'msg' => '报名失败.']);
- }
- }
- //热装楼盘进度类型筛选
- public function progress()
- {
- $id = input('id', '', 'intval');
- $type = input('type', '', 'trim');
- $where[] = ['building_id', '=', $id];
- if (!empty($type)) {
- $where[] = ['type', '=', $type];
- }
- $list = BuildingProgress::where($where)->order('addtime desc')->select();
- if (empty($list)) $list = [];
- else $list = $list->toArray();
- $vrObj = new Vr();
- foreach ($list as &$item) {
- if (empty($item['vr'])) {
- $item['vr'] = [];
- continue;
- }
- $vrUrlList = explode(',', $item['vr']);
- $vrData = [];
- foreach ($vrUrlList as $url) {
- $vrData[] = [
- 'vrUrl' => urlencode($url),
- 'vrfirstImg' => $vrObj->getFirstImg($url)
- ];
- }
- $item['vr'] = $vrData;
- }
- return json(['code' => 0, 'data' => $list]);
- }
- //热装楼盘关联的案例
- public function material_case()
- {
- $param = $this->request->param();
- $building_id = input('building_id', '', 'intval');
- $p = input('p');
- $r = input('r');
- if (!empty($p)) {
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $pArr);
- }
- $room = input('room', '', 'intval');
- $c_where[] = ['building_id', '=', $building_id];
- if (!empty($room)) {
- $housetype_id = BuildingHousetype::where([['room', '=', $room], ['building_id', '=', $building_id]])->column('id');
- $c_where[] = ['housetype_id', 'in', $housetype_id];
- }
- $ht_ids = BuildingMaterialCase::where([['building_id', '=', $building_id]])
- ->group('housetype_id')
- ->field('housetype_id,count(*)as count')
- ->select()
- ->toArray();
- if (!empty($ht_ids)) {
- foreach ($ht_ids as $key => $val) {
- $ht_ids[$key]['room'] = BuildingHousetype::where('id', $val['housetype_id'])->value('room');
- }
- foreach ($ht_ids as $key => $val) {
- $xin[$val['room']][] = $val;
- }
- $acn = 0;
- foreach ($xin as $key => $val) {
- $cn = 0;
- foreach ($val as $k => $v) {
- $cn += $v['count'];
- $acn += $v['count'];
- }
- $a = ['room' => $key, 'count' => $cn];
- $xa[] = $a;
- }
- $xa[] = ['room' => 0, 'count' => $acn];
- }
- $housetype_list = !empty($xa) ? $xa : [];
- $case_ids = BuildingMaterialCase::where($c_where)->column('material_case_id');
- $where[] = ['id', 'in', $case_ids];
- setCondition($param, 'style_id', '=', $where);
- setCondition($param, ['square_start', 'square'], '>=', $where);
- setCondition($param, ['square_end', 'square'], '<', $where);
- setCondition($param, ['keyword', 'title'], ['like', '%VALUE%'], $where);
- $page = !empty($param['page']) ? $param['page'] : 1;
- $limit = !empty($param['limit']) ? $param['limit'] : 15;
- $list = MaterialCase::with(['designer' => function ($query) {
- $query->field('id,name, headimgurl,addtime');
- }, 'community' => function ($query) {
- $query->field('id,name');
- }, 'decostyle' => function ($query) {
- $query->field('id,name');
- }])->where($where)->page($page, $limit)->select();
- $collectedIds = UserCollect::where(['user_id' => !empty($this->user['id']) ? $this->user['id'] : 0, 'content_type' => 'materialCase'])->column('content_id');
- foreach ($list as &$item) {
- if (in_array($item['id'], $collectedIds)) {
- $item['collected'] = true;
- } else {
- $item['collected'] = false;
- }
- $param = [
- 'id' => $item['id'],
- 'type' => 'MaterialCase',
- 'employee_id' => !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0
- ];
- $param = http_build_query($param);
- $aes = new Aes(config('app.jwt_key'));
- $query = 'index/index/content/r/' . $r . '/p/' . $aes->encrypt($param);
- $domain = request()->domain();
- $url = $domain . '/' . $query;
- $item['url'] = $url;
- if (!empty($item['vr_case'])) {
- $item['vr_case'] = urlencode($item['vr_case']);
- }
- }
- $data = ['list' => $list, 'housetype_list' => $housetype_list];
- return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
- }
- //研发案例列表
- public function dev_case_list()
- {
- $id = input('id', '', 'intval');
- if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']);
- $list = BuildingDevelopCase::with(['decostyles'])->where('housetype_id', $id)
- ->field('id,name,type,housetype_id,decostyles_id')
- ->select();
- return json(['code' => 0, 'data' => $list]);
- }
- //研发案例详情
- public function dev_case_detail()
- {
- $id = input('id', '', 'intval');
- $p = input('p');
- $r = input('r');
- if (!empty($p)) {
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $pArr);
- }
- $employee_id = !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0;
- $uid = 0;
- if (!empty($this->user)) {
- $uid = $this->user['id'];
- }
- if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']);
- $data = BuildingDevelopCase::with(['decostyles'])->where('id', $id)->find();
- if (!empty($data['vr_link'])) {
- $data['vr_link'] = urlencode($data['vr_link']);
- }
- $domain = request()->domain();
- $data['cont_link'] = $domain . '/index/index/dev_case_details.html?r=' . $r . '&id=' . $data['id'] . '&p=' . $p;
- if (!empty($uid)) {
- $org_id = Employee::where('id', '=', $employee_id)->value('org_id');
- event(new FootPrints($uid, $employee_id, $org_id, $data, 'devcase'));
- }
- return json(['code' => 0, 'data' => $data]);
- }
- //研发案例h5图文详情
- public function dev_case_details()
- {
- $id = input('id');
- $r = input('r');
- $p = input('p');
- if (empty($id)) {
- echo '参数错误';
- exit;
- }
- $data = BuildingDevelopCase::with(['decostyles'])->where('id', $id)->find();
- $share_content = strip_tags(preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $data['content']));
- View::assign('share_content', $share_content);
- if (!empty($p)) {
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $pArr);
- }
- $building_id = !empty($pArr['id']) ? $pArr['id'] : 0;
- if (!empty($building_id)) {
- $building_data = BuildingModel::where('id', $building_id)->find()->toArray();
- }
- View::assign('share_img', !empty($building_data['cover'][0]) ? $building_data['cover'][0] : '');
- // 设置分享链接
- $jssdk = new JsSdk();
- $appid = config('app.official_appid');
- if (cache('?jsapi_ticket')) {
- $ticket = cache('jsapi_ticket');
- } else {
- // 获取普通access_token
- if (!$token = Cache::get('zqxg_offi_access_token')) {
- $token = getAccessToken($appid, config('app.official_secret'));
- Cache::set('zqxg_offi_access_token', $token, 7100);
- }
- $ticket = $jssdk->getJsApiTicket($token);
- cache('jsapi_ticket', $ticket, 7200);
- }
- $signPackage = $jssdk->getSignPackage($ticket);
- $signPackage['appid'] = $appid;
- View::assign('wxconfig', $signPackage);
- $employee_id = !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0;
- $uid = 0;
- $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
- if (!empty($this->user)) {
- $uid = $this->user['id'];
- }
- if (!empty($uid)) {
- $org_id = Employee::where('id', '=', $employee_id)->value('org_id');
- event(new FootPrints($uid, $employee_id, $org_id, $data, 'devcase'));
- $foot = ModelFootprints::where(['uid' => $this->user['id'], 'employee_id' => $employee_id, 'pipe_type' => 'devcase', 'org_id' => $org_id])->field('id,addtime')->order('addtime desc')->find();
- if ($foot) $visit = $foot->toArray();
- }
- View::assign('visit', $visit);
- View::assign('data', $data);
- View::assign('r', $r);
- View::assign('p', $p);
- if (!empty($this->user)) {
- $share_employee_id = Employee::where(['id' => $employee_id])->value('id');
- // 分享关系创建
- if (!empty($share_employee_id)) {
- $this->addClue($employee_id);
- }
-
- View::assign('authorize', true);
- } else {
- View::assign('authorize', false);
- }
- return View::fetch();
- }
- //楼盘进度详情
- public function progress_detail()
- {
- $id = input('id');
- $r = input('r');
- $p = input('p');
- if (empty($id)) {
- echo '参数错误';
- exit;
- }
- $data = BuildingProgress::where('id', $id)->find();
- $building_data = BuildingModel::where('id', $data['building_id'])->find();
- $data['building_name'] = $building_data['name'];
- $vrObj = new Vr();
- if ($data['type'] == 'vr') {
- $vrUrlList = explode(',', $data['vr']);
- $vrData = [];
- foreach ($vrUrlList as $url) {
- $vrData[] = [
- 'vrUrl' => urlencode($url),
- 'vrfirstImg' => $vrObj->getFirstImg($url)
- ];
- }
- $data['vr'] = $vrData;
- }
- $share_content = strip_tags(preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $data['content']));
- View::assign('share_content', $share_content);
- if (!empty($p)) {
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $pArr);
- }
- // $building_id = !empty($pArr['id']) ? $pArr['id'] : 0;
- // if (!empty($building_id)) {
- // $building_data = BuildingModel::where('id', $building_id)->find()->toArray();
- // }
- View::assign('share_img', !empty($building_data['cover'][0]) ? $building_data['cover'][0] : '');
- // 设置分享链接
- $jssdk = new JsSdk();
- $appid = config('app.official_appid');
- if (cache('?jsapi_ticket')) {
- $ticket = cache('jsapi_ticket');
- } else {
- // 获取普通access_token
- if (!$token = Cache::get('zqxg_offi_access_token')) {
- $token = getAccessToken($appid, config('app.official_secret'));
- Cache::set('zqxg_offi_access_token', $token, 7100);
- }
- $ticket = $jssdk->getJsApiTicket($token);
- cache('jsapi_ticket', $ticket, 7200);
- }
- $signPackage = $jssdk->getSignPackage($ticket);
- $signPackage['appid'] = $appid;
- View::assign('wxconfig', $signPackage);
- $employee_id = !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0;
- $data['share_employee'] = Employee::with(['user' => function ($query) {
- $query->field('id,headimgurl');
- }])->where(['id' => $employee_id])->field('id,uid,name,phone,qrcode,org_id')->find();
- $companyType = Miniprogram::where(['root_id' => $r])->value('notify');
- $data['company_type'] = $companyType;
-
- $uid = 0;
- $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
- if (!empty($this->user)) {
- $uid = $this->user['id'];
- }
- if (!empty($uid)) {
- $org_id = Employee::where('id', '=', $employee_id)->value('org_id');
- event(new FootPrints($uid, $employee_id, $org_id, $data, 'progressDetail'));
- $foot = ModelFootprints::where(['uid' => $this->user['id'], 'employee_id' => $employee_id, 'pipe_type' => 'progressDetail', 'org_id' => $org_id])->field('id,addtime')->order('addtime desc')->find();
- if ($foot) $visit = $foot->toArray();
- }
- // 公司名获取
- $data['company_name'] = Company::where(['root_id' => $r])->value('company_name');
- View::assign('visit', $visit);
- View::assign('data', $data);
- View::assign('r', $r);
- View::assign('p', $p);
- if (!empty($this->user)) {
- $share_employee_id = Employee::where(['id' => $employee_id])->value('id');
- // 分享关系创建
- if (!empty($share_employee_id)) {
- $this->addClue($employee_id);
- }
- View::assign('authorize', true);
- } else {
- View::assign('authorize', false);
- }
- return View::fetch();
- }
- //热装楼盘户型接口
- public function houseroom_list()
- {
- $id = input('id', '', 'intval');
- //小区户型
- $housetype = BuildingHousetype::with(['devcase' => function ($query) {
- $query->field('housetype_id,id,name,type,vr_link,content,cover,decostyles_id');
- }])->where('building_id', '=', $id)->withCount(['materialCase'])->select();
- $xin = null;
- $vrObj = new Vr();
- if (!empty($housetype->toArray())) {
- $domain = request()->domain();
- $houselist = $housetype->toArray();
- foreach ($houselist as $key => $val) {
- if (empty($val['house_img']) && !empty($val['vr_link'])) {
- $houselist[$key]['house_img'][] = $vrObj->getFirstImg($val['vr_link']);
- }
- if (empty($val['devcase'])) continue;
- foreach ($val['devcase'] as $k => $v) {
- $houselist[$key]['devcase'][$k]['decostyles_name'] = Decostyle::where('id', $v['decostyles_id'])->value('name');
- $houselist[$key]['devcase'][$k]['area'] = $val['area'];
- $houselist[$key]['devcase'][$k]['room'] = $val['room'];
- $houselist[$key]['devcase'][$k]['hall'] = $val['hall'];
- $houselist[$key]['devcase'][$k]['bathroom'] = $val['bathroom'];
- if (!empty($v['vr_link'])) {
- $houselist[$key]['devcase'][$k]['vr_link'] = urlencode($v['vr_link']);
- }
- if ($v['type'] == 1) {
- $houselist[$key]['devcase'][$k]['cover'] = $vrObj->getFirstImg($v['vr_link']);
- }
- }
- if (!empty($val['vr_link'])) {
- $houselist[$key]['vr_link'] = urlencode($val['vr_link']);
- }
- }
- foreach ($houselist as $key => $val) {
- $houselist[$key]['housetype_cont_link'] = $val['housetype_cont_link'] = $domain . '/index/index/housetype.html?r=' . $val['root_id'] . '&id=' . $val['id'];
- $xin[$val['room']][] = $val;
- }
- $xin[0] = $houselist;
- }
- return json(['code' => 0, 'list' => $xin, 'msg' => '获取成功']);
- }
- //h5户型详情
- public function housetype()
- {
- $id = input('id', '', 'intval');
- $r = input('r');
- $p = input('p');
- if (empty($id)) {
- echo '参数错误';
- exit;
- }
- View::assign('r', $r);
- $info = $data = BuildingHousetype::where([['id','=',$id],['root_id','=',$r]])->findOrEmpty();
- if($info->isEmpty()){
- echo '参数错误';
- exit;
- }
- $info['new_orientation'] = $info->getData('orientation');
- $info['vr_link_img'] = '';
- if (!empty($info['vr_link'])) {
- $vrObj = new Vr();
- $info['vr_link_img'] = $vrObj->getFirstImg($info['vr_link']);
- }
- View::assign('info', $info);
- View::assign('p', $p);
- //查询楼盘地址和小区
- $build = BuildingModel::where('id',$info->building_id)->field('community_id,address')->findOrEmpty();
- if (!$build->isEmpty()){
- $build->community = $build->community_id ? Community::where('id',$build->community_id)->value('name') : '';
- }
- View::assign('build', $build);
- //分享人信息
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $pArr);
- $employee_id = isset($pArr['employee_id']) ? intval($pArr['employee_id']) : 0;
- $leftToEmpId = Employee::where(['id' => $employee_id, 'state' => '离职'])->value('left_to_empid');
- if ($leftToEmpId) $employee_id = $leftToEmpId;
- //关联案例
- $case_ids = BuildingMaterialCase::where([['housetype_id','=',$id],['root_id','=',$r]])->column('material_case_id');
- $case = [];
- if($case_ids){
- $where[] = ['id', 'in', $case_ids];
- $case = MaterialCase::with(['decostyle' => function ($query) {
- $query->field('id,name')->bind(['decostyle_name'=>'name']);
- }])->where($where)->limit(4)->select()->toArray();
- }
- foreach ($case as &$item) {
- $param = [
- 'id' => $item['id'],
- 'type' => 'MaterialCase',
- 'employee_id' => !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0
- ];
- $param = http_build_query($param);
- $query = 'index/index/content/r/' . $r . '/p/' . $aes->encrypt($param);
- $domain = request()->domain();
- $url = $domain . '/' . $query;
- $item['url'] = $url;
- if (!empty($item['vr_case'])) {
- $item['vr_case'] = urlencode($item['vr_case']);
- }
- }
- View::assign('case', $case);
- //关联在施工地
- $construction_id = $info->constructionid ? explode(',',$info->constructionid) : [];
- $where = [];
- $where[] = ['id', 'in', $construction_id];
- $where[] = ['root_id', '=', $r];
- $con = ConstructionModel::with(['housetype','community'])->where($where)->limit(4)->select()->toArray();
- //施工进程查询
- $record_list = ConstructionRecord::where([['construction_id', 'in', array_column($con,'id')]])->group('construction_id')->column('max(step_id)','construction_id');
- $sid = array_values($record_list);
- $step_list = ConstructionStep::where([['root_id', '=', $r]])->column('name,id');
- $step_arr = array_column($step_list,'name','id');
- $now_step = !empty($step_list[0]['name']) ? $step_list[0]['name'] : '';//第一个施工进度
- foreach ($con as $key => $value) {
- $con[$key]['hname'] = isset($value['housetype']['name']) ? $value['housetype']['name'] : '';
- $con[$key]['cname'] = isset($value['community']['name']) ? $value['community']['name'] : '';
- //施工进度
- $con[$key]['progress'] = !isset($record_list[$value['id']]) ? $now_step : $step_arr[$record_list[$value['id']]];
- $param = [
- 'id' => $value['id'],
- 'type' => 'construction',
- 'employee_id' => !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0
- ];
- $param = http_build_query($param);
- $con[$key]['p'] = $aes->encrypt($param);
- }
- View::assign('con', $con);
- View::assign('getPhone', false);
- $data['share_employee'] = Employee::with(['user' => function ($query) {
- $query->field('id,headimgurl');
- }])->where(['id' => $employee_id])->field('id,uid,name,phone,qrcode,org_id')->find();
- $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
- if (!empty($this->user)) {
- // 分享关系创建
- if (!empty($data['share_employee'])) {
- $clue = $this->addClue($employee_id);
- if (!empty($clue) && $clue->phone)
- View::assign('getPhone', true);
- event(new FootPrints($this->user['id'], $data['share_employee']['id'], $data['share_employee']['org_id'], $data, lcfirst($pArr['type'])));
- $foot = ModelFootprints::where(['uid' => $this->user['id'], 'employee_id' => $data['share_employee']['id'], 'pipe_type' => lcfirst($pArr['type']), 'org_id' => $data['share_employee']['org_id']])->field('id,addtime')->order('addtime desc')->find();
- if (isset($foot)) $visit = $foot->toArray();
- }
- View::assign('authorize', true);
- } else {
- View::assign('authorize', false);
- }
- View::assign('visit', $visit);
- $company = Company::where('root_id', '=', $r)->field(['id', 'company_name', 'logo', 'company_address', 'root_id'])->find();
- $companyType = Miniprogram::where(['root_id' => $r])->value('notify');
- $data['company_name'] = $company['company_name'];
- $data['company_logo'] = $company['logo'];
- $data['company_address'] = $company['company_address'];
- $data['company_type'] = $companyType;
- $data['name'] = $info->room.'室'.$info->hall.'厅'.$info->bathroom.'卫';
- View::assign('data', $data);
- // 设置分享链接
- $jssdk = new JsSdk();
- $appid = config('app.official_appid');
- if (cache('?jsapi_ticket')) {
- $ticket = cache('jsapi_ticket');
- } else {
- // 获取普通access_token
- if (!$token = Cache::get('zqxg_offi_access_token')) {
- $token = getAccessToken($appid, config('app.official_secret'));
- Cache::set('zqxg_offi_access_token', $token, 7100);
- }
- $ticket = $jssdk->getJsApiTicket($token);
- cache('jsapi_ticket', $ticket, 7200);
- }
- $signPackage = $jssdk->getSignPackage($ticket);
- $signPackage['appid'] = $appid;
- View::assign('wxconfig', $signPackage);
- View::assign('share_content', $build->community);
- View::assign('share_img', $info->house_img ? $info->house_img[0] : ($info['vr_link_img'] ?: ''));
- return View::fetch();
- }
- //热装楼盘关联案例风格接口
- public function housetype_list()
- {
- $r = input('r', '', 'intval');
- $styleArr = Decostyle::where([['root_id', '=', $r]])->where([['type', '=', 0]])->field('id, name')->select();
- return json(['code' => 0, 'data' => $styleArr, 'msg' => '获取成功']);
- }
- /**
- * 已存在的客户访问新店面时,复制user信息
- * @param $user
- * @param $new_root
- */
- private function copyUser($user, $new_root)
- {
- $where[] = ['unionid', '=', $user['unionid']];
- $where[] = ['root_id', '=', $new_root];
- $find = User::where($where)->findOrEmpty();
- if ($find->isEmpty()) {
- unset($user['id']);
- $user['root_id'] = $new_root;
- $user = User::create($user);
- $this->user = $user;
- } else {
- $this->user = $find;
- }
- }
- /**
- * 修改浏览时长
- */
- public function visitDueTime()
- {
- $id = input('id');
- $visit_time = input('visit_time');
- $time = input('time');
- $where = ['id' => $id, 'addtime' => $visit_time];
- ModelFootprints::where($where)->update(['visit_due_time' => $time]);
- //增加记录素材的浏览时长到素材表
- $data = ModelFootprints::where($where)->find();
- $reg_info = !empty($data['reg_info']) ? json_decode($data->getData('reg_info'),true) : ['id'=>0];
- if(!empty($time) && !empty($data['pipe_type']) && in_array($data['pipe_type'],['article','materialEvidence','materialCase','CompanyStrength','video'])){
- $class = 'app\\model\\' . ucfirst($data['pipe_type']);
- if (!class_exists($class)) return json(['code' =>1, 'msg' => '类型不存在']);
- $datas = (new $class())->where(['id' => $reg_info['id']])->find();
- $old_due_time = $datas->visit_due_time;
- $datas->visit_due_time = $old_due_time + $time;
- $datas->save();
- }
- return json(['code' => 0, 'msg' => '操作成功']);
- }
- /**
- * vr展示页面
- * @param [type] $p [description]
- * @return [type] [description]
- */
- public function vr($p)
- {
- $param = $this->request->only(['id', 'type', 'vr_link']);
- if (!in_array($param['type'], ['materialCase', 'building', 'construction', 'company','buildingHousetype'])) {
- return json(['code' => 1, 'msg' => '类型错误']);
- }
- $className = 'app\\model\\' . ucfirst($param['type']);
- if($param['type'] == 'company') $className = 'app\\model\\CompanyVrshow';
- $obj = new $className();
- $field = 'id';
- $data = $obj->where($field, $param['id'])->find();
- // 足迹
- $aes = new Aes(config('app.jwt_key'));
- $queryData = $aes->decrypt($p);
- parse_str($queryData, $token);
- $params['employee_id'] = isset($token['employee_id']) ? intval($token['employee_id']) : 0;
- $root_id = '';
- $employee = [];
- if (!empty($params['employee_id'])) {
- $employee = Employee::with('userImg')->field('id,uid,org_id,root_id,name,phone')->find($params['employee_id']);
- $org_id = $employee->org_id;
- $root_id = $employee->root_id;
- }
- $params['root_id'] = $root_id;
- $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
- if (!empty($this->user)) {
- if (!empty($params['employee_id'])) {
- event(new FootPrints($this->user['id'], $params['employee_id'], $org_id ?? 0, $data, $param['type'] . 'Vr'));
- $foot = ModelFootprints::where(['uid' => $this->user['id'], 'employee_id' => $params['employee_id'], 'pipe_type' => $param['type'] . 'Vr', 'org_id' => $org_id])->field('id,addtime')->order('addtime desc')->find();
- if ($foot) $visit = $foot->toArray();
- // 分享关系创建
- $this->addClue($params['employee_id']);
- }
- View::assign('authorize', true);
- } else {
- View::assign('authorize', false);
- }
- View::assign('visit', $visit);
- $r = input('r');
- View::assign('r', $r);
- View::assign('p', $p);
- View::assign('type', $param['type']);
- View::assign('vr', urldecode($param['vr_link']));
- View::assign('employee', $employee);
- // 设置分享链接
- $jssdk = new JsSdk();
- $appid = config('app.official_appid');
- if (cache('?jsapi_ticket')) {
- $ticket = cache('jsapi_ticket');
- } else {
- // 获取普通access_token
- if (!$token = Cache::get('zqxg_offi_access_token')) {
- $token = getAccessToken($appid, config('app.official_secret'));
- Cache::set('zqxg_offi_access_token', $token, 7100);
- }
- $ticket = $jssdk->getJsApiTicket($token);
- cache('jsapi_ticket', $ticket, 7200);
- }
- $signPackage = $jssdk->getSignPackage($ticket);
- $signPackage['appid'] = $appid;
- View::assign('wxconfig', $signPackage);
- $data['share_employee'] = Employee::with(['user' => function ($query) {
- $query->field('id,headimgurl');
- }])->where(['id' => $params['employee_id']])->field('id,uid,name,phone,qrcode,org_id')->find();
- $company = Company::where('root_id', '=', $root_id)->field(['id', 'company_name', 'logo', 'company_address', 'root_id'])->find();
- $companyType = Miniprogram::where(['root_id' => $company->root_id])->value('notify');
- $data['company_name'] = $company['company_name'];
- $data['company_logo'] = $company['logo'];
- $data['company_address'] = $company['company_address'];
- $data['company_type'] = $companyType;
- View::assign('data', $data);
- return View::fetch();
- }
- /**
- * 通过经纪人分享的内容,用户进行报名(h5)
- */
- public function add_customer()
- {
- $param = $this->request->only(['name', 'phone', 'community_name', 'agent_id']);
- $agtdata = AgentUser::where(['id' => $param['agent_id'], 'root_id' => $this->user['root_id']])->find();
- if (empty($agtdata)) return json(['code' => 1, 'msg' => '推荐人信息未查询到']);
- if ($this->user['id'] == $agtdata['uid']) return json(['code' => 1, 'msg' => '您的身份是推荐人,不能报名']);
- $isEmployee = Employee::where([['uid', '=', $this->user['id']], ['state', 'in', ['在职', '待审核']], ['root_id', '=', $this->user['root_id']]])->findOrEmpty();
- if (!$isEmployee->isEmpty()) return json(['code' => 1, 'msg' => '您已加入企业,无法报名']);
- // 添加客户检测手机号的重复
- $tips = (new AgentsLogic())->checkPepeat([$param['phone']], orgSubIds($agtdata['org_id']));
- if (!empty($tips)) return $tips;
- $data = [
- 'employee_id' => $agtdata['agent_employee_id'],
- 'org_id' => $agtdata['org_id'],
- 'state' => 0,
- 'name' => $param['name'],
- 'phone' => cypherphone(trim($param['phone'])),
- 'community_name' => $param['community_name'],
- 'sex' => 1,
- 'agents_id' => $agtdata['id'],
- 'agent_source_type' => 3
- ];
- //保存报备的客户
- Db::startTrans();
- try {
- // 更新线索电话
- $condition = [
- 'employee_id' => $agtdata['agent_employee_id'],
- 'uid' => $this->user['id'],
- 'org_id' => $agtdata['org_id']
- ];
- // 更新线索信息,并默认报备状态
- $had = CustomerClue::where($condition)->find();
- if (empty($had->phone)) {
- $had->phone = $param['phone'];
- $had->state = 1;
- $had->save();
- }
- $data['clue_id'] = $had['id'];
- $ms = Customer::insertGetId($data);
- $empuid = Employee::where('id', $agtdata['agent_employee_id'])->value('uid');
- $log = [
- 'employee_id' => $agtdata['agent_employee_id'],
- 'customer_id' => $ms,
- 'type' => '',
- 'remark' => '通过推荐人分享的内容报名的客户',
- 'user_id' => $empuid,
- 'state' => 1,
- 'org_id' => $agtdata['org_id']
- ];
- CustomerVisitLog::insertGetId($log);
- // 足迹
- if (!empty($this->user['id']) && $isEmployee->isEmpty()) {
- $footerArr = [
- 'name'=>$param['name'],
- 'phone'=>$param['phone'],
- 'community_name'=>$param['community_name'],
- ];
- event(new FootPrints($this->user['id'], $agtdata['agent_employee_id'] ?? 0, $agtdata['org_id'] ?? 0, $footerArr, 'agentShareContentCrm'));
- }
- Db::commit();
- return json(['code' => 0, 'msg' => '报名成功']);
- } catch (\Exception $e) {
- Db::rollback();
- return json(['code' => 1, 'msg' => '报名失败']);
- }
- }
- }
|