m_ua = new useractionrecordmodel(); $this->m_uc = new userconnectrecordmodel(); $this->m_us = new usersearchrecordmodel(); $this->m_ucd = new userconnectrecorddaymodel(); } /*** * 保存用户沟通行为 * useraction表不再记录用户沟通行为 20211215 wj * 2021090927 * wj */ public function saveuserconnect($arr) { $type = 2; $arr['type'] = $type; $result = $this->checkData($arr); if (1 != $result['status']) { return $result; } //$refId = isset($arr['ref_id']) ? $arr['ref_id'] : 0; $uidInfo = $this->checkUser($arr['uid']); $reciveruserid = isset($arr['reciveruserid']) ? $arr['reciveruserid'] : 0; $ruidInfo = $this->checkUser($reciveruserid); if (empty($ruidInfo)) { return backarr(0, "用户不存在"); } $openid = empty($arr['openid']) ? $uidInfo['openid'] : $arr['openid']; $sendusername = isset($arr['sendusername']) ? $arr['sendusername'] : $uidInfo['wname']; $reciverusername = isset($arr['reciverusername']) ? $arr['reciverusername'] : $ruidInfo['wname']; Db::startTrans(); try { $detailData = [ 'openid' => $openid, 'senduserid' => $arr['uid'], 'sendusername' => $sendusername, 'reciveruserid' => $reciveruserid, 'reciverusername' => $reciverusername, 'sourceid' => $arr['sourceid'], 'sourcetype' => $arr['source_type'], ]; $resultCheck = $this->m_uc->checkDataForInsert($detailData); if (1 == $resultCheck['status']) { $usid = $this->m_uc->insinfo($detailData); if (!$usid) { throw new \Exception("详细总表保存失败"); } } $usdid = $this->m_ucd->insinfo($detailData); //$detailId = 'd' . $usdid; if (!$usdid) { throw new \Exception("详细保存失败"); } /* if (empty($refId)) { $refId = $arr['sourceid']; } $sourcetype = $arr['source_type']; if (in_array($sourcetype, [1, 2])) { $sourcetype = 'invent'; } elseif (in_array($sourcetype, [3, 4])) { $sourcetype = 'jobhunting'; } $uaData = [ 'uid' => $arr['uid'], 'ref_id' => $refId, 'type' => $arr['type'], 'source_type' => $arr['source_type'], 'detail_id' => $detailId, ]; $usId = $this->m_ua->insinfo($uaData); if (!$usId) { throw new \Exception("保存失败", 1); }*/ Db::commit(); return backarr(1, "保存成功"); } catch (\Exception $e) { Db::rollback(); return backarr(0, $e->getMessage()); } } /*** * 保存用户点击行为 * 2021090927 * wj */ public function saveuserclick($arr) { $type = 1; $arr['type'] = $type; $result = $this->checkData($arr); if (1 != $result['status']) { return $result; } $refId = isset($arr['ref_id']) ? $arr['ref_id'] : 0; Db::startTrans(); try { $uaData = [ 'uid' => $arr['uid'], 'ref_id' => $refId, 'type' => $arr['type'], 'source_type' => $arr['source_type'], ]; $usId = $this->m_ua->insinfo($uaData); if (!$usId) { throw new \Exception("保存失败", 1); } Db::commit(); return backarr(1, "保存成功"); } catch (\Exception $e) { Db::rollback(); return backarr(0, $e->getMessage()); } } /*** * 保存用户搜索行为 * 2021090927 * wj */ public function saveusersearch($arr) { $type = 3; $arr['type'] = $type; $result = $this->checkData($arr); if (1 != $result['status']) { return $result; } if (!isset($arr['content']) || empty($arr['content'])) { return backarr(0, "无查询内容"); } $refId = isset($arr['ref_id']) ? $arr['ref_id'] : 0; Db::startTrans(); try { $detailData = [ 'uid' => $arr['uid'], 'content' => $arr['content'], 'sourcetype' => $arr['source_type'], ]; $detailId = $this->m_us->insinfo($detailData); if (!$detailId) { throw new \Exception("详细保存失败"); } $uaData = [ 'uid' => $arr['uid'], 'ref_id' => $refId, 'type' => $arr['type'], 'source_type' => $arr['source_type'], 'detail_id' => $detailId, ]; $usId = $this->m_ua->insinfo($uaData); if (!$usId) { throw new \Exception("保存失败", 1); } Db::commit(); return backarr(1, "保存成功"); } catch (\Exception $e) { Db::rollback(); return backarr(0, $e->getMessage()); } } private function checkData($arr) { $fillField = ['uid', 'source_type']; foreach ($fillField as $key => $value) { if (!isset($arr[$value]) || empty($arr[$value])) { return backarr(0, "请求参数错误"); } } $info = $this->checkUser($arr['uid']); if (empty($info)) { return backarr(0, "用户不存在"); } return backarr(1, ""); } /*** * 判断用户是否存在 * 2021090927 * wj */ private function checkUser($id) { $m_w = new userinfomodel(); $info = $m_w->getInfo(['id' => $id]); return $info; } /* * 20211129 * steelxu * 按用户获取主动联系的清单 */ public function getconnecttotalbyusreid($arr) { $userid = $arr['userid']; $list = $this->m_uc->seltotalbyuserid($userid); if ($list) { return backarr(1, "查询成功", $list); } else { return backarr(0, "无数据"); } } /* * 20211130 * steelxu5 * 按用户获取当日主动联系的清单及评价情况 */ public function getconnectinfolistbyuiddate($arr) { $userid = $arr['userid']; $calldate = $arr['calldate']; $clist = $this->m_uc->selinfolistbyuiddate($userid, $calldate); $t_i = new inventmodel(); $t_j = new jobhuntingmodel(); $t_e = new evaluatemodel(); foreach ($clist as &$callrecord) { $sourcetype = $callrecord['sourcetype']; $sourceid = $callrecord['sourceid']; $sourceuser = $callrecord['reciveruserid']; if ($sourcetype == 1) { $sourceinfo = $t_i->selinfobyid($sourceid); } else { $sourceinfo = $t_j->selinfobyid($sourceid); } $callrecord['sourceinfo'] = $sourceinfo; if ($callrecord['senderevaluate'] == 1) { $einfo = $t_e->selinfobyuidetype($userid, 1); $callrecord['einfo'] = $einfo; } } if ($clist) { return backarr(1, "查询成功", $clist); } else { return backarr(0, "无数据"); } } /* * 20211201 * steelxu5 */ public function savenewconnectevaluate($arr) { $arr['evaluatetime'] = date('Y-m-d H:i:s'); $t_e = new evaluatemodel(); $id = $t_e->insinfo($arr); if (!isset($arr['sourceid']) || !isset($arr['sourcetype'])) { return backarr(0, "请求错误"); } $sourceid = $arr['sourceid']; $sourcetype = $arr['sourcetype']; $ecount = $this->m_uc->updatesenderevaluebysid($sourceid, $sourcetype); if ($id) { return backarr(1, "更新成功", $id); } else { return backarr(0, "提交失败"); } } /** * 根据查询条件获取联系列表 * 20211209 * wj */ public function getconnectlist($arr) { $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1; $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10; $where = []; if (isset($arr['swname']) && !empty($arr['swname']) && is_string($arr['swname'])) { $where['swname'] = $arr['swname']; } if (isset($arr['stelno']) && !empty($arr['stelno']) && is_string($arr['stelno'])) { $where['stelno'] = $arr['stelno']; } if (isset($arr['rwname']) && !empty($arr['rwname']) && is_string($arr['rwname'])) { $where['rwname'] = $arr['rwname']; } if (isset($arr['rtelno']) && !empty($arr['rtelno']) && is_string($arr['rtelno'])) { $where['rtelno'] = $arr['rtelno']; } if (isset($arr['code']) && !empty($arr['code']) && is_string($arr['code'])) { $where['code'] = $arr['code']; } if (isset($arr['calltime']) && !empty($arr['calltime']) && is_array($arr['calltime'])) { if (count(array_filter($arr['calltime'])) == 2) { $where['calltime'] = $arr['calltime']; } } if (isset($arr['worktype']) && !empty($arr['worktype']) && is_string($arr['worktype'])) { $where['worktype'] = $arr['worktype']; } $count = $this->m_uc->getconnectlist($where, true); $count = $count[0]['count']; if ($count <= 0) { return backarr(0, '无数据'); } $list = $this->m_uc->getconnectlist($where, false, $page, $size); $data = [ 'count' => $count, 'list' => $list, ]; return backarr(1, '查询成功', $data); } /** * 根据查询条件获取联系列表 * 20211217 * wj */ public function getconnectbydaylist($arr) { $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1; $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10; $where = []; $callday = date('Ymd'); if (isset($arr['callday']) && !empty($arr['callday']) && is_string($arr['callday'])) { $callday = date("Ymd", strtotime($arr['callday'])); } if (isset($arr['swname']) && !empty($arr['swname']) && is_string($arr['swname'])) { $where['swname'] = $arr['swname']; } if (isset($arr['stelno']) && !empty($arr['stelno']) && is_string($arr['stelno'])) { $where['stelno'] = $arr['stelno']; } if (isset($arr['rwname']) && !empty($arr['rwname']) && is_string($arr['rwname'])) { $where['rwname'] = $arr['rwname']; } if (isset($arr['rtelno']) && !empty($arr['rtelno']) && is_string($arr['rtelno'])) { $where['rtelno'] = $arr['rtelno']; } if (isset($arr['code']) && !empty($arr['code']) && is_string($arr['code'])) { $where['code'] = $arr['code']; } /*if (isset($arr['calltime']) && !empty($arr['calltime']) && is_array($arr['calltime'])) { if (count(array_filter($arr['calltime'])) == 2) { $where['calltime'] = $arr['calltime']; } }*/ if (isset($arr['worktype']) && !empty($arr['worktype']) && is_string($arr['worktype'])) { $where['worktype'] = $arr['worktype']; } $daystr = $callday; $isExist = $this->m_ucd->isexist($daystr); if (!$isExist) { $where['callday'] = $daystr; $count = $this->m_uc->getconnectlist($where, true); $count = $count[0]['count']; if ($count <= 0) { return backarr(0, '无数据'); } } else { $this->m_ucd->setTableName($daystr); $count = $this->m_ucd->getconnectlist($where, true); $count = $count[0]['count']; if ($count <= 0) { return backarr(0, '无数据'); } $list = $this->m_ucd->getconnectlist($where, false, $page, $size); } $data = [ 'count' => $count, 'list' => $list, ]; return backarr(1, '查询成功', $data); } /*** * 保存用户点击行为 保存工作类型 * 20211209 * wj */ public function saveuserclickworktype($arr) { $arr['source_type'] = 'worktype'; $result = $this->checkData($arr); if (1 != $result['status']) { return $result; } $refId = isset($arr['ref_id']) ? $arr['ref_id'] : 0; $uaData = [ 'uid' => $arr['uid'], 'ref_id' => $refId, 'type' => 1, 'source_type' => $arr['source_type'], 'record_time' => date('Y-m-d H:i:s'), ]; $usId = $this->m_ua->insinfo($uaData); if (empty($usId)) { return backarr(0, "保存失败"); } return backarr(1, "保存成功"); } /* * 20211220 * wj * 统计联系电话的时间段 */ public function getconnecttimebucket($arr) { $date = isset($arr['date']) && !empty($arr['date']) ? $arr['date'] : date('Ymd'); $daystr = date('Ymd', strtotime($date)); $isExist = $this->m_ucd->isexist($daystr); if (!$isExist) { $where['callday'] = $daystr; $list = $this->m_uc->getconnecttimebucket($where); if (empty($list)) { return backarr(0, '无数据'); } } else { $this->m_ucd->setTableName($daystr); $list = $this->m_ucd->getconnecttimebucket($arr); if (empty($list)) { return backarr(0, '无数据'); } } return backarr(1, '查询成功', $list); } /* * 20211222 * wj * 统计联系电话次数 */ public function getconnectbyinvent($arr) { $date = isset($arr['date']) && !empty($arr['date']) ? $arr['date'] : date('Ymd'); $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1; $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10; $daystr = date('Ymd', strtotime($date)); $isExist = $this->m_ucd->isexist($daystr); if (!$isExist) { $where['callday'] = $daystr; $count = $this->m_uc->getconnectbyinvent($where, true); if ($count <= 0) { return backarr(0, '无数据'); } $list = $this->m_uc->getconnectbyinvent($where, false, $page, $size); } else { $this->m_ucd->setTableName($daystr); $count = $this->m_ucd->getconnectbyinvent($arr, true); if ($count <= 0) { return backarr(0, '无数据'); } $list = $this->m_ucd->getconnectbyinvent($arr, false, $page, $size); } $date = [ 'count' => $count, 'list' => $list, ]; return backarr(1, '查询成功', $date); } }