123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <?php
- namespace app\model;
- use think\Model;
- use app\model\Miniprogram;
- use think\facade\Cache;
- use wx\offiaccount\msg\Template;
- class Footprints extends Model
- {
- public function employee()
- {
- return $this->belongsTo(Employee::class, 'employee_id')->bind(['employee_name' => 'name']);
- }
- public function getRegInfoAttr($value, $data)
- {
- $info = json_decode($value, true);
- switch ($data['pipe_type']) {
- case 'wwbm':
- $name = '';
- if (isset($info['name'])) {
- $name = $info['name'];
- }
- $remark = '';
- if (isset($info['remark'])) {
- $remark = $info['remark'];
- }
- $content = '#微网报名#姓名:' . $name . ',面积:' . $remark;
- !isset($info['phone']) ?: $content .= ',手机号:' . $info['phone'];
- break;
- case 'activity':
- $content = '#活动#《' . $info['title'] . '》';
- break;
- case 'materialCase':
- $content = '#案例#《' . $info['title'] . '》';
- break;
- case 'materialEvidence':
- $content = '#口碑见证#《' . $info['title'] . '》';
- break;
- case 'priceCalculation':
- $info = json_decode($info['value'], true);
- $name = '';
- if (isset($info['name'])) {
- $name = '姓名:' . $info['name'] . ',';
- }
- //$content = '#装修报价#' . $name . '手机号:' . $info['mobile'] . ',小区:' . $info['community'] . ',面积:' . $info['area'] . ',户型:' . $info['bedroom'] . ',风格:' . $info['style'] . ',房屋类型:' . $info['type'];
- $content = '#装修报价#' . $name . '手机号:' . $info['mobile'] . ',小区:' . $info['community'] . ',面积:' . $info['area'];
- break;
- case 'styleTest':
- $info = json_decode($info['value'], true);
- $content = '#家装风格测一测#' . $info['style'];
- break;
- case 'likeTest':
- $info = json_decode($info['value'], true);
- $content = '#老房翻新风格测一测#' . $info['style'];
- break;
- case 'toolDecohelper':
- $content = '#装修知识#《' . $info['title'] . '》';
- break;
- case 'video':
- $content = '#视频#《' . $info['title'] . '》';
- break;
- case 'share':
- $name = '';
- if (isset($info['name'])) {
- $name = '姓名:' . $info['name'] . ',';
- }
- $title = isset($info['data']['title']) ? $info['data']['title'] : (isset($info['data']['name']) ? $info['data']['name'] : '');
- $content = '#链接分享报名#《' . $title . '》' . $name . '手机号:' . $info['mobile'];
- break;
- case 'article':
- $content = '#图文素材#《' . $info['title'] . '》';
- break;
- case 'building':
- $name = isset($info['name']) ? $info['name'] : '';
- $title = isset($info['prompt']) ? '('.$info['prompt'].')' : '';
- $content = '#楼盘'.$title.'#《' . $name . '》';
- break;
- case 'construction':
- $name = isset($info['name']) ? $info['name'] : '';
- $content = '#在施工地#《' . $name . '》';
- break;
- case 'designer':
- $designer_name = isset($info['title']) ? $info['title'] : '';
- // 预约设计师来源
- if (!empty($info['share_pipe_type'])) {
- switch ($info['share_pipe_type']) {
- case 'materialCase':
- $material_case = MaterialCase::where('id', '=', $info['share_data_id'])->findOrEmpty();
- if (!$material_case->isEmpty()) {
- if (!empty($info['mobile'])) {
- $content = "从装修案例《" . $material_case['title'] . "》中预约了" . $designer_name . "设计师,手机号" . $info['mobile'];
- } else {
- $content = "从装修案例《" . $material_case['title'] . "》中预约了" . $designer_name . "设计师";
- }
- } else {
- $content = !empty($info['mobile']) ? "从装修案例中预约了" . $designer_name . "设计师,手机号" . $info['mobile'] : "从装修案例中预约了" . $designer_name . "设计师";
- }
- break;
- case 'designer':
- $content = "从设计师列表预约了" . $designer_name . "设计师";
- break;
- default:
- $content = "预约了" . $designer_name . "设计师";
- break;
- }
- } else {
- $content = "查看了" . $designer_name . "设计师";
- }
- break;
- case 'card':
- $content = "访问了您的名片";
- break;
- case 'quote':
- $area = $info['area'] ? $info['area'] . "m²" : "未填写";
- $content = "#装修报价#\r\n面积:" . $area . "\r\n户型:" . $info['room'] . "室" . $info['hall'] . "厅" . $info['bathroom'] . "卫\r\n" . "手机号:" . $info['phone'];/* . "\r\n报价时间:" . $info['addtime']*/;
- break;
- case 'companyStrength': //新版
- $content = !empty($info) ? '#公司实力#《' . $info['title'] . '》' : '';
- break;
- case 'CompanyStrength': //旧版
- $content = !empty($info) ? '#公司实力#《' . $info['title'] . '》' : '';
- break;
- case 'building_urge':
- $name = isset($info['name']) ? $info['name'] : '';
- $content = !empty($info['phone']) ? "催更了《" . $name . "》楼盘,手机号" . $info['phone'] : "催更了《" . $name . "》楼盘";
- break;
- case 'askedfitup':
- $content = !empty($info['phone']) ? "#询问装修#手机号" . $info['phone'] : '#询问装修#手机号 未获取';
- break;
- case 'lottery':
- $act_type = $info['type'] == 1 ? '大转盘' : '砸金蛋';
- $content = !empty($info['luckname']) ? "#参加" . $info['title'] . $act_type . "活动#中奖奖品为" . $info['luckname'] : "#参加" . $info['title'] . $act_type . "活动#";
- break;
- case 'materialCaseVr':
- $content = '#案例VR#《' . $info['title'] . '》';
- break;
- case 'buildingVr':
- $name = isset($info['name']) ? $info['name'] : '';
- $content = '#楼盘进度VR#《' . $name . '》';
- break;
- case 'companyVr':
- $title = !empty($info['name']) ? $info['name'] : '';
- $content = "访问了您的".$title."VR展厅";
- break;
- case 'employeeCardVr':
- $content = "访问了您的VR名片";
- break;
- case 'constructionVr':
- $name = isset($info['name']) ? $info['name'] : '';
- $content = '#在施工地VR#《' . $name . '》';
- break;
- case 'getDecorationDesign':
- $mobile = (isset($info['mobile']) && !empty($info['mobile'])) ? $info['mobile'] : '';
- $content = "#免费领取设计方案#小区:" . $info['community'] . ',面积' . $info['area'] . ',户型' . $info['bedroom'] . ',电话:' . $mobile;
- break;
- case 'toolAll':
- $content = !empty($info['type']) ? "访问了您的谈单工具《" . $info['type'] . '》' : "访问了您的谈单工具";
- break;
- case 'agents':
- //$info = json_decode($info['value'], true);
- $name = '';
- if (isset($info['agent_name'])) {
- $name = '姓名:' . $info['agent_name'] . ',';
- }
- $content = '#经纪人#' . $name . '手机号:' . $info['agent_phone'];
- break;
- case 'spellgroup':
- $content = "访问了您的装修拼团";
- break;
- case 'weiwang':
- $content = "访问了您的个人微网";
- break;
- case 'devcase':
- $devcase_type = BuildingDevelopCase::where('id', $info['id'])->value('type');
- $case_type = $devcase_type == 1 ? 'VR' : '图文';
- $name = isset($info['name']) ? $info['name'] : '';
- $content = '#研发案例#类别:' . $case_type . ' 案例标题:' . $name;
- break;
- case 'progressDetail':
- $name = isset($info['name']) ? $info['name'] : '';
- $content = '#楼盘进度详情#' . $name;
- break;
- case 'agentArticle':
- $content = '#经纪人分享文章#' . $info['title'];
- break;
- case 'groupVr':
- $title = $info['title'] ?: '未命名作品';
- $title = isset($info['prompt']) ? '浏览了'.$info['prompt'].'的VR作品“'.$title.'”' : $title;
- $content = '#vr作品#' . $title;
- break;
- case 'groupVrVr':
- $title = $info['title'] ?: '未命名作品';
- $title = isset($info['prompt']) ? '浏览了'.$info['prompt'].'的VR作品“'.$title.'”' : $title;
- $content = '#vr作品#' . $title;
- break;
- case 'agentShareContentCrm':
- $name = '';
- if (isset($info['name']) && !empty($info['name'])) {
- $name = '姓名:' . $info['name'] . ',';
- }
- $community_name = '';
- if (isset($info['community_name']) && !empty($info['community_name'])) {
- $community_name = ',小区:' . $info['community_name'];
- }
- $phone = !empty($info['phone']) ? $info['phone'] : '暂无';
- $content = '#经纪人分享内容客户报名信息#' . $name . '手机号:' . $phone . $community_name;
- break;
- case 'TrainClassList':
- $content = '访问了您的课程列表';
- break;
- case 'TrainClass':
- $content = '访问了'.$info['title'].'课程';
- break;
- case 'TrainCourse':
- $content = '访问了'.$info['class_title'].'-'.$info['title'].'课件';
- break;
- case 'housetype':
- $content = "户型:" . $info['room'] . "室" . $info['hall'] . "厅" . $info['bathroom'] . "卫";
- break;
- case 'housetypeVr':
- $size = $info['room'] . "室" . $info['hall'] . "厅" . $info['bathroom'] . "卫";
- if(!isset($info['prompt'])){
- $content = "户型:" . $size;
- }else{
- $content = '浏览了户型【'.$info['prompt'].'】的VR作品';
- }
- break;
- case 'buildingHousetype':
- $content = "户型:" . $info['room'] . "室" . $info['hall'] . "厅" . $info['bathroom'] . "卫";
- break;
- default:
- $content = '';
- break;
- }
- return $content;
- }
- public function customer()
- {
- return $this->hasOne(Customer::class, 'uid', 'uid');
- }
- public function user()
- {
- return $this->hasOne(User::class, 'id', 'uid')->bind(['headimgurl' => 'headimgurl']);
- }
- /**
- * 发送公众号消息
- */
- public static function onAfterInsert($info)
- {
- $employee = Employee::field('official_openid,root_id')->where('id', $info['employee_id'])->find();
- if (empty($employee) || empty($employee['root_id'])) return true; //数据问题,防止报错
- // 如果是员工足迹产生(包含在职,待审核)
- $isEmployee = Employee::where([['uid', '=', $info['uid']], ['root_id', '=', $employee['root_id']], ['state', 'in', ['在职', '待审核']]])->find();
- if ($isEmployee) return true;
- $miniAppid = Miniprogram::where('root_id', $employee['root_id'])->find();
- if (empty($employee['official_openid'])) return true;
- $nickname = User::where('id', $info['uid'])->value('nickname');
- $first = '客户' . $nickname;
- //新增浏览数据后给业务员发送公众号消息
- $operation = [
- 'wwbm' => '通过',
- 'activity' => '浏览了',
- 'materialCase' => '浏览了',
- 'materialEvidence' => '浏览了',
- 'priceCalculation' => '浏览了',
- 'styleTest' => '浏览了',
- 'likeTest' => '浏览了',
- 'toolDecohelper' => '浏览了',
- 'video' => '浏览了',
- 'share' => '通过',
- 'article' => '浏览了',
- 'building' => '浏览了',
- 'construction' => '浏览了',
- 'designer' => '',
- 'card' => '',
- 'quote' => '浏览了',
- 'companyStrength' => '浏览了',
- 'CompanyStrength' => '浏览了',
- 'building_urge' => '',
- 'askedfitup' => '浏览了',
- 'lottery' => '',
- 'materialCaseVr' => '浏览了',
- 'buildingVr' => '浏览了',
- 'companyVr' => '',
- 'employeeCardVr' => '',
- 'constructionVr' => '浏览了',
- 'getDecorationDesign' => '浏览了',
- 'toolAll' => '',
- 'agents' => '浏览了',
- 'spellgroup' => '',
- 'weiwang' => '',
- 'devcase' => '浏览了',
- 'progressDetail' => '浏览了',
- 'agentArticle' => '浏览了',
- 'housetype'=> '浏览了',
- 'buildingHousetype'=> '浏览了',
- 'groupVr'=> '浏览了',
- 'groupVrVr'=> '浏览了',
- ];
- if (!isset($operation[$info['pipe_type']])) return true;
- $msg = $first . $operation[$info['pipe_type']] . $info['reg_info'];
- $wxTemp = new Template();
- if (!$token = Cache::get('zqxg_offi_access_token')) {
- $appid = config('app.official_appid');
- $token = $wxTemp->getAccessToken($appid, config('app.official_secret'));
- Cache::set('zqxg_offi_access_token', $token, 7100);
- }
- //通知编号
- $day = date('Y-m-d');
- $count = Footprints::where([['employee_id', '=', $info->employee_id], ['addtime', 'like', '%' . $day . '%']])->count();
- $number = date('Ymd') . $count;
- //本月累计
- $month = date('Y-m');
- $month_count = Footprints::where([['employee_id', '=', $info->employee_id], ['addtime', 'like', '%' . $month . '%']])->count();
- $rs = $wxTemp->sendTemplateMsg($token, [
- "touser" => $employee->official_openid,
- "template_id" => "H0zPfXZX7JyjgZp8PtZSjxBraoXjunDYKqM5x_PlDQM",
- "miniprogram" => [
- "appid" => $miniAppid->appid,
- "pagepath" => "/pages/index/index?office_type=clue_radar&clientype=" . $miniAppid->notify
- ],
- "data" => [
- "first" => [
- "value" => "新增一条客户足迹,请及时跟进",
- "color" => "#173177"
- ],
- "keyword1" => [
- "value" => '新增浏览记录通知',
- "color" => "#173177"
- ],
- "keyword2" => [
- "value" => $number,
- "color" => "#173177"
- ],
- "keyword3" => [
- "value" => $msg,
- "color" => "#173177"
- ],
- "remark" => [
- "value" => '本月累计' . $month_count . '条浏览记录',
- "color" => "#173177"
- ]
- ]
- ]);
- return true;
- }
- }
|