Footprints.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. use app\model\Miniprogram;
  5. use think\facade\Cache;
  6. use wx\offiaccount\msg\Template;
  7. class Footprints extends Model
  8. {
  9. public function employee()
  10. {
  11. return $this->belongsTo(Employee::class, 'employee_id')->bind(['employee_name' => 'name']);
  12. }
  13. public function getRegInfoAttr($value, $data)
  14. {
  15. $info = json_decode($value, true);
  16. switch ($data['pipe_type']) {
  17. case 'wwbm':
  18. $name = '';
  19. if (isset($info['name'])) {
  20. $name = $info['name'];
  21. }
  22. $remark = '';
  23. if (isset($info['remark'])) {
  24. $remark = $info['remark'];
  25. }
  26. $content = '#微网报名#姓名:' . $name . ',面积:' . $remark;
  27. !isset($info['phone']) ?: $content .= ',手机号:' . $info['phone'];
  28. break;
  29. case 'activity':
  30. $content = '#活动#《' . $info['title'] . '》';
  31. break;
  32. case 'materialCase':
  33. $content = '#案例#《' . $info['title'] . '》';
  34. break;
  35. case 'materialEvidence':
  36. $content = '#口碑见证#《' . $info['title'] . '》';
  37. break;
  38. case 'priceCalculation':
  39. $info = json_decode($info['value'], true);
  40. $name = '';
  41. if (isset($info['name'])) {
  42. $name = '姓名:' . $info['name'] . ',';
  43. }
  44. //$content = '#装修报价#' . $name . '手机号:' . $info['mobile'] . ',小区:' . $info['community'] . ',面积:' . $info['area'] . ',户型:' . $info['bedroom'] . ',风格:' . $info['style'] . ',房屋类型:' . $info['type'];
  45. $content = '#装修报价#' . $name . '手机号:' . $info['mobile'] . ',小区:' . $info['community'] . ',面积:' . $info['area'];
  46. break;
  47. case 'styleTest':
  48. $info = json_decode($info['value'], true);
  49. $content = '#家装风格测一测#' . $info['style'];
  50. break;
  51. case 'likeTest':
  52. $info = json_decode($info['value'], true);
  53. $content = '#老房翻新风格测一测#' . $info['style'];
  54. break;
  55. case 'toolDecohelper':
  56. $content = '#装修知识#《' . $info['title'] . '》';
  57. break;
  58. case 'video':
  59. $content = '#视频#《' . $info['title'] . '》';
  60. break;
  61. case 'share':
  62. $name = '';
  63. if (isset($info['name'])) {
  64. $name = '姓名:' . $info['name'] . ',';
  65. }
  66. $title = isset($info['data']['title']) ? $info['data']['title'] : (isset($info['data']['name']) ? $info['data']['name'] : '');
  67. $content = '#链接分享报名#《' . $title . '》' . $name . '手机号:' . $info['mobile'];
  68. break;
  69. case 'article':
  70. $content = '#图文素材#《' . $info['title'] . '》';
  71. break;
  72. case 'building':
  73. $name = isset($info['name']) ? $info['name'] : '';
  74. $title = isset($info['prompt']) ? '('.$info['prompt'].')' : '';
  75. $content = '#楼盘'.$title.'#《' . $name . '》';
  76. break;
  77. case 'construction':
  78. $name = isset($info['name']) ? $info['name'] : '';
  79. $content = '#在施工地#《' . $name . '》';
  80. break;
  81. case 'designer':
  82. $designer_name = isset($info['title']) ? $info['title'] : '';
  83. // 预约设计师来源
  84. if (!empty($info['share_pipe_type'])) {
  85. switch ($info['share_pipe_type']) {
  86. case 'materialCase':
  87. $material_case = MaterialCase::where('id', '=', $info['share_data_id'])->findOrEmpty();
  88. if (!$material_case->isEmpty()) {
  89. if (!empty($info['mobile'])) {
  90. $content = "从装修案例《" . $material_case['title'] . "》中预约了" . $designer_name . "设计师,手机号" . $info['mobile'];
  91. } else {
  92. $content = "从装修案例《" . $material_case['title'] . "》中预约了" . $designer_name . "设计师";
  93. }
  94. } else {
  95. $content = !empty($info['mobile']) ? "从装修案例中预约了" . $designer_name . "设计师,手机号" . $info['mobile'] : "从装修案例中预约了" . $designer_name . "设计师";
  96. }
  97. break;
  98. case 'designer':
  99. $content = "从设计师列表预约了" . $designer_name . "设计师";
  100. break;
  101. default:
  102. $content = "预约了" . $designer_name . "设计师";
  103. break;
  104. }
  105. } else {
  106. $content = "查看了" . $designer_name . "设计师";
  107. }
  108. break;
  109. case 'card':
  110. $content = "访问了您的名片";
  111. break;
  112. case 'quote':
  113. $area = $info['area'] ? $info['area'] . "m²" : "未填写";
  114. $content = "#装修报价#\r\n面积:" . $area . "\r\n户型:" . $info['room'] . "室" . $info['hall'] . "厅" . $info['bathroom'] . "卫\r\n" . "手机号:" . $info['phone'];/* . "\r\n报价时间:" . $info['addtime']*/;
  115. break;
  116. case 'companyStrength': //新版
  117. $content = !empty($info) ? '#公司实力#《' . $info['title'] . '》' : '';
  118. break;
  119. case 'CompanyStrength': //旧版
  120. $content = !empty($info) ? '#公司实力#《' . $info['title'] . '》' : '';
  121. break;
  122. case 'building_urge':
  123. $name = isset($info['name']) ? $info['name'] : '';
  124. $content = !empty($info['phone']) ? "催更了《" . $name . "》楼盘,手机号" . $info['phone'] : "催更了《" . $name . "》楼盘";
  125. break;
  126. case 'askedfitup':
  127. $content = !empty($info['phone']) ? "#询问装修#手机号" . $info['phone'] : '#询问装修#手机号 未获取';
  128. break;
  129. case 'lottery':
  130. $act_type = $info['type'] == 1 ? '大转盘' : '砸金蛋';
  131. $content = !empty($info['luckname']) ? "#参加" . $info['title'] . $act_type . "活动#中奖奖品为" . $info['luckname'] : "#参加" . $info['title'] . $act_type . "活动#";
  132. break;
  133. case 'materialCaseVr':
  134. $content = '#案例VR#《' . $info['title'] . '》';
  135. break;
  136. case 'buildingVr':
  137. $name = isset($info['name']) ? $info['name'] : '';
  138. $content = '#楼盘进度VR#《' . $name . '》';
  139. break;
  140. case 'companyVr':
  141. $title = !empty($info['name']) ? $info['name'] : '';
  142. $content = "访问了您的".$title."VR展厅";
  143. break;
  144. case 'employeeCardVr':
  145. $content = "访问了您的VR名片";
  146. break;
  147. case 'constructionVr':
  148. $name = isset($info['name']) ? $info['name'] : '';
  149. $content = '#在施工地VR#《' . $name . '》';
  150. break;
  151. case 'getDecorationDesign':
  152. $mobile = (isset($info['mobile']) && !empty($info['mobile'])) ? $info['mobile'] : '';
  153. $content = "#免费领取设计方案#小区:" . $info['community'] . ',面积' . $info['area'] . ',户型' . $info['bedroom'] . ',电话:' . $mobile;
  154. break;
  155. case 'toolAll':
  156. $content = !empty($info['type']) ? "访问了您的谈单工具《" . $info['type'] . '》' : "访问了您的谈单工具";
  157. break;
  158. case 'agents':
  159. //$info = json_decode($info['value'], true);
  160. $name = '';
  161. if (isset($info['agent_name'])) {
  162. $name = '姓名:' . $info['agent_name'] . ',';
  163. }
  164. $content = '#经纪人#' . $name . '手机号:' . $info['agent_phone'];
  165. break;
  166. case 'spellgroup':
  167. $content = "访问了您的装修拼团";
  168. break;
  169. case 'weiwang':
  170. $content = "访问了您的个人微网";
  171. break;
  172. case 'devcase':
  173. $devcase_type = BuildingDevelopCase::where('id', $info['id'])->value('type');
  174. $case_type = $devcase_type == 1 ? 'VR' : '图文';
  175. $name = isset($info['name']) ? $info['name'] : '';
  176. $content = '#研发案例#类别:' . $case_type . ' 案例标题:' . $name;
  177. break;
  178. case 'progressDetail':
  179. $name = isset($info['name']) ? $info['name'] : '';
  180. $content = '#楼盘进度详情#' . $name;
  181. break;
  182. case 'agentArticle':
  183. $content = '#经纪人分享文章#' . $info['title'];
  184. break;
  185. case 'groupVr':
  186. $title = $info['title'] ?: '未命名作品';
  187. $title = isset($info['prompt']) ? '浏览了'.$info['prompt'].'的VR作品“'.$title.'”' : $title;
  188. $content = '#vr作品#' . $title;
  189. break;
  190. case 'groupVrVr':
  191. $title = $info['title'] ?: '未命名作品';
  192. $title = isset($info['prompt']) ? '浏览了'.$info['prompt'].'的VR作品“'.$title.'”' : $title;
  193. $content = '#vr作品#' . $title;
  194. break;
  195. case 'agentShareContentCrm':
  196. $name = '';
  197. if (isset($info['name']) && !empty($info['name'])) {
  198. $name = '姓名:' . $info['name'] . ',';
  199. }
  200. $community_name = '';
  201. if (isset($info['community_name']) && !empty($info['community_name'])) {
  202. $community_name = ',小区:' . $info['community_name'];
  203. }
  204. $phone = !empty($info['phone']) ? $info['phone'] : '暂无';
  205. $content = '#经纪人分享内容客户报名信息#' . $name . '手机号:' . $phone . $community_name;
  206. break;
  207. case 'TrainClassList':
  208. $content = '访问了您的课程列表';
  209. break;
  210. case 'TrainClass':
  211. $content = '访问了'.$info['title'].'课程';
  212. break;
  213. case 'TrainCourse':
  214. $content = '访问了'.$info['class_title'].'-'.$info['title'].'课件';
  215. break;
  216. case 'housetype':
  217. $content = "户型:" . $info['room'] . "室" . $info['hall'] . "厅" . $info['bathroom'] . "卫";
  218. break;
  219. case 'housetypeVr':
  220. $size = $info['room'] . "室" . $info['hall'] . "厅" . $info['bathroom'] . "卫";
  221. if(!isset($info['prompt'])){
  222. $content = "户型:" . $size;
  223. }else{
  224. $content = '浏览了户型【'.$info['prompt'].'】的VR作品';
  225. }
  226. break;
  227. case 'buildingHousetype':
  228. $content = "户型:" . $info['room'] . "室" . $info['hall'] . "厅" . $info['bathroom'] . "卫";
  229. break;
  230. default:
  231. $content = '';
  232. break;
  233. }
  234. return $content;
  235. }
  236. public function customer()
  237. {
  238. return $this->hasOne(Customer::class, 'uid', 'uid');
  239. }
  240. public function user()
  241. {
  242. return $this->hasOne(User::class, 'id', 'uid')->bind(['headimgurl' => 'headimgurl']);
  243. }
  244. /**
  245. * 发送公众号消息
  246. */
  247. public static function onAfterInsert($info)
  248. {
  249. $employee = Employee::field('official_openid,root_id')->where('id', $info['employee_id'])->find();
  250. if (empty($employee) || empty($employee['root_id'])) return true; //数据问题,防止报错
  251. // 如果是员工足迹产生(包含在职,待审核)
  252. $isEmployee = Employee::where([['uid', '=', $info['uid']], ['root_id', '=', $employee['root_id']], ['state', 'in', ['在职', '待审核']]])->find();
  253. if ($isEmployee) return true;
  254. $miniAppid = Miniprogram::where('root_id', $employee['root_id'])->find();
  255. if (empty($employee['official_openid'])) return true;
  256. $nickname = User::where('id', $info['uid'])->value('nickname');
  257. $first = '客户' . $nickname;
  258. //新增浏览数据后给业务员发送公众号消息
  259. $operation = [
  260. 'wwbm' => '通过',
  261. 'activity' => '浏览了',
  262. 'materialCase' => '浏览了',
  263. 'materialEvidence' => '浏览了',
  264. 'priceCalculation' => '浏览了',
  265. 'styleTest' => '浏览了',
  266. 'likeTest' => '浏览了',
  267. 'toolDecohelper' => '浏览了',
  268. 'video' => '浏览了',
  269. 'share' => '通过',
  270. 'article' => '浏览了',
  271. 'building' => '浏览了',
  272. 'construction' => '浏览了',
  273. 'designer' => '',
  274. 'card' => '',
  275. 'quote' => '浏览了',
  276. 'companyStrength' => '浏览了',
  277. 'CompanyStrength' => '浏览了',
  278. 'building_urge' => '',
  279. 'askedfitup' => '浏览了',
  280. 'lottery' => '',
  281. 'materialCaseVr' => '浏览了',
  282. 'buildingVr' => '浏览了',
  283. 'companyVr' => '',
  284. 'employeeCardVr' => '',
  285. 'constructionVr' => '浏览了',
  286. 'getDecorationDesign' => '浏览了',
  287. 'toolAll' => '',
  288. 'agents' => '浏览了',
  289. 'spellgroup' => '',
  290. 'weiwang' => '',
  291. 'devcase' => '浏览了',
  292. 'progressDetail' => '浏览了',
  293. 'agentArticle' => '浏览了',
  294. 'housetype'=> '浏览了',
  295. 'buildingHousetype'=> '浏览了',
  296. 'groupVr'=> '浏览了',
  297. 'groupVrVr'=> '浏览了',
  298. ];
  299. if (!isset($operation[$info['pipe_type']])) return true;
  300. $msg = $first . $operation[$info['pipe_type']] . $info['reg_info'];
  301. $wxTemp = new Template();
  302. if (!$token = Cache::get('zqxg_offi_access_token')) {
  303. $appid = config('app.official_appid');
  304. $token = $wxTemp->getAccessToken($appid, config('app.official_secret'));
  305. Cache::set('zqxg_offi_access_token', $token, 7100);
  306. }
  307. //通知编号
  308. $day = date('Y-m-d');
  309. $count = Footprints::where([['employee_id', '=', $info->employee_id], ['addtime', 'like', '%' . $day . '%']])->count();
  310. $number = date('Ymd') . $count;
  311. //本月累计
  312. $month = date('Y-m');
  313. $month_count = Footprints::where([['employee_id', '=', $info->employee_id], ['addtime', 'like', '%' . $month . '%']])->count();
  314. $rs = $wxTemp->sendTemplateMsg($token, [
  315. "touser" => $employee->official_openid,
  316. "template_id" => "H0zPfXZX7JyjgZp8PtZSjxBraoXjunDYKqM5x_PlDQM",
  317. "miniprogram" => [
  318. "appid" => $miniAppid->appid,
  319. "pagepath" => "/pages/index/index?office_type=clue_radar&clientype=" . $miniAppid->notify
  320. ],
  321. "data" => [
  322. "first" => [
  323. "value" => "新增一条客户足迹,请及时跟进",
  324. "color" => "#173177"
  325. ],
  326. "keyword1" => [
  327. "value" => '新增浏览记录通知',
  328. "color" => "#173177"
  329. ],
  330. "keyword2" => [
  331. "value" => $number,
  332. "color" => "#173177"
  333. ],
  334. "keyword3" => [
  335. "value" => $msg,
  336. "color" => "#173177"
  337. ],
  338. "remark" => [
  339. "value" => '本月累计' . $month_count . '条浏览记录',
  340. "color" => "#173177"
  341. ]
  342. ]
  343. ]);
  344. return true;
  345. }
  346. }