Index.php 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\index\controller;
  4. use app\event\FootPrints;
  5. use app\event\Msg;
  6. use app\model\Building as BuildingModel;
  7. use app\model\BuildingConstruction;
  8. use app\model\BuildingHousetype;
  9. use app\model\BuildingProgress;
  10. use app\model\BuildingUrge;
  11. use app\model\Company;
  12. use app\model\Construction;
  13. use app\model\ConstructionRecord;
  14. use app\model\ConstructionStep;
  15. use app\model\Designer;
  16. use app\model\DesignerReserve;
  17. use app\model\Org;
  18. use app\model\QuoteRecord as QuoteRecordModel;
  19. use app\model\Setting;
  20. use toolkits\Aec;
  21. use think\facade\View;
  22. use app\model\ActivityOrder;
  23. use app\model\CustomerClue;
  24. use app\model\Employee;
  25. use app\model\Footprints as ModelFootprints;
  26. use app\model\Miniprogram;
  27. use app\model\User;
  28. use app\model\AgentUser;
  29. use app\model\Customer;
  30. use think\facade\Db;
  31. use app\model\CreditsSetting;
  32. use app\logics\AgentsLogic;
  33. use app\model\AgentIntegral;
  34. use openssl\Aes;
  35. use think\facade\Cache;
  36. use wx\offiaccount\JsSdk;
  37. use think\helper\Str;
  38. use wx\offiaccount\User as OffiaccountUser;
  39. use app\model\CustomerVisitLog;
  40. use xiaohongwu\Vr;
  41. use app\model\BuildingMaterialCase;
  42. use app\model\MaterialCase;
  43. use app\model\UserCollect;
  44. use app\model\Decostyle;
  45. use app\model\BuildingDevelopCase;
  46. use app\model\ActivitySign;
  47. use app\model\CustomersSubscribe;
  48. use app\model\Activity;
  49. use app\model\Community;
  50. use app\model\Construction as ConstructionModel;
  51. class Index extends Wxbase
  52. {
  53. public function initialize()
  54. {
  55. $request = request();
  56. $action = $request->action();
  57. $nocheck = ['visitDueTime', 'houseroom_list', 'housetype_list', 'progress', 'material_case', 'dev_case_list', 'dev_case_detail'];
  58. if (in_array($action, $nocheck)) return;
  59. //if ($action == 'visitDueTime') return;
  60. $r = $request->param('r');
  61. $user = session('user');
  62. if (!empty($user) && $user['root_id'] != $r) {
  63. $this->copyUser($user, $r);
  64. } else {
  65. $this->user = session('user');
  66. }
  67. $n = $request->param('n');
  68. $code = $request->param('code');
  69. if (!empty($code) && empty($this->user)) {
  70. $this->codeForInfo($code);
  71. }
  72. $noauth = ['content','dev_case_details','vr','progress_detail','housetype'];
  73. if (in_array($action,$noauth) && empty($n)) return;
  74. if (empty($this->user) && empty($code)) {
  75. $this->redirectForCode();
  76. }
  77. }
  78. private function redirectForCode()
  79. {
  80. $request = request();
  81. $param = $request->get();
  82. $appid = config('app.official_appid');
  83. // 跳转授权页面
  84. unset($param['code']);
  85. unset($param['state']);
  86. if ($request->action() == 'content') unset($param['n']);
  87. if ($request->action() == 'vr') unset($param['n']);
  88. $redirectUrl = url($request->baseUrl(), $param, false, true);
  89. $wxUser = new OffiaccountUser();
  90. $wxUser->redirectForCode($appid, $redirectUrl);
  91. }
  92. /**
  93. * 通过code获取用户信息并定向
  94. *
  95. * @return void
  96. */
  97. private function codeForInfo($code)
  98. {
  99. $request = request();
  100. $param = $request->param();
  101. $get = $request->get();
  102. $wxUser = new OffiaccountUser();
  103. $appid = config('app.official_appid');
  104. $data = $wxUser->getAccessTokenByCode($appid, config('app.official_secret'), $code);
  105. if (isset($data['errcode']) && in_array($data['errcode'], [40029, 40163, 41008, 42003])) { // code已经被使用
  106. echo "<script>history.go(-1);</script>";
  107. exit;
  108. } elseif (isset($data['errcode'])) {
  109. trace('授权获取用户信息', 'error');
  110. trace($data, 'error');
  111. echo $data['errmsg'];
  112. exit;
  113. }
  114. // 查询用户信息是否存在
  115. $user = User::whereOr([[['openid', '=', $data['openid']], ['root_id', '=', $param['r']]], [['unionid', '=', $data['unionid']], ['root_id', '=', $param['r']]]])->order('updatetime desc')->findOrEmpty();
  116. if ($user->isEmpty() || empty($user->unionid) || empty($user->headimgurl) || $user->nickname=='游客') {
  117. $userInfo = $wxUser->getH5UserInfo($data['access_token'], $data['openid']);
  118. if (isset($userInfo['errcode'])) {
  119. trace('拉取用户信息', 'error');
  120. trace($data, 'error');
  121. echo '请求失败';
  122. exit;
  123. }
  124. $user->save([
  125. 'nickname' => $userInfo['nickname'],
  126. 'sex' => $userInfo['sex'],
  127. 'headimgurl' => $userInfo['headimgurl'],
  128. 'province' => $userInfo['province'],
  129. 'city' => $userInfo['city'],
  130. 'country' => $userInfo['country'],
  131. 'openid' => $userInfo['openid'],
  132. 'unionid' => $userInfo['unionid'] ?? '',
  133. 'root_id' => $param['r'],
  134. 'updatetime' => date('Y-m-d H:i:s')
  135. ]);
  136. } else {
  137. $user->updatetime = date('Y-m-d H:i:s');
  138. if (empty($user->unionid)) $user->unionid = $data['unionid'];
  139. $user->save();
  140. }
  141. $this->user = $user->toArray();
  142. session('user', $this->user);
  143. session('openid', $data['openid']);
  144. }
  145. /**
  146. * 建立线索关系
  147. */
  148. private function addClue($employee_id, $agent_id = null)
  149. {
  150. // 判断是否是员工
  151. $isEmployee = Employee::where([['uid', '=', $this->user['id']], ['root_id', '=', $this->user['root_id']], ['state', 'in', ['在职', '待审核']]])->find();
  152. if ($isEmployee) return false;
  153. $employee = Employee::find($employee_id);
  154. if (empty($employee)) return false;
  155. $data = [
  156. 'employee_id' => $employee_id,
  157. 'uid' => $this->user['id'],
  158. 'org_id' => $employee->org_id
  159. ];
  160. // 建立线索关系
  161. $had = CustomerClue::where($data)->find();
  162. if (!$had) {
  163. //如果是经纪人分享
  164. if (!empty($agent_id)) $data['agent_id'] = $agent_id;
  165. CustomerClue::create($data);
  166. } else {
  167. $had->updatetime = date('Y-m-d H:i:s');
  168. $had->save();
  169. }
  170. return $had;
  171. }
  172. /**
  173. * 用户分享内容
  174. */
  175. public function content($p)
  176. {
  177. // 设置分享链接
  178. $jssdk = new JsSdk();
  179. $appid = config('app.official_appid');
  180. if (cache('?jsapi_ticket')) {
  181. $ticket = cache('jsapi_ticket');
  182. } else {
  183. // 获取普通access_token
  184. if (!$token = Cache::get('zqxg_offi_access_token')) {
  185. $token = getAccessToken($appid, config('app.official_secret'));
  186. Cache::set('zqxg_offi_access_token', $token, 7100);
  187. }
  188. $ticket = $jssdk->getJsApiTicket($token);
  189. cache('jsapi_ticket', $ticket, 7200);
  190. }
  191. $signPackage = $jssdk->getSignPackage($ticket);
  192. $signPackage['appid'] = $appid;
  193. View::assign('wxconfig', $signPackage);
  194. $aes = new Aes(config('app.jwt_key'));
  195. $queryData = $aes->decrypt($p);
  196. parse_str($queryData, $pArr);
  197. // 分享内容获取
  198. $data = $this->getContent(intval($pArr['id']), $pArr['type']);
  199. if (empty($data)) abort(404, '页面不存在');
  200. $employee_id = isset($pArr['employee_id']) ? intval($pArr['employee_id']) : 0;
  201. $leftToEmpId = Employee::where(['id' => $employee_id, 'state' => '离职'])->value('left_to_empid');
  202. if ($leftToEmpId) $employee_id = $leftToEmpId;
  203. $data['share_employee'] = Employee::with(['user' => function ($query) {
  204. $query->field('id,headimgurl');
  205. }])->where(['id' => $employee_id])->field('id,uid,name,phone,qrcode,org_id')->find();
  206. //判断是否是经纪人分享
  207. $agent_id = isset($pArr['agent_id']) ? intval($pArr['agent_id']) : null;
  208. $data['agent_id'] = $agent_id;
  209. View::assign('data', $data);
  210. View::assign('p', $p);
  211. $r = input('r');
  212. View::assign('r', $r);
  213. $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
  214. View::assign('getPhone', false);
  215. if (!empty($this->user)) {
  216. // 分享关系创建
  217. if (!empty($data['share_employee'])) {
  218. $clue = $this->addClue($employee_id, $agent_id);
  219. if (!empty($clue) && $clue->phone)
  220. View::assign('getPhone', true);
  221. event(new FootPrints($this->user['id'], $data['share_employee']['id'], $data['share_employee']['org_id'], $data, lcfirst($pArr['type'])));
  222. $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();
  223. if ($foot) $visit = $foot->toArray();
  224. }
  225. View::assign('authorize', true);
  226. $check = ModelFootprints::where(['uid' => $this->user['id'], 'pipe_type' => 'designer'])->findOrEmpty();
  227. // $check = DesignerReserve::where([['uid','=',$this->user['id']],['pipe_type','=','materialCase']])->findOrEmpty();
  228. View::assign('is_reserve', $check->isEmpty() ? 0 : 1);
  229. } else {
  230. View::assign('authorize', false);
  231. View::assign('is_reserve', 0);
  232. }
  233. View::assign('visit', $visit);
  234. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  235. $url = 'https://' . $ali_oss_bindurl . '/';
  236. View::assign('url', $url);
  237. return View::fetch('index/' . Str::snake($pArr['type'], '_'));
  238. }
  239. private function getContent($id, $classType)
  240. {
  241. if($classType == 'company') $classType = 'CompanyVrshow';
  242. $class = 'app\\model\\' . $classType;
  243. if (!class_exists($class)) return null;
  244. $obj = new $class();
  245. $data = $obj->find($id);
  246. if (empty($data)) {
  247. return null;
  248. }
  249. if ($classType == 'Activity' && !empty($this->user)) {
  250. // 判断是否交定
  251. $hadPay = ActivityOrder::where(['user_id' => $this->user['id'], 'activity_id' => $data['id'], 'state' => 1])->count();
  252. if ($hadPay) $data['had_pay'] = 1;
  253. else $data['had_pay'] = 0;
  254. //是否报名
  255. $sign = ActivitySign::where([['uid', '=', $this->user['id']], ['aid', '=', $data['id']]])->findOrEmpty();
  256. $data['activity_sign'] = !$sign->isEmpty();
  257. $data['sign_qrcode'] = $sign->qrcode;
  258. } elseif ($classType == 'Construction') {
  259. // 查询施工步骤
  260. $steps = ConstructionStep::where(['root_id' => $data->root_id])->field('id,order,name')->order('order')->select();
  261. // 查询施工情况
  262. $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();
  263. $vrObj = new Vr();
  264. foreach ($records as $k => $v) {
  265. if (!empty($v['vr']) && $v['type'] == 'vr') {
  266. $vrUrlList = explode(',', $v['vr']);
  267. $vrData = [];
  268. foreach ($vrUrlList as $url) {
  269. $vrData[] = [
  270. 'vrUrl' => urlencode($url),
  271. 'vrfirstImg' => $vrObj->getFirstImg($url)
  272. ];
  273. }
  274. $records[$k]['vr'] = $vrData;
  275. }
  276. }
  277. // 施工进度
  278. $maxStep = 0;
  279. foreach ($records as $r) {
  280. if ($maxStep == 0) $maxStep = $r->step->order;
  281. elseif ($maxStep < $r->step->order) $maxStep = $r->step->order;
  282. }
  283. View::assign('steps', $steps);
  284. View::assign('maxStep', $maxStep);
  285. View::assign('records', $records);
  286. } elseif ($classType == 'Building') {
  287. $data = BuildingModel::find($id);
  288. //关联在施工地数量
  289. $area_list = BuildingHousetype::where('building_id', '=', $id)->order('area asc')->limit(3)->column('area');
  290. // $data['area_list'] = implode('/', array_values(array_unique(array_filter($area_list))));
  291. $data['area_list'] = array_values(array_unique(array_filter($area_list)));
  292. //小区户型
  293. $housetype = BuildingHousetype::where('building_id', '=', $id)->withCount(['materialCase'])->select()->each(function ($item) {
  294. if (!empty($item['vr_link'])) {
  295. $item->vr_link = urlencode($item['vr_link']);
  296. }
  297. });
  298. $data['housetype'] = $housetype->toArray();
  299. $vrObj = new Vr();
  300. $data['vr_link_cover'] = '';
  301. if (!empty($data['vr_link'])) {
  302. $data['vr_link_cover'] = $vrObj->getFirstImg($data['vr_link']);
  303. $data['vr_link'] = urlencode($data['vr_link']);
  304. }
  305. $data['housetype_count'] = $housetype->count();
  306. //$vrObj = new Vr();
  307. $domain = request()->domain();
  308. $progress_list = BuildingProgress::where('building_id', '=', $id)->order('addtime desc')->select()->toArray();
  309. foreach ($progress_list as &$item) {
  310. if (empty($item['vr'])) {
  311. $item['vr'] = [];
  312. } else {
  313. $vrUrlList = explode(',', $item['vr']);
  314. $vrData = [];
  315. foreach ($vrUrlList as $url) {
  316. $vrData[] = [
  317. 'vrUrl' => urlencode($url),
  318. 'vrfirstImg' => $vrObj->getFirstImg($url)
  319. ];
  320. }
  321. $item['vr'] = $vrData;
  322. }
  323. $item['progress_cont_link'] = $domain . '/index/index/progress_detail.html?r=' . $item['root_id'] . '&id=' . $item['id'];
  324. }
  325. $data['progress'] = $progress_list;
  326. //在施工地
  327. $construction_ids = BuildingConstruction::where('building_id', '=', $id)->column('construction_id');
  328. $construction = Construction::with(['style', 'housetype'])->where([['id', 'in', $construction_ids]])->select()->toArray();
  329. // 查询施工步骤
  330. $steps = ConstructionStep::where(['root_id' => $data->root_id])->field('id,order,name')->order('order')->select();
  331. foreach ($construction as &$item) {
  332. $item['step_list'] = $steps;
  333. // 查询施工情况
  334. $records = ConstructionRecord::with(['step'])->where(['construction_id' => $item['id']])->field('id,step_id,img,content,addtime')->order('step_id')->select();
  335. // 施工进度
  336. $maxStep = 0;
  337. foreach ($records as $r) {
  338. if ($maxStep == 0) $maxStep = $r->step->order;
  339. elseif ($maxStep < $r->step->order) $maxStep = $r->step->order;
  340. }
  341. $item['maxStep'] = $maxStep;
  342. }
  343. $data['construction'] = $construction;
  344. } elseif ($classType == 'MaterialCase') {
  345. $data->designer = Employee::with(['designer', 'user'])->where('id', $data['designer_id'])->find();
  346. if ($data->designer) {
  347. $data->designer->headimgurl = User::where('id', '=', $data['designer']['uid'])->value('headimgurl');
  348. }
  349. $data->img_content = $data->img_content ? json_decode($data->img_content, true) : [];
  350. } elseif($classType == 'AgentArticle'){
  351. $data->files = !empty($data['file'][0]) ? str_replace('https://'.config('app.ali_oss_bindurl').'/','',$data['file'][0]) : '';
  352. }
  353. $company = Company::where('root_id', '=', $data['root_id'])->field(['id', 'company_name', 'logo', 'company_address', 'root_id'])->find();
  354. $companyType = Miniprogram::where(['root_id' => $company->root_id])->value('notify');
  355. $data['company_name'] = $company['company_name'];
  356. $data['company_logo'] = $company['logo'];
  357. $data['company_address'] = str_replace(array("\r\n", "\r", "\n"), "", $company['company_address']);
  358. $data['company_type'] = $companyType;
  359. //增加浏览次数
  360. $is_employee = false;
  361. if (!empty($this->user)) {
  362. $e_where[] = ['uid', '=', $this->user['id']];
  363. $e_where[] = ['state', 'in', ['在职', '待审核']];
  364. if ($this->user['root_id']) {
  365. $e_where[] = ['root_id', '=', $this->user['root_id']];
  366. }
  367. $isEmployee = Employee::where($e_where)->findOrEmpty();
  368. if (!$isEmployee->isEmpty()) $is_employee = true;
  369. }
  370. if (isset($data['view_times']) && !$is_employee) {
  371. $data->view_times++;
  372. $data->allowField(['view_times'])->save();
  373. }
  374. if (isset($data['hot']) && !$is_employee) {
  375. $data->hot++;
  376. $data->allowField(['hot'])->save();
  377. }
  378. return $data;
  379. }
  380. public function invite()
  381. {
  382. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  383. $al = request()->param('al');
  384. $decrypt_arr = explode('&', $aec->decrypt($al));
  385. $manager = str_replace('is_manager=', '', $decrypt_arr[2]);
  386. $orgid = str_replace('orgid=', '', $decrypt_arr[0]);
  387. $orgobj = Org::find($orgid);
  388. View::assign('manager', $manager == 'false' ? '员工' : '管理员');
  389. View::assign('orginfo', $orgobj->info);
  390. View::assign('al', $al);
  391. return View::fetch();
  392. }
  393. public function invitor() //手机端管理者邀请链接生成界面
  394. {
  395. //$aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  396. //
  397. //$al = input('al');
  398. //$decrypt_arr = explode('&', $aec->decrypt($al));
  399. //$orgid = str_replace('orgid=', '', $decrypt_arr[0]);
  400. //$orgobj = Org::find($orgid);
  401. //View::assign('orginfo', $orgobj->info);
  402. //View::assign('orgid', $orgid);
  403. return View::fetch();
  404. }
  405. // public function register()
  406. // {
  407. // $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  408. // $params = request()->param(['al', 'phone', 'name']);
  409. // $decrypt_arr = explode('&', $aec->decrypt($params['al']));
  410. // $orgid = str_replace('orgid=', '', $decrypt_arr[0]);
  411. // $role = str_replace('role=', '', $decrypt_arr[1]);
  412. // $is_manager = str_replace('is_manager=', '', $decrypt_arr[2]);
  413. // $is_manager = ($is_manager == 'false') ? 0 : 1;
  414. // $openid = session('openid');
  415. // $result = EmployeeLogic::addemployee($params['name'], $params['phone'], $orgid, $openid, $role, $is_manager);
  416. // if ($result) {
  417. // return ['code' => 0, 'msg' => '成功提交', 'data' => $result];
  418. // } else {
  419. // return ['code' => 1, 'msg' => '提交失败'];
  420. // }
  421. // }
  422. /**
  423. * 用户报名
  424. */
  425. public function signup($p)
  426. {
  427. $aes = new Aes(config('app.jwt_key'));
  428. $queryData = $aes->decrypt($p);
  429. parse_str($queryData, $token);
  430. $class = 'app\\model\\' . $token['type'];
  431. $id = intval($token['id']);
  432. if (!class_exists($class)) return;
  433. $obj = new $class();
  434. $objData = $obj->find($id);
  435. if (empty($objData)) abort(404, '页面不存在');
  436. $employee_id = isset($token['employee_id']) ? intval($token['employee_id']) : 0;
  437. $root_id = '';
  438. if (!empty($employee_id)) {
  439. $employee = Employee::find($employee_id);
  440. $org_id = $employee->org_id;
  441. $root_id = $employee->root_id;
  442. }
  443. $e_where[] = ['uid', '=', $this->user['id']];
  444. $e_where[] = ['state', 'in', ['在职', '待审核']];
  445. if ($root_id) {
  446. $e_where[] = ['root_id', '=', $root_id];
  447. }
  448. $isEmployee = Employee::where($e_where)->findOrEmpty();
  449. if (!$isEmployee->isEmpty()) return json(['code' => 1, 'msg' => '员工无需报名']);
  450. $data = $this->request->only(['name', 'remark', 'mobile']);
  451. $data = array_filter($data);
  452. $data['data'] = $objData->toArray();
  453. $data['uid'] = $this->user['id'];
  454. $type = input('type', '', 'trim');
  455. // 新增vr下的报名,vr下报名不限制次数,产品小胖
  456. $vr_type = ['constructionVr', 'buildingVr', 'materialCaseVr'];
  457. if (!in_array($type, $vr_type)) {
  458. // 检测防止重复提交
  459. $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();
  460. if ($hadList) {
  461. $keys = array_keys($data['data']);
  462. foreach ($hadList as $i) {
  463. $info = json_decode($i->getData('reg_info'), true);
  464. $data = $info['data'];
  465. $exitKey = array_keys($data);
  466. $cha = array_diff($keys, $exitKey);
  467. if (empty($cha)) {
  468. if ($token['type'] == "Building") {
  469. return json(['code' => 1, 'msg' => '您已询问装修成功,请勿重复询问']);
  470. } elseif ($token['type'] == "MaterialCase") {
  471. return json(['code' => 1, 'msg' => '您已预约成功,请勿重复预约']);
  472. } else {
  473. return json(['code' => 1, 'msg' => '您已报名成功,请勿重复报名']);
  474. }
  475. }
  476. }
  477. }
  478. }
  479. // vr页面报名数据处理
  480. $vrData = [];
  481. switch ($type) {
  482. case 'materialCaseVr':
  483. $vrData['title'] = '案例"' . $objData['title'] . '"VR';
  484. $vrData['id'] = $id;
  485. break;
  486. case 'buildingVr':
  487. $vrData['title'] = '热装楼盘"' . $objData['name'] . '"VR';
  488. $vrData['id'] = $id;
  489. break;
  490. case 'constructionVr':
  491. $vrData['title'] = '在施工地"' . $objData['name'] . '"VR';
  492. $vrData['id'] = $id;
  493. break;
  494. default:
  495. break;
  496. }
  497. if (in_array($type, $vr_type)) {
  498. $data['data'] = $vrData;
  499. }
  500. $share_type = 'share';
  501. if ($token['type'] == "Building") {
  502. $share_type = 'askedfitup';
  503. $data['phone'] = $data['mobile'];
  504. if (empty($data['phone'])) return json(['code' => 1, 'msg' => '手机号为空']);
  505. }
  506. $type = $type ? $type : $share_type;
  507. //跳过统一添加足迹的控制器数组
  508. $noaddfoot = ['material_case'];
  509. // 添加足迹
  510. if (!empty($data['uid']) && !in_array($type, $noaddfoot)) {
  511. event(new FootPrints($data['uid'], $employee_id, $org_id ?? 0, $data, $share_type));
  512. }
  513. switch ($type) {
  514. case 'activity':
  515. if ($root_id && $employee_id && $data['mobile']) {
  516. // 客户跟进保护规则
  517. $orgs = orgSubIds($root_id);
  518. $c_where[] = ['phone|phone1|phone2', '=', cypherphone($data['mobile'])];
  519. $c_where[] = ['org_id', 'in', $orgs];
  520. $c_where[] = ['employee_id', '<>', 'null'];
  521. $c_where[] = ['employee_id', '<>', $employee_id];
  522. $have_customer = Customer::where($c_where)->select()->toArray();
  523. $customer_ids = array_column($have_customer, 'id');
  524. if (!empty($customer_ids)) {
  525. $yylf_state = CustomerVisitLog::changeState('预约量房', 'chaos');
  526. $lf_state = CustomerVisitLog::changeState('已量房', 'chaos');
  527. $yydc_state = CustomerVisitLog::changeState('预约活动', 'chaos');
  528. $dc_state = CustomerVisitLog::changeState('已到场', 'chaos');
  529. $yydd_state = CustomerVisitLog::changeState('预约到店', 'chaos');
  530. $dd_state = CustomerVisitLog::changeState('已到店', 'chaos');
  531. $sub_setting = Setting::where([['root_id', '=', $root_id], ['name', '=', 'subscribe_protected']])->findOrEmpty();
  532. if (!$sub_setting->isEmpty()) {
  533. $setting_content = json_decode($sub_setting['content'], true);
  534. foreach ($setting_content as $k_s => $v_s) {
  535. if (!empty($v_s['state']) && !empty($v_s['day']) && $v_s['state'] == 1) {
  536. $continue = false;
  537. $sub_state = 0;
  538. $errmsg = '您已有预约,无需重复预约';
  539. $check_log = false;
  540. $check_where = [];
  541. switch ($k_s) {
  542. case 'liangfang':
  543. $sub_state = 3;
  544. $visit_state = 1;
  545. $check_log = true;
  546. $check_where[] = ['customer_id', 'in', $customer_ids];
  547. $check_where[] = ['addtime', '>', date('Y-m-d H:i:s', time() - 24 * 3600 * $v_s['day'])];
  548. $check_where[] = ['employee_id', 'in', array_column($have_customer, 'employee_id')];
  549. $check_where[] = ['state', 'in', $lf_state];
  550. break;
  551. case 'yliangfang': //预约量房
  552. $sub_state = 3;
  553. $visit_state = 0;
  554. break;
  555. case 'daodian':
  556. $sub_state = 1;
  557. $visit_state = 1;
  558. $check_log = true;
  559. $check_where[] = ['customer_id', 'in', $customer_ids];
  560. $check_where[] = ['addtime', '>', date('Y-m-d H:i:s', time() - 24 * 3600 * $v_s['day'])];
  561. $check_where[] = ['employee_id', 'in', array_column($have_customer, 'employee_id')];
  562. $check_where[] = ['state', 'in', $dd_state];
  563. break;
  564. case 'ydaodian':
  565. $sub_state = 1;
  566. $visit_state = 0;
  567. break;
  568. case 'daochang':
  569. $sub_state = 2;
  570. $visit_state = 1;
  571. $check_log = true;
  572. $check_where[] = ['customer_id', 'in', $customer_ids];
  573. $check_where[] = ['addtime', '>', date('Y-m-d H:i:s', time() - 24 * 3600 * $v_s['day'])];
  574. $check_where[] = ['employee_id', 'in', array_column($have_customer, 'employee_id')];
  575. $check_where[] = ['state', 'in', $dc_state];
  576. break;
  577. case 'ydaochang':
  578. $sub_state = 2;
  579. $visit_state = 0;
  580. break;
  581. default:
  582. $continue = true;
  583. break;
  584. }
  585. if ($continue) continue;
  586. // 查询保护时间段内添加的预约量房记录
  587. unset($v_where);
  588. $v_where[] = ['customer_id', 'in', $customer_ids];
  589. $v_where[] = ['addtime', '>', date('Y-m-d H:i:s', time() - 24 * 3600 * $v_s['day'])];
  590. $v_where[] = ['employee_id', 'in', array_column($have_customer, 'employee_id')];
  591. $v_where[] = ['type', '=', $sub_state];
  592. $v_where[] = ['state', '=', $visit_state];
  593. $sub_list = CustomersSubscribe::where($v_where)->select()->toArray();
  594. if (!empty($sub_list)) {
  595. return json(['code' => 1, 'msg' => $errmsg]);
  596. }
  597. if ($check_log) {
  598. $log_list = CustomerVisitLog::where($check_where)->select()->toArray();
  599. if (!empty($log_list)) {
  600. return json(['code' => 1, 'msg' => $errmsg]);
  601. }
  602. }
  603. }
  604. }
  605. }
  606. }
  607. }
  608. //报名活动成功后建档
  609. if ($token['type'] == 'Activity' && $root_id && $data['uid'] && $id && $data['mobile'] && $employee_id) {
  610. $data['aid'] = $id;
  611. $data['employee_id'] = $employee_id;
  612. $data['root_id'] = $root_id;
  613. $this->activitySign($data);
  614. }
  615. $new = $this->user['nickname'] . '报名了' . $objData['title'] . '活动,请及时处理';
  616. if ($employee_id) {
  617. event(new Msg($employee_id, $new, 'activity', $id));
  618. }
  619. break;
  620. case 'material_case':
  621. if ($objData['designer_id']) {
  622. $designer = Employee::where('id', $objData['designer_id'])->find();
  623. if (!$designer->isEmpty()) {
  624. $new = $this->user['nickname'] . '预约了' . $designer['name'] . '设计师,请及时跟进';
  625. if ($employee_id) {
  626. event(new Msg($employee_id, $new, 'material_case'));
  627. // 通知到设计师
  628. /*$d_msg = "“" . $employee['nickname'] . "”名下的“" . $this->user['nickname] . "”预约了您,请及时沟通";
  629. event(new Msg($objData['designer_id'], $d_msg, 'designer'));*/
  630. }
  631. $designer_data['designer_id'] = $objData['designer_id'];
  632. $designer_data['uid'] = $this->user['id'];
  633. $designer_data['employee_id'] = $employee_id;
  634. $designer_data['pipe_type'] = 'materialCase';
  635. $designer_data['data_id'] = $id;
  636. $designer_data['root_id'] = $designer['root_id'];
  637. DesignerReserve::create($designer_data);
  638. $d_where[] = ['id', '=', $objData['designer_id']];
  639. $d_where[] = ['root_id', '=', $designer['root_id']];
  640. $root_id = $designer['root_id'];
  641. $designer_find = Employee::with(['designer' => function ($query) use ($root_id) {
  642. $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']);
  643. }])->where($d_where)->field('name title,id,show,id designer_id,root_id')->findOrEmpty();
  644. $designer_find['share_pipe_type'] = 'materialCase';
  645. $designer_find['share_data_id'] = $id;
  646. $designer_find['mobile'] = !empty($data['mobile']) ? $data['mobile'] : '未获取';
  647. event(new FootPrints($data['uid'], $employee_id, $org_id ?? 0, $designer_find, 'designer'));
  648. } else {
  649. $new = $this->user['nickname'] . '预约了设计师,请及时跟进';
  650. if ($employee_id) {
  651. event(new Msg($employee_id, $new, 'material_case'));
  652. }
  653. }
  654. } else {
  655. $designer_find['share_pipe_type'] = 'materialCase';
  656. $designer_find['share_data_id'] = $id;
  657. $designer_find['mobile'] = !empty($data['mobile']) ? $data['mobile'] : '';
  658. event(new FootPrints($data['uid'], $employee_id ?? 0, $org_id ?? 0, $designer_find, 'designer'));
  659. }
  660. break;
  661. case 'video':
  662. $new = $this->user['nickname'] . '预约了装修服务,请及时跟进';
  663. if ($employee_id) {
  664. event(new Msg($employee_id, $new, 'video'));
  665. }
  666. break;
  667. default:
  668. break;
  669. }
  670. return json(['code' => 0, 'msg' => '报名成功']);
  671. }
  672. /**
  673. * 活动报名成功后,建档,邀约
  674. */
  675. private function activitySign($data)
  676. {
  677. $aec = new Aec(config('app.aec_key'), config('app.aec_iv'));
  678. $phone = $aec->encrypt($data['mobile']);
  679. //建档
  680. $orgs = Org::where([['path', 'like', $data['root_id'] . '-%']])->column('id');
  681. $customer = Customer::where([['phone|phone1|phone2', '=', $phone], ['org_id', 'in', $orgs], ['employee_id', '=', $data['employee_id']]])->findOrEmpty();
  682. $employee = Employee::where('id', $data['employee_id'])->field('id,uid,org_id')->find();
  683. $aw[] = ['phone|phone1|phone2', '=', $phone];
  684. $aw[] = ['org_id', 'in', $orgs];
  685. $aw[] = ['is_resource','=',0];
  686. $customer_list = Customer::where($aw)->select()->toArray();
  687. $have_customer = [];
  688. foreach($customer_list as $k => $v) {
  689. if ($v['employee_id'] > 0 && $v['employee_id'] != $data['employee_id']) {
  690. $have_customer[] = $v;
  691. }
  692. }
  693. $empcrm_repeat[] = ['root_id', '=', $data['root_id']];
  694. $empcrm_repeat[] = ['name', '=', 'empcrm_customer_repeat'];
  695. $repeat_setting = Setting::where($empcrm_repeat)->findOrEmpty();
  696. //判断同部门
  697. if (!$repeat_setting->isEmpty()) {
  698. $repeat_org = explode(',', $repeat_setting['content']);
  699. if (!in_array($employee['org_id'], $repeat_org)) {
  700. $repeat_org = [$employee['org_id']];
  701. }
  702. } else {
  703. $repeat_org = [$employee['org_id']];
  704. }
  705. // 需要验证
  706. if (!empty($have_customer)) {
  707. foreach ($have_customer as $ex) {
  708. if (in_array($ex['org_id'], $repeat_org)) {
  709. $have_emp = Employee::where('id', '=', $ex['employee_id'])->value('name');
  710. return json(['code' => 1, 'msg' => '您已是' . $have_emp . '的客户,请联系他预约']);
  711. }
  712. }
  713. }
  714. if ($customer->isEmpty()) {
  715. $save = [];
  716. $save['uid'] = $data['uid'];
  717. $save['employee_id'] = $data['employee_id'];
  718. $save['clue_id'] = CustomerClue::where([['uid', '=', $data['uid']], ['org_id', 'in', $orgs], ['employee_id', '=', $data['employee_id']]])->value('id') ?: 0;
  719. $save['phone'] = $phone;
  720. $save['name'] = $data['name'] ?: User::where('id', $data['uid'])->value('nickname');
  721. $save['state'] = 0;
  722. $save['org_id'] = $employee->org_id;
  723. $save['remark'] = 'h5活动报名建档';
  724. $save['sex'] = 1;
  725. $cid = Customer::insertGetId($save);
  726. } else {
  727. $cid = $customer->id;
  728. }
  729. //邀约活动
  730. $save = [];
  731. $save['customer_id'] = $cid;
  732. $save['type'] = 3;
  733. $save['next_contact_date'] = date('Y-m-d');
  734. $save['remark'] = '活动邀约';
  735. $save['employee_id'] = $data['employee_id'];
  736. $save['user_id'] = $data['uid'];
  737. $save['state'] = 6;
  738. $save['aid'] = $data['aid'];
  739. CustomerVisitLog::insertGetId($save);
  740. // $update['state'] = 0;//不改变客户之前的状态
  741. $update['uid'] = $data['uid'];
  742. $update['aid'] = $data['aid'];
  743. $update['revisit_time'] = date('Y-m-d');
  744. $update['last_contact_date'] = date('Y-m-d');
  745. $update['updatetime'] = date('Y-m-d H:i:s');
  746. Customer::where('id', $cid)->update($update);
  747. //预约表添加数据
  748. $subscribe = [
  749. 'customer_id' => $cid,
  750. 'subscribe_date' => date('Y-m-d'),
  751. 'employee_id' => $data['employee_id'],
  752. 'type' => 2,
  753. 'aid' => (int)$data['aid'],
  754. 'org_id' => $employee->org_id
  755. ];
  756. CustomersSubscribe::insertGetId($subscribe);
  757. //二维码内容,活动id,报名人uid
  758. $qrcode_con = $data['aid'] . '&' . $cid . '&' . $data['uid'];
  759. $cate = Activity::where('id', $data['aid'])->value('cate');
  760. $qrcode_con = $qrcode_con . '&' . $cate;
  761. //生成二维码
  762. $name = uniqid() . '.jpg';
  763. $path = 'activityqrcode/' . $name;
  764. $img = qrcode($qrcode_con, 'upload/' . $name);
  765. $res = ossUpload($path, 'upload/' . $name);
  766. @unlink('upload/' . $name); //删除本地文件
  767. ActivitySign::insertGetId([
  768. 'aid' => $data['aid'],
  769. 'root_id' => $data['root_id'],
  770. 'uid' => $data['uid'],
  771. 'share_uid' => $employee->uid,
  772. 'share_employee_id' => $data['employee_id'],
  773. 'qrcode' => $path,
  774. 'qrcode_con' => $qrcode_con,
  775. 'addtime' => date('Y-m-d H:i:s')
  776. ]);
  777. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  778. $url = 'https://' . $ali_oss_bindurl . '/' . $path;
  779. return $url;
  780. }
  781. /**
  782. * 获取装修设计方案报名
  783. */
  784. public function getDecorationDesign($p)
  785. {
  786. // 解析获取分享人信息
  787. $aes = new Aes(config('app.jwt_key'));
  788. $queryData = $aes->decrypt($p);
  789. parse_str($queryData, $token);
  790. // 查询员工信息
  791. $employee_id = isset($token['employee_id']) ? intval($token['employee_id']) : 0;
  792. $root_id = '';
  793. if (!empty($employee_id)) {
  794. $employee = Employee::find($employee_id);
  795. $org_id = $employee->org_id;
  796. $root_id = $employee->root_id;
  797. }
  798. $e_where[] = ['uid', '=', $this->user['id']];
  799. $e_where[] = ['state', 'in', ['在职', '待审核']];
  800. if ($root_id) {
  801. $e_where[] = ['root_id', '=', $root_id];
  802. }
  803. $isEmployee = Employee::where($e_where)->findOrEmpty();
  804. if (!$isEmployee->isEmpty()) return json(['code' => 1, 'msg' => '员工无需报名']);
  805. // 检测防止重复提交
  806. $hadList = ModelFootprints::where([['uid', '=', $this->user['id']], ['employee_id', '=', $employee_id], ['pipe_type', '=', 'getDecorationDesign']])->count();
  807. if ($hadList) {
  808. return json(['code' => 1, 'msg' => '您已报名成功,请勿重复报名']);
  809. }
  810. // 初始化类型
  811. $msgType = [
  812. 'Article' => ['拓客图文', 'title'],
  813. 'MaterialCase' => ['案例', 'title'],
  814. 'Building' => ['热装楼盘', 'name'],
  815. 'Construction' => ['在施工地', 'name'],
  816. 'MaterialEvidence' => ['客户好评', 'title'],
  817. 'Video' => ['拓客视频', 'title'],
  818. 'CompanyStrength' => ['公司实力', 'title']
  819. ];
  820. // 判断类型是否正确
  821. if (!isset($msgType[$token['type']])) return json(['code' => 1, 'msg' => '类型不存在']);
  822. // 获取分享内容
  823. $class = 'app\\model\\' . $token['type'];
  824. $id = intval($token['id']);
  825. $obj = new $class();
  826. $objData = $obj->find($id);
  827. if (empty($objData)) return json(['code' => 1, 'msg' => '内容不存在']);
  828. // 获取报名信息
  829. $data = $this->request->only(['community', 'area', 'bedroom', 'mobile']);
  830. $data = array_filter($data);
  831. $data['data'] = $objData->toArray();
  832. $data['uid'] = $this->user['id'];
  833. event(new FootPrints($data['uid'], $employee_id, $org_id ?? 0, $data, 'getDecorationDesign'));
  834. $msg = $this->user['nickname'] . '在' . $msgType[$token['type']][0] . '《' . $objData[$msgType[$token['type']][1]] . '》中申请获取装修方案,请及时处理';
  835. event(new Msg($employee_id, $msg, Str::snake($token['type'])));
  836. // 更新线索电话
  837. $condition = [
  838. 'employee_id' => $employee_id,
  839. 'uid' => $this->user['id'],
  840. 'org_id' => $org_id ?? 0
  841. ];
  842. // 建立线索关系
  843. $had = CustomerClue::where($condition)->find();
  844. if (empty($had->phone)) {
  845. $had->phone = $data['mobile'];
  846. $had->save();
  847. }
  848. return json(['code' => 0, 'msg' => '报名成功']);
  849. }
  850. /**
  851. * 报价
  852. */
  853. public function quote($p)
  854. {
  855. $params = $this->request->only(['area', 'room', 'hall', 'bathroom', 'phone']);
  856. $aes = new Aes(config('app.jwt_key'));
  857. $queryData = $aes->decrypt($p);
  858. parse_str($queryData, $token);
  859. $params['uid'] = $this->user['id'];
  860. $params['employee_id'] = isset($token['employee_id']) ? intval($token['employee_id']) : 0;
  861. $root_id = '';
  862. if (!empty($params['employee_id'])) {
  863. $employee = Employee::find($params['employee_id']);
  864. $org_id = $employee->org_id;
  865. $root_id = $employee->root_id;
  866. }
  867. $params['root_id'] = $root_id;
  868. $e_where[] = ['uid', '=', $this->user['id']];
  869. $e_where[] = ['state', 'in', ['在职', '待审核']];
  870. if ($root_id) {
  871. $e_where[] = ['root_id', '=', $root_id];
  872. }
  873. $isEmployee = Employee::where($e_where)->findOrEmpty();
  874. if (!$isEmployee->isEmpty()) return json(['code' => 1, 'msg' => '员工无需报价']);
  875. $id = QuoteRecordModel::insertGetId($params);
  876. $info = QuoteRecordModel::find($id);
  877. event(new FootPrints($this->user['id'], $params['employee_id'], $org_id ?? 0, $info, 'quote'));
  878. return json(['code' => 0, 'msg' => '恭喜您成功获取报价,稍后会有服务顾问跟您联系']);
  879. }
  880. /**
  881. * 楼盘催更新
  882. */
  883. public function urge()
  884. {
  885. $building_id = input('building_id', '', 'intval');
  886. $employee_id = input('employee_id', '', 'intval');
  887. $phone = input('mobile');
  888. $uid = $this->user['id'];
  889. $data['building_id'] = $building_id;
  890. $data['urge_uid'] = $uid;
  891. $data['employee_id'] = $employee_id;
  892. $data['root_id'] = Employee::where('id', $employee_id)->value('root_id');
  893. $result = BuildingUrge::create($data);
  894. if ($result) {
  895. $user = User::find($uid);
  896. $user_name = '客户';
  897. $user_phone = $phone ? $phone : '未获取';
  898. if (!empty($user)) {
  899. $user_name = $user['nickname'];
  900. }
  901. $building = BuildingModel::find($building_id);
  902. if (!empty($building)) {
  903. event(new Msg($employee_id, $user_name . '于' . date('Y-m-d H:i:s') . ' 催更' . $building['name'] . '施工进展。', 'building', $building_id));
  904. if (!empty($uid)) {
  905. $org_id = Employee::where('id', '=', $employee_id)->value('org_id');
  906. $building['phone'] = $user_phone;
  907. event(new FootPrints($uid, $employee_id, $org_id, $building, 'building_urge'));
  908. }
  909. }
  910. return json(['code' => 0, 'msg' => '催更成功']);
  911. } else {
  912. return json(['code' => 1, 'msg' => '操作失败']);
  913. }
  914. }
  915. public function construction()
  916. {
  917. $id = input('construction_id', '', 'intval');
  918. $p = input('p', '', 'trim');
  919. $data = $this->getContent($id, 'Construction');
  920. // 设置分享链接
  921. $jssdk = new JsSdk();
  922. $appid = config('app.official_appid');
  923. if (cache('?jsapi_ticket')) {
  924. $ticket = cache('jsapi_ticket');
  925. } else {
  926. // 获取普通access_token
  927. if (!$token = Cache::get('zqxg_offi_access_token')) {
  928. $token = getAccessToken($appid, config('app.official_secret'));
  929. Cache::set('zqxg_offi_access_token', $token, 7100);
  930. }
  931. $ticket = $jssdk->getJsApiTicket($token);
  932. cache('jsapi_ticket', $ticket, 7200);
  933. }
  934. $signPackage = $jssdk->getSignPackage($ticket);
  935. $signPackage['appid'] = $appid;
  936. View::assign('wxconfig', $signPackage);
  937. $aes = new Aes(config('app.jwt_key'));
  938. $queryData = $aes->decrypt($p);
  939. parse_str($queryData, $pArr);
  940. // 分享内容获取
  941. if (empty($data)) abort(404, '页面不存在');
  942. $employee_id = isset($pArr['employee_id']) ? intval($pArr['employee_id']) : 0;
  943. $leftToEmpId = Employee::where(['id' => $employee_id, 'state' => '离职'])->value('left_to_empid');
  944. if ($leftToEmpId) $employee_id = $leftToEmpId;
  945. $r = input('r');
  946. View::assign('r', $r);
  947. View::assign('p', $p);
  948. View::assign('getPhone', false);
  949. $data['share_employee'] = Employee::with(['user' => function ($query) {
  950. $query->field('id,headimgurl');
  951. }])->where(['id' => $employee_id])->field('id,uid,name,phone,qrcode,org_id')->find();
  952. $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
  953. if (!empty($this->user)) {
  954. // 分享关系创建
  955. if (!empty($data['share_employee'])) {
  956. $clue = $this->addClue($employee_id);
  957. if (!empty($clue) && $clue->phone)
  958. View::assign('getPhone', true);
  959. event(new FootPrints($this->user['id'], $data['share_employee']['id'], $data['share_employee']['org_id'], $data, lcfirst($pArr['type'])));
  960. $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();
  961. if ($foot) $visit = $foot->toArray();
  962. }
  963. View::assign('authorize', true);
  964. } else {
  965. View::assign('authorize', false);
  966. }
  967. View::assign('visit', $visit);
  968. View::assign('data', $data);
  969. return View::fetch();
  970. }
  971. //用户通过经纪人分享的活动报名
  972. public function agent_actsing()
  973. {
  974. $param = $this->request->only(['phone', 'sex', 'agent_id', 'aid']);
  975. $agtdata = AgentUser::where('id', $param['agent_id'])->find();
  976. if (empty($agtdata)) return json(['code' => 1, 'msg' => '所属经纪人信息为空']);
  977. if ($this->user['id'] == $agtdata['uid']) return json(['code' => 1, 'msg' => '您的身份是经纪人,不能参加活动']);
  978. $isEmployee = Employee::where(['uid' => $this->user['id']])->find();
  979. if ($isEmployee) return json(['code' => 1, 'msg' => '您的身份是业务员,不能参加活动']);
  980. $data['employee_id'] = $agtdata['agent_employee_id'];
  981. $data['org_id'] = $agtdata['org_id'];
  982. $data['state'] = 0;
  983. $data['level'] = 'C';
  984. $data['agents_id'] = $agtdata['id'];
  985. $data['agent_source_type'] = 2;
  986. $data['uid'] = $this->user['id'];
  987. $data['name'] = $this->user['nickname'];
  988. $data['sex'] = !empty($param['sex']) ? $param['sex'] : 1;
  989. $orgids = orgSubIds(!empty($this->user['root_id']) ? $this->user['root_id'] : $agtdata['root_id']);
  990. // 新建档,检测手机号是否重复
  991. $pharr = [$param['phone']];
  992. $tips = (new AgentsLogic())->checkPepeat($pharr, $orgids);
  993. if (!empty($tips)) return $tips;
  994. //检测用户是否已经建过档
  995. $aw[] = ['uid', '=', $this->user['id']];
  996. $aw[] = ['org_id', 'in', $orgids];
  997. $customer = Customer::where($aw)->find();
  998. if (!empty($customer)) {
  999. return json(['code' => 1, 'msg' => '报名失败,你已经报过名']);
  1000. }
  1001. //插入经济人提报的客户
  1002. $data['phone'] = cypherphone(trim($param['phone']));
  1003. Db::startTrans();
  1004. try {
  1005. $ms = Customer::insertGetId($data);
  1006. $empuid = Employee::where('id', $agtdata['agent_employee_id'])->value('uid');
  1007. $visitlog = CustomerVisitLog::where([['customer_id', '=', $ms], ['state', 'in', CustomerVisitLog::changeState('待确认', 'chaos')]])->find();
  1008. if (!$visitlog) {
  1009. $save = [];
  1010. $save['customer_id'] = $ms;
  1011. $save['type'] = '';
  1012. $save['remark'] = !empty($data['remark']) ? $data['remark'] : '通过经纪人分享的活动报名的客户';
  1013. $save['employee_id'] = $agtdata['agent_employee_id'];
  1014. $save['user_id'] = $empuid;
  1015. $save['state'] = 1;
  1016. //$save['aid'] = $param['aid'];
  1017. CustomerVisitLog::insertGetId($save);
  1018. }
  1019. if ($agtdata['type'] == 2) {
  1020. $rule_type = 'wanghong_integral';
  1021. $itg_rule = CreditsSetting::where([['code', '=', $rule_type], ['root_id', '=', $agtdata['root_id']]])->value('value');
  1022. //$itg_rule=json_decode($itg_rule,true);
  1023. $state = '网红活动录入客户';
  1024. $add = array(
  1025. 'agent_id' => $agtdata['id'],
  1026. 'type' => 4,
  1027. 'integral' => $itg_rule ? $itg_rule : 1,
  1028. 'addtime' => time(),
  1029. 'state' => $state,
  1030. 'customer_id' => $ms,
  1031. 'status' => 1
  1032. );
  1033. AgentIntegral::insert($add);
  1034. }
  1035. //生成活动二维码
  1036. //二维码内容,活动id,报名人uid
  1037. $qrcode_con = $param['aid'] . '&' . $ms . '&' . $this->user['id'];
  1038. $cate = Activity::where('id', $param['aid'])->value('cate');
  1039. $qrcode_con = $qrcode_con . '&' . $cate;
  1040. $name = uniqid() . '.jpg';
  1041. $path = 'activityqrcode/' . $name;
  1042. $img = qrcode($qrcode_con, 'upload/' . $name);
  1043. $res = ossUpload($path, 'upload/' . $name);
  1044. @unlink('upload/' . $name); //删除本地文件
  1045. ActivitySign::insertGetId([
  1046. 'aid' => $param['aid'],
  1047. 'root_id' => $orgids,
  1048. 'uid' => $this->user['id'],
  1049. 'share_uid' => $empuid,
  1050. 'share_employee_id' => $agtdata['agent_employee_id'],
  1051. 'qrcode' => $path,
  1052. 'qrcode_con' => $qrcode_con,
  1053. 'addtime' => date('Y-m-d H:i:s')
  1054. ]);
  1055. $ali_oss_bindurl = config('app.ali_oss_bindurl');
  1056. $url = 'https://' . $ali_oss_bindurl . '/' . $path;
  1057. Db::commit();
  1058. } catch (\Exception $e) {
  1059. Db::rollback();
  1060. var_dump($e->getMessage());
  1061. return json(['code' => 1, 'msg' => '报名数据失败.']);
  1062. }
  1063. if ($ms) {
  1064. return json(['code' => 0, 'msg' => '报名成功.']);
  1065. } else {
  1066. return json(['code' => 1, 'msg' => '报名失败.']);
  1067. }
  1068. }
  1069. //热装楼盘进度类型筛选
  1070. public function progress()
  1071. {
  1072. $id = input('id', '', 'intval');
  1073. $type = input('type', '', 'trim');
  1074. $where[] = ['building_id', '=', $id];
  1075. if (!empty($type)) {
  1076. $where[] = ['type', '=', $type];
  1077. }
  1078. $list = BuildingProgress::where($where)->order('addtime desc')->select();
  1079. if (empty($list)) $list = [];
  1080. else $list = $list->toArray();
  1081. $vrObj = new Vr();
  1082. foreach ($list as &$item) {
  1083. if (empty($item['vr'])) {
  1084. $item['vr'] = [];
  1085. continue;
  1086. }
  1087. $vrUrlList = explode(',', $item['vr']);
  1088. $vrData = [];
  1089. foreach ($vrUrlList as $url) {
  1090. $vrData[] = [
  1091. 'vrUrl' => urlencode($url),
  1092. 'vrfirstImg' => $vrObj->getFirstImg($url)
  1093. ];
  1094. }
  1095. $item['vr'] = $vrData;
  1096. }
  1097. return json(['code' => 0, 'data' => $list]);
  1098. }
  1099. //热装楼盘关联的案例
  1100. public function material_case()
  1101. {
  1102. $param = $this->request->param();
  1103. $building_id = input('building_id', '', 'intval');
  1104. $p = input('p');
  1105. $r = input('r');
  1106. if (!empty($p)) {
  1107. $aes = new Aes(config('app.jwt_key'));
  1108. $queryData = $aes->decrypt($p);
  1109. parse_str($queryData, $pArr);
  1110. }
  1111. $room = input('room', '', 'intval');
  1112. $c_where[] = ['building_id', '=', $building_id];
  1113. if (!empty($room)) {
  1114. $housetype_id = BuildingHousetype::where([['room', '=', $room], ['building_id', '=', $building_id]])->column('id');
  1115. $c_where[] = ['housetype_id', 'in', $housetype_id];
  1116. }
  1117. $ht_ids = BuildingMaterialCase::where([['building_id', '=', $building_id]])
  1118. ->group('housetype_id')
  1119. ->field('housetype_id,count(*)as count')
  1120. ->select()
  1121. ->toArray();
  1122. if (!empty($ht_ids)) {
  1123. foreach ($ht_ids as $key => $val) {
  1124. $ht_ids[$key]['room'] = BuildingHousetype::where('id', $val['housetype_id'])->value('room');
  1125. }
  1126. foreach ($ht_ids as $key => $val) {
  1127. $xin[$val['room']][] = $val;
  1128. }
  1129. $acn = 0;
  1130. foreach ($xin as $key => $val) {
  1131. $cn = 0;
  1132. foreach ($val as $k => $v) {
  1133. $cn += $v['count'];
  1134. $acn += $v['count'];
  1135. }
  1136. $a = ['room' => $key, 'count' => $cn];
  1137. $xa[] = $a;
  1138. }
  1139. $xa[] = ['room' => 0, 'count' => $acn];
  1140. }
  1141. $housetype_list = !empty($xa) ? $xa : [];
  1142. $case_ids = BuildingMaterialCase::where($c_where)->column('material_case_id');
  1143. $where[] = ['id', 'in', $case_ids];
  1144. setCondition($param, 'style_id', '=', $where);
  1145. setCondition($param, ['square_start', 'square'], '>=', $where);
  1146. setCondition($param, ['square_end', 'square'], '<', $where);
  1147. setCondition($param, ['keyword', 'title'], ['like', '%VALUE%'], $where);
  1148. $page = !empty($param['page']) ? $param['page'] : 1;
  1149. $limit = !empty($param['limit']) ? $param['limit'] : 15;
  1150. $list = MaterialCase::with(['designer' => function ($query) {
  1151. $query->field('id,name, headimgurl,addtime');
  1152. }, 'community' => function ($query) {
  1153. $query->field('id,name');
  1154. }, 'decostyle' => function ($query) {
  1155. $query->field('id,name');
  1156. }])->where($where)->page($page, $limit)->select();
  1157. $collectedIds = UserCollect::where(['user_id' => !empty($this->user['id']) ? $this->user['id'] : 0, 'content_type' => 'materialCase'])->column('content_id');
  1158. foreach ($list as &$item) {
  1159. if (in_array($item['id'], $collectedIds)) {
  1160. $item['collected'] = true;
  1161. } else {
  1162. $item['collected'] = false;
  1163. }
  1164. $param = [
  1165. 'id' => $item['id'],
  1166. 'type' => 'MaterialCase',
  1167. 'employee_id' => !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0
  1168. ];
  1169. $param = http_build_query($param);
  1170. $aes = new Aes(config('app.jwt_key'));
  1171. $query = 'index/index/content/r/' . $r . '/p/' . $aes->encrypt($param);
  1172. $domain = request()->domain();
  1173. $url = $domain . '/' . $query;
  1174. $item['url'] = $url;
  1175. if (!empty($item['vr_case'])) {
  1176. $item['vr_case'] = urlencode($item['vr_case']);
  1177. }
  1178. }
  1179. $data = ['list' => $list, 'housetype_list' => $housetype_list];
  1180. return json(['code' => 0, 'data' => $data, 'msg' => '获取成功']);
  1181. }
  1182. //研发案例列表
  1183. public function dev_case_list()
  1184. {
  1185. $id = input('id', '', 'intval');
  1186. if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']);
  1187. $list = BuildingDevelopCase::with(['decostyles'])->where('housetype_id', $id)
  1188. ->field('id,name,type,housetype_id,decostyles_id')
  1189. ->select();
  1190. return json(['code' => 0, 'data' => $list]);
  1191. }
  1192. //研发案例详情
  1193. public function dev_case_detail()
  1194. {
  1195. $id = input('id', '', 'intval');
  1196. $p = input('p');
  1197. $r = input('r');
  1198. if (!empty($p)) {
  1199. $aes = new Aes(config('app.jwt_key'));
  1200. $queryData = $aes->decrypt($p);
  1201. parse_str($queryData, $pArr);
  1202. }
  1203. $employee_id = !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0;
  1204. $uid = 0;
  1205. if (!empty($this->user)) {
  1206. $uid = $this->user['id'];
  1207. }
  1208. if (empty($id)) return json(['code' => 1, 'msg' => '参数错误']);
  1209. $data = BuildingDevelopCase::with(['decostyles'])->where('id', $id)->find();
  1210. if (!empty($data['vr_link'])) {
  1211. $data['vr_link'] = urlencode($data['vr_link']);
  1212. }
  1213. $domain = request()->domain();
  1214. $data['cont_link'] = $domain . '/index/index/dev_case_details.html?r=' . $r . '&id=' . $data['id'] . '&p=' . $p;
  1215. if (!empty($uid)) {
  1216. $org_id = Employee::where('id', '=', $employee_id)->value('org_id');
  1217. event(new FootPrints($uid, $employee_id, $org_id, $data, 'devcase'));
  1218. }
  1219. return json(['code' => 0, 'data' => $data]);
  1220. }
  1221. //研发案例h5图文详情
  1222. public function dev_case_details()
  1223. {
  1224. $id = input('id');
  1225. $r = input('r');
  1226. $p = input('p');
  1227. if (empty($id)) {
  1228. echo '参数错误';
  1229. exit;
  1230. }
  1231. $data = BuildingDevelopCase::with(['decostyles'])->where('id', $id)->find();
  1232. $share_content = strip_tags(preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $data['content']));
  1233. View::assign('share_content', $share_content);
  1234. if (!empty($p)) {
  1235. $aes = new Aes(config('app.jwt_key'));
  1236. $queryData = $aes->decrypt($p);
  1237. parse_str($queryData, $pArr);
  1238. }
  1239. $building_id = !empty($pArr['id']) ? $pArr['id'] : 0;
  1240. if (!empty($building_id)) {
  1241. $building_data = BuildingModel::where('id', $building_id)->find()->toArray();
  1242. }
  1243. View::assign('share_img', !empty($building_data['cover'][0]) ? $building_data['cover'][0] : '');
  1244. // 设置分享链接
  1245. $jssdk = new JsSdk();
  1246. $appid = config('app.official_appid');
  1247. if (cache('?jsapi_ticket')) {
  1248. $ticket = cache('jsapi_ticket');
  1249. } else {
  1250. // 获取普通access_token
  1251. if (!$token = Cache::get('zqxg_offi_access_token')) {
  1252. $token = getAccessToken($appid, config('app.official_secret'));
  1253. Cache::set('zqxg_offi_access_token', $token, 7100);
  1254. }
  1255. $ticket = $jssdk->getJsApiTicket($token);
  1256. cache('jsapi_ticket', $ticket, 7200);
  1257. }
  1258. $signPackage = $jssdk->getSignPackage($ticket);
  1259. $signPackage['appid'] = $appid;
  1260. View::assign('wxconfig', $signPackage);
  1261. $employee_id = !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0;
  1262. $uid = 0;
  1263. $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
  1264. if (!empty($this->user)) {
  1265. $uid = $this->user['id'];
  1266. }
  1267. if (!empty($uid)) {
  1268. $org_id = Employee::where('id', '=', $employee_id)->value('org_id');
  1269. event(new FootPrints($uid, $employee_id, $org_id, $data, 'devcase'));
  1270. $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();
  1271. if ($foot) $visit = $foot->toArray();
  1272. }
  1273. View::assign('visit', $visit);
  1274. View::assign('data', $data);
  1275. View::assign('r', $r);
  1276. View::assign('p', $p);
  1277. if (!empty($this->user)) {
  1278. $share_employee_id = Employee::where(['id' => $employee_id])->value('id');
  1279. // 分享关系创建
  1280. if (!empty($share_employee_id)) {
  1281. $this->addClue($employee_id);
  1282. }
  1283. View::assign('authorize', true);
  1284. } else {
  1285. View::assign('authorize', false);
  1286. }
  1287. return View::fetch();
  1288. }
  1289. //楼盘进度详情
  1290. public function progress_detail()
  1291. {
  1292. $id = input('id');
  1293. $r = input('r');
  1294. $p = input('p');
  1295. if (empty($id)) {
  1296. echo '参数错误';
  1297. exit;
  1298. }
  1299. $data = BuildingProgress::where('id', $id)->find();
  1300. $building_data = BuildingModel::where('id', $data['building_id'])->find();
  1301. $data['building_name'] = $building_data['name'];
  1302. $vrObj = new Vr();
  1303. if ($data['type'] == 'vr') {
  1304. $vrUrlList = explode(',', $data['vr']);
  1305. $vrData = [];
  1306. foreach ($vrUrlList as $url) {
  1307. $vrData[] = [
  1308. 'vrUrl' => urlencode($url),
  1309. 'vrfirstImg' => $vrObj->getFirstImg($url)
  1310. ];
  1311. }
  1312. $data['vr'] = $vrData;
  1313. }
  1314. $share_content = strip_tags(preg_replace('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', '', $data['content']));
  1315. View::assign('share_content', $share_content);
  1316. if (!empty($p)) {
  1317. $aes = new Aes(config('app.jwt_key'));
  1318. $queryData = $aes->decrypt($p);
  1319. parse_str($queryData, $pArr);
  1320. }
  1321. // $building_id = !empty($pArr['id']) ? $pArr['id'] : 0;
  1322. // if (!empty($building_id)) {
  1323. // $building_data = BuildingModel::where('id', $building_id)->find()->toArray();
  1324. // }
  1325. View::assign('share_img', !empty($building_data['cover'][0]) ? $building_data['cover'][0] : '');
  1326. // 设置分享链接
  1327. $jssdk = new JsSdk();
  1328. $appid = config('app.official_appid');
  1329. if (cache('?jsapi_ticket')) {
  1330. $ticket = cache('jsapi_ticket');
  1331. } else {
  1332. // 获取普通access_token
  1333. if (!$token = Cache::get('zqxg_offi_access_token')) {
  1334. $token = getAccessToken($appid, config('app.official_secret'));
  1335. Cache::set('zqxg_offi_access_token', $token, 7100);
  1336. }
  1337. $ticket = $jssdk->getJsApiTicket($token);
  1338. cache('jsapi_ticket', $ticket, 7200);
  1339. }
  1340. $signPackage = $jssdk->getSignPackage($ticket);
  1341. $signPackage['appid'] = $appid;
  1342. View::assign('wxconfig', $signPackage);
  1343. $employee_id = !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0;
  1344. $data['share_employee'] = Employee::with(['user' => function ($query) {
  1345. $query->field('id,headimgurl');
  1346. }])->where(['id' => $employee_id])->field('id,uid,name,phone,qrcode,org_id')->find();
  1347. $companyType = Miniprogram::where(['root_id' => $r])->value('notify');
  1348. $data['company_type'] = $companyType;
  1349. $uid = 0;
  1350. $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
  1351. if (!empty($this->user)) {
  1352. $uid = $this->user['id'];
  1353. }
  1354. if (!empty($uid)) {
  1355. $org_id = Employee::where('id', '=', $employee_id)->value('org_id');
  1356. event(new FootPrints($uid, $employee_id, $org_id, $data, 'progressDetail'));
  1357. $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();
  1358. if ($foot) $visit = $foot->toArray();
  1359. }
  1360. // 公司名获取
  1361. $data['company_name'] = Company::where(['root_id' => $r])->value('company_name');
  1362. View::assign('visit', $visit);
  1363. View::assign('data', $data);
  1364. View::assign('r', $r);
  1365. View::assign('p', $p);
  1366. if (!empty($this->user)) {
  1367. $share_employee_id = Employee::where(['id' => $employee_id])->value('id');
  1368. // 分享关系创建
  1369. if (!empty($share_employee_id)) {
  1370. $this->addClue($employee_id);
  1371. }
  1372. View::assign('authorize', true);
  1373. } else {
  1374. View::assign('authorize', false);
  1375. }
  1376. return View::fetch();
  1377. }
  1378. //热装楼盘户型接口
  1379. public function houseroom_list()
  1380. {
  1381. $id = input('id', '', 'intval');
  1382. //小区户型
  1383. $housetype = BuildingHousetype::with(['devcase' => function ($query) {
  1384. $query->field('housetype_id,id,name,type,vr_link,content,cover,decostyles_id');
  1385. }])->where('building_id', '=', $id)->withCount(['materialCase'])->select();
  1386. $xin = null;
  1387. $vrObj = new Vr();
  1388. if (!empty($housetype->toArray())) {
  1389. $domain = request()->domain();
  1390. $houselist = $housetype->toArray();
  1391. foreach ($houselist as $key => $val) {
  1392. if (empty($val['house_img']) && !empty($val['vr_link'])) {
  1393. $houselist[$key]['house_img'][] = $vrObj->getFirstImg($val['vr_link']);
  1394. }
  1395. if (empty($val['devcase'])) continue;
  1396. foreach ($val['devcase'] as $k => $v) {
  1397. $houselist[$key]['devcase'][$k]['decostyles_name'] = Decostyle::where('id', $v['decostyles_id'])->value('name');
  1398. $houselist[$key]['devcase'][$k]['area'] = $val['area'];
  1399. $houselist[$key]['devcase'][$k]['room'] = $val['room'];
  1400. $houselist[$key]['devcase'][$k]['hall'] = $val['hall'];
  1401. $houselist[$key]['devcase'][$k]['bathroom'] = $val['bathroom'];
  1402. if (!empty($v['vr_link'])) {
  1403. $houselist[$key]['devcase'][$k]['vr_link'] = urlencode($v['vr_link']);
  1404. }
  1405. if ($v['type'] == 1) {
  1406. $houselist[$key]['devcase'][$k]['cover'] = $vrObj->getFirstImg($v['vr_link']);
  1407. }
  1408. }
  1409. if (!empty($val['vr_link'])) {
  1410. $houselist[$key]['vr_link'] = urlencode($val['vr_link']);
  1411. }
  1412. }
  1413. foreach ($houselist as $key => $val) {
  1414. $houselist[$key]['housetype_cont_link'] = $val['housetype_cont_link'] = $domain . '/index/index/housetype.html?r=' . $val['root_id'] . '&id=' . $val['id'];
  1415. $xin[$val['room']][] = $val;
  1416. }
  1417. $xin[0] = $houselist;
  1418. }
  1419. return json(['code' => 0, 'list' => $xin, 'msg' => '获取成功']);
  1420. }
  1421. //h5户型详情
  1422. public function housetype()
  1423. {
  1424. $id = input('id', '', 'intval');
  1425. $r = input('r');
  1426. $p = input('p');
  1427. if (empty($id)) {
  1428. echo '参数错误';
  1429. exit;
  1430. }
  1431. View::assign('r', $r);
  1432. $info = $data = BuildingHousetype::where([['id','=',$id],['root_id','=',$r]])->findOrEmpty();
  1433. if($info->isEmpty()){
  1434. echo '参数错误';
  1435. exit;
  1436. }
  1437. $info['new_orientation'] = $info->getData('orientation');
  1438. $info['vr_link_img'] = '';
  1439. if (!empty($info['vr_link'])) {
  1440. $vrObj = new Vr();
  1441. $info['vr_link_img'] = $vrObj->getFirstImg($info['vr_link']);
  1442. }
  1443. View::assign('info', $info);
  1444. View::assign('p', $p);
  1445. //查询楼盘地址和小区
  1446. $build = BuildingModel::where('id',$info->building_id)->field('community_id,address')->findOrEmpty();
  1447. if (!$build->isEmpty()){
  1448. $build->community = $build->community_id ? Community::where('id',$build->community_id)->value('name') : '';
  1449. }
  1450. View::assign('build', $build);
  1451. //分享人信息
  1452. $aes = new Aes(config('app.jwt_key'));
  1453. $queryData = $aes->decrypt($p);
  1454. parse_str($queryData, $pArr);
  1455. $employee_id = isset($pArr['employee_id']) ? intval($pArr['employee_id']) : 0;
  1456. $leftToEmpId = Employee::where(['id' => $employee_id, 'state' => '离职'])->value('left_to_empid');
  1457. if ($leftToEmpId) $employee_id = $leftToEmpId;
  1458. //关联案例
  1459. $case_ids = BuildingMaterialCase::where([['housetype_id','=',$id],['root_id','=',$r]])->column('material_case_id');
  1460. $case = [];
  1461. if($case_ids){
  1462. $where[] = ['id', 'in', $case_ids];
  1463. $case = MaterialCase::with(['decostyle' => function ($query) {
  1464. $query->field('id,name')->bind(['decostyle_name'=>'name']);
  1465. }])->where($where)->limit(4)->select()->toArray();
  1466. }
  1467. foreach ($case as &$item) {
  1468. $param = [
  1469. 'id' => $item['id'],
  1470. 'type' => 'MaterialCase',
  1471. 'employee_id' => !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0
  1472. ];
  1473. $param = http_build_query($param);
  1474. $query = 'index/index/content/r/' . $r . '/p/' . $aes->encrypt($param);
  1475. $domain = request()->domain();
  1476. $url = $domain . '/' . $query;
  1477. $item['url'] = $url;
  1478. if (!empty($item['vr_case'])) {
  1479. $item['vr_case'] = urlencode($item['vr_case']);
  1480. }
  1481. }
  1482. View::assign('case', $case);
  1483. //关联在施工地
  1484. $construction_id = $info->constructionid ? explode(',',$info->constructionid) : [];
  1485. $where = [];
  1486. $where[] = ['id', 'in', $construction_id];
  1487. $where[] = ['root_id', '=', $r];
  1488. $con = ConstructionModel::with(['housetype','community'])->where($where)->limit(4)->select()->toArray();
  1489. //施工进程查询
  1490. $record_list = ConstructionRecord::where([['construction_id', 'in', array_column($con,'id')]])->group('construction_id')->column('max(step_id)','construction_id');
  1491. $sid = array_values($record_list);
  1492. $step_list = ConstructionStep::where([['root_id', '=', $r]])->column('name,id');
  1493. $step_arr = array_column($step_list,'name','id');
  1494. $now_step = !empty($step_list[0]['name']) ? $step_list[0]['name'] : '';//第一个施工进度
  1495. foreach ($con as $key => $value) {
  1496. $con[$key]['hname'] = isset($value['housetype']['name']) ? $value['housetype']['name'] : '';
  1497. $con[$key]['cname'] = isset($value['community']['name']) ? $value['community']['name'] : '';
  1498. //施工进度
  1499. $con[$key]['progress'] = !isset($record_list[$value['id']]) ? $now_step : $step_arr[$record_list[$value['id']]];
  1500. $param = [
  1501. 'id' => $value['id'],
  1502. 'type' => 'construction',
  1503. 'employee_id' => !empty($pArr['employee_id']) ? $pArr['employee_id'] : 0
  1504. ];
  1505. $param = http_build_query($param);
  1506. $con[$key]['p'] = $aes->encrypt($param);
  1507. }
  1508. View::assign('con', $con);
  1509. View::assign('getPhone', false);
  1510. $data['share_employee'] = Employee::with(['user' => function ($query) {
  1511. $query->field('id,headimgurl');
  1512. }])->where(['id' => $employee_id])->field('id,uid,name,phone,qrcode,org_id')->find();
  1513. $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
  1514. if (!empty($this->user)) {
  1515. // 分享关系创建
  1516. if (!empty($data['share_employee'])) {
  1517. $clue = $this->addClue($employee_id);
  1518. if (!empty($clue) && $clue->phone)
  1519. View::assign('getPhone', true);
  1520. event(new FootPrints($this->user['id'], $data['share_employee']['id'], $data['share_employee']['org_id'], $data, lcfirst($pArr['type'])));
  1521. $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();
  1522. if (isset($foot)) $visit = $foot->toArray();
  1523. }
  1524. View::assign('authorize', true);
  1525. } else {
  1526. View::assign('authorize', false);
  1527. }
  1528. View::assign('visit', $visit);
  1529. $company = Company::where('root_id', '=', $r)->field(['id', 'company_name', 'logo', 'company_address', 'root_id'])->find();
  1530. $companyType = Miniprogram::where(['root_id' => $r])->value('notify');
  1531. $data['company_name'] = $company['company_name'];
  1532. $data['company_logo'] = $company['logo'];
  1533. $data['company_address'] = $company['company_address'];
  1534. $data['company_type'] = $companyType;
  1535. $data['name'] = $info->room.'室'.$info->hall.'厅'.$info->bathroom.'卫';
  1536. View::assign('data', $data);
  1537. // 设置分享链接
  1538. $jssdk = new JsSdk();
  1539. $appid = config('app.official_appid');
  1540. if (cache('?jsapi_ticket')) {
  1541. $ticket = cache('jsapi_ticket');
  1542. } else {
  1543. // 获取普通access_token
  1544. if (!$token = Cache::get('zqxg_offi_access_token')) {
  1545. $token = getAccessToken($appid, config('app.official_secret'));
  1546. Cache::set('zqxg_offi_access_token', $token, 7100);
  1547. }
  1548. $ticket = $jssdk->getJsApiTicket($token);
  1549. cache('jsapi_ticket', $ticket, 7200);
  1550. }
  1551. $signPackage = $jssdk->getSignPackage($ticket);
  1552. $signPackage['appid'] = $appid;
  1553. View::assign('wxconfig', $signPackage);
  1554. View::assign('share_content', $build->community);
  1555. View::assign('share_img', $info->house_img ? $info->house_img[0] : ($info['vr_link_img'] ?: ''));
  1556. return View::fetch();
  1557. }
  1558. //热装楼盘关联案例风格接口
  1559. public function housetype_list()
  1560. {
  1561. $r = input('r', '', 'intval');
  1562. $styleArr = Decostyle::where([['root_id', '=', $r]])->where([['type', '=', 0]])->field('id, name')->select();
  1563. return json(['code' => 0, 'data' => $styleArr, 'msg' => '获取成功']);
  1564. }
  1565. /**
  1566. * 已存在的客户访问新店面时,复制user信息
  1567. * @param $user
  1568. * @param $new_root
  1569. */
  1570. private function copyUser($user, $new_root)
  1571. {
  1572. $where[] = ['unionid', '=', $user['unionid']];
  1573. $where[] = ['root_id', '=', $new_root];
  1574. $find = User::where($where)->findOrEmpty();
  1575. if ($find->isEmpty()) {
  1576. unset($user['id']);
  1577. $user['root_id'] = $new_root;
  1578. $user = User::create($user);
  1579. $this->user = $user;
  1580. } else {
  1581. $this->user = $find;
  1582. }
  1583. }
  1584. /**
  1585. * 修改浏览时长
  1586. */
  1587. public function visitDueTime()
  1588. {
  1589. $id = input('id');
  1590. $visit_time = input('visit_time');
  1591. $time = input('time');
  1592. $where = ['id' => $id, 'addtime' => $visit_time];
  1593. ModelFootprints::where($where)->update(['visit_due_time' => $time]);
  1594. //增加记录素材的浏览时长到素材表
  1595. $data = ModelFootprints::where($where)->find();
  1596. $reg_info = !empty($data['reg_info']) ? json_decode($data->getData('reg_info'),true) : ['id'=>0];
  1597. if(!empty($time) && !empty($data['pipe_type']) && in_array($data['pipe_type'],['article','materialEvidence','materialCase','CompanyStrength','video'])){
  1598. $class = 'app\\model\\' . ucfirst($data['pipe_type']);
  1599. if (!class_exists($class)) return json(['code' =>1, 'msg' => '类型不存在']);
  1600. $datas = (new $class())->where(['id' => $reg_info['id']])->find();
  1601. $old_due_time = $datas->visit_due_time;
  1602. $datas->visit_due_time = $old_due_time + $time;
  1603. $datas->save();
  1604. }
  1605. return json(['code' => 0, 'msg' => '操作成功']);
  1606. }
  1607. /**
  1608. * vr展示页面
  1609. * @param [type] $p [description]
  1610. * @return [type] [description]
  1611. */
  1612. public function vr($p)
  1613. {
  1614. $param = $this->request->only(['id', 'type', 'vr_link']);
  1615. if (!in_array($param['type'], ['materialCase', 'building', 'construction', 'company','buildingHousetype'])) {
  1616. return json(['code' => 1, 'msg' => '类型错误']);
  1617. }
  1618. $className = 'app\\model\\' . ucfirst($param['type']);
  1619. if($param['type'] == 'company') $className = 'app\\model\\CompanyVrshow';
  1620. $obj = new $className();
  1621. $field = 'id';
  1622. $data = $obj->where($field, $param['id'])->find();
  1623. // 足迹
  1624. $aes = new Aes(config('app.jwt_key'));
  1625. $queryData = $aes->decrypt($p);
  1626. parse_str($queryData, $token);
  1627. $params['employee_id'] = isset($token['employee_id']) ? intval($token['employee_id']) : 0;
  1628. $root_id = '';
  1629. $employee = [];
  1630. if (!empty($params['employee_id'])) {
  1631. $employee = Employee::with('userImg')->field('id,uid,org_id,root_id,name,phone')->find($params['employee_id']);
  1632. $org_id = $employee->org_id;
  1633. $root_id = $employee->root_id;
  1634. }
  1635. $params['root_id'] = $root_id;
  1636. $visit = ['id' => 0, 'addtime' => date('Y-m-d H:i:s')];
  1637. if (!empty($this->user)) {
  1638. if (!empty($params['employee_id'])) {
  1639. event(new FootPrints($this->user['id'], $params['employee_id'], $org_id ?? 0, $data, $param['type'] . 'Vr'));
  1640. $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();
  1641. if ($foot) $visit = $foot->toArray();
  1642. // 分享关系创建
  1643. $this->addClue($params['employee_id']);
  1644. }
  1645. View::assign('authorize', true);
  1646. } else {
  1647. View::assign('authorize', false);
  1648. }
  1649. View::assign('visit', $visit);
  1650. $r = input('r');
  1651. View::assign('r', $r);
  1652. View::assign('p', $p);
  1653. View::assign('type', $param['type']);
  1654. View::assign('vr', urldecode($param['vr_link']));
  1655. View::assign('employee', $employee);
  1656. // 设置分享链接
  1657. $jssdk = new JsSdk();
  1658. $appid = config('app.official_appid');
  1659. if (cache('?jsapi_ticket')) {
  1660. $ticket = cache('jsapi_ticket');
  1661. } else {
  1662. // 获取普通access_token
  1663. if (!$token = Cache::get('zqxg_offi_access_token')) {
  1664. $token = getAccessToken($appid, config('app.official_secret'));
  1665. Cache::set('zqxg_offi_access_token', $token, 7100);
  1666. }
  1667. $ticket = $jssdk->getJsApiTicket($token);
  1668. cache('jsapi_ticket', $ticket, 7200);
  1669. }
  1670. $signPackage = $jssdk->getSignPackage($ticket);
  1671. $signPackage['appid'] = $appid;
  1672. View::assign('wxconfig', $signPackage);
  1673. $data['share_employee'] = Employee::with(['user' => function ($query) {
  1674. $query->field('id,headimgurl');
  1675. }])->where(['id' => $params['employee_id']])->field('id,uid,name,phone,qrcode,org_id')->find();
  1676. $company = Company::where('root_id', '=', $root_id)->field(['id', 'company_name', 'logo', 'company_address', 'root_id'])->find();
  1677. $companyType = Miniprogram::where(['root_id' => $company->root_id])->value('notify');
  1678. $data['company_name'] = $company['company_name'];
  1679. $data['company_logo'] = $company['logo'];
  1680. $data['company_address'] = $company['company_address'];
  1681. $data['company_type'] = $companyType;
  1682. View::assign('data', $data);
  1683. return View::fetch();
  1684. }
  1685. /**
  1686. * 通过经纪人分享的内容,用户进行报名(h5)
  1687. */
  1688. public function add_customer()
  1689. {
  1690. $param = $this->request->only(['name', 'phone', 'community_name', 'agent_id']);
  1691. $agtdata = AgentUser::where(['id' => $param['agent_id'], 'root_id' => $this->user['root_id']])->find();
  1692. if (empty($agtdata)) return json(['code' => 1, 'msg' => '推荐人信息未查询到']);
  1693. if ($this->user['id'] == $agtdata['uid']) return json(['code' => 1, 'msg' => '您的身份是推荐人,不能报名']);
  1694. $isEmployee = Employee::where([['uid', '=', $this->user['id']], ['state', 'in', ['在职', '待审核']], ['root_id', '=', $this->user['root_id']]])->findOrEmpty();
  1695. if (!$isEmployee->isEmpty()) return json(['code' => 1, 'msg' => '您已加入企业,无法报名']);
  1696. // 添加客户检测手机号的重复
  1697. $tips = (new AgentsLogic())->checkPepeat([$param['phone']], orgSubIds($agtdata['org_id']));
  1698. if (!empty($tips)) return $tips;
  1699. $data = [
  1700. 'employee_id' => $agtdata['agent_employee_id'],
  1701. 'org_id' => $agtdata['org_id'],
  1702. 'state' => 0,
  1703. 'name' => $param['name'],
  1704. 'phone' => cypherphone(trim($param['phone'])),
  1705. 'community_name' => $param['community_name'],
  1706. 'sex' => 1,
  1707. 'agents_id' => $agtdata['id'],
  1708. 'agent_source_type' => 3
  1709. ];
  1710. //保存报备的客户
  1711. Db::startTrans();
  1712. try {
  1713. // 更新线索电话
  1714. $condition = [
  1715. 'employee_id' => $agtdata['agent_employee_id'],
  1716. 'uid' => $this->user['id'],
  1717. 'org_id' => $agtdata['org_id']
  1718. ];
  1719. // 更新线索信息,并默认报备状态
  1720. $had = CustomerClue::where($condition)->find();
  1721. if (empty($had->phone)) {
  1722. $had->phone = $param['phone'];
  1723. $had->state = 1;
  1724. $had->save();
  1725. }
  1726. $data['clue_id'] = $had['id'];
  1727. $ms = Customer::insertGetId($data);
  1728. $empuid = Employee::where('id', $agtdata['agent_employee_id'])->value('uid');
  1729. $log = [
  1730. 'employee_id' => $agtdata['agent_employee_id'],
  1731. 'customer_id' => $ms,
  1732. 'type' => '',
  1733. 'remark' => '通过推荐人分享的内容报名的客户',
  1734. 'user_id' => $empuid,
  1735. 'state' => 1,
  1736. 'org_id' => $agtdata['org_id']
  1737. ];
  1738. CustomerVisitLog::insertGetId($log);
  1739. // 足迹
  1740. if (!empty($this->user['id']) && $isEmployee->isEmpty()) {
  1741. $footerArr = [
  1742. 'name'=>$param['name'],
  1743. 'phone'=>$param['phone'],
  1744. 'community_name'=>$param['community_name'],
  1745. ];
  1746. event(new FootPrints($this->user['id'], $agtdata['agent_employee_id'] ?? 0, $agtdata['org_id'] ?? 0, $footerArr, 'agentShareContentCrm'));
  1747. }
  1748. Db::commit();
  1749. return json(['code' => 0, 'msg' => '报名成功']);
  1750. } catch (\Exception $e) {
  1751. Db::rollback();
  1752. return json(['code' => 1, 'msg' => '报名失败']);
  1753. }
  1754. }
  1755. }