123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- <?php
- /*
- * @Author: wang jun
- * @Date: 2021-09-28 11:21:10
- * @Last Modified by: wang jun
- * @Last Modified time: 2021-12-15 13:51:21
- */
- namespace app\index\logic;
- use app\index\model\evaluatemodel;
- use app\index\model\inventmodel;
- use app\index\model\jobhuntingmodel;
- use app\index\model\useractionrecordmodel;
- use app\index\model\userconnectrecorddaymodel;
- use app\index\model\userconnectrecordmodel;
- use app\index\model\userinfomodel;
- use app\index\model\usersearchrecordmodel;
- use think\Db;
- class useractionlogic
- {
- private $m_ua;
- private $m_uc;
- public function __construct()
- {
- $this->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);
- }
- }
|