useractionlogic.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-09-28 11:21:10
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-12-15 13:51:21
  7. */
  8. namespace app\index\logic;
  9. use app\index\model\evaluatemodel;
  10. use app\index\model\inventmodel;
  11. use app\index\model\jobhuntingmodel;
  12. use app\index\model\useractionrecordmodel;
  13. use app\index\model\userconnectrecorddaymodel;
  14. use app\index\model\userconnectrecordmodel;
  15. use app\index\model\userinfomodel;
  16. use app\index\model\usersearchrecordmodel;
  17. use think\Db;
  18. class useractionlogic
  19. {
  20. private $m_ua;
  21. private $m_uc;
  22. public function __construct()
  23. {
  24. $this->m_ua = new useractionrecordmodel();
  25. $this->m_uc = new userconnectrecordmodel();
  26. $this->m_us = new usersearchrecordmodel();
  27. $this->m_ucd = new userconnectrecorddaymodel();
  28. }
  29. /***
  30. * 保存用户沟通行为
  31. * useraction表不再记录用户沟通行为 20211215 wj
  32. * 2021090927
  33. * wj
  34. */
  35. public function saveuserconnect($arr)
  36. {
  37. $type = 2;
  38. $arr['type'] = $type;
  39. $result = $this->checkData($arr);
  40. if (1 != $result['status']) {
  41. return $result;
  42. }
  43. //$refId = isset($arr['ref_id']) ? $arr['ref_id'] : 0;
  44. $uidInfo = $this->checkUser($arr['uid']);
  45. $reciveruserid = isset($arr['reciveruserid']) ? $arr['reciveruserid'] : 0;
  46. $ruidInfo = $this->checkUser($reciveruserid);
  47. if (empty($ruidInfo)) {
  48. return backarr(0, "用户不存在");
  49. }
  50. $openid = empty($arr['openid']) ? $uidInfo['openid'] : $arr['openid'];
  51. $sendusername = isset($arr['sendusername']) ? $arr['sendusername'] : $uidInfo['wname'];
  52. $reciverusername = isset($arr['reciverusername']) ? $arr['reciverusername'] : $ruidInfo['wname'];
  53. Db::startTrans();
  54. try {
  55. $detailData = [
  56. 'openid' => $openid,
  57. 'senduserid' => $arr['uid'],
  58. 'sendusername' => $sendusername,
  59. 'reciveruserid' => $reciveruserid,
  60. 'reciverusername' => $reciverusername,
  61. 'sourceid' => $arr['sourceid'],
  62. 'sourcetype' => $arr['source_type'],
  63. ];
  64. $resultCheck = $this->m_uc->checkDataForInsert($detailData);
  65. if (1 == $resultCheck['status']) {
  66. $usid = $this->m_uc->insinfo($detailData);
  67. if (!$usid) {
  68. throw new \Exception("详细总表保存失败");
  69. }
  70. }
  71. $usdid = $this->m_ucd->insinfo($detailData);
  72. //$detailId = 'd' . $usdid;
  73. if (!$usdid) {
  74. throw new \Exception("详细保存失败");
  75. }
  76. /*
  77. if (empty($refId)) {
  78. $refId = $arr['sourceid'];
  79. }
  80. $sourcetype = $arr['source_type'];
  81. if (in_array($sourcetype, [1, 2])) {
  82. $sourcetype = 'invent';
  83. } elseif (in_array($sourcetype, [3, 4])) {
  84. $sourcetype = 'jobhunting';
  85. }
  86. $uaData = [
  87. 'uid' => $arr['uid'],
  88. 'ref_id' => $refId,
  89. 'type' => $arr['type'],
  90. 'source_type' => $arr['source_type'],
  91. 'detail_id' => $detailId,
  92. ];
  93. $usId = $this->m_ua->insinfo($uaData);
  94. if (!$usId) {
  95. throw new \Exception("保存失败", 1);
  96. }*/
  97. Db::commit();
  98. return backarr(1, "保存成功");
  99. } catch (\Exception $e) {
  100. Db::rollback();
  101. return backarr(0, $e->getMessage());
  102. }
  103. }
  104. /***
  105. * 保存用户点击行为
  106. * 2021090927
  107. * wj
  108. */
  109. public function saveuserclick($arr)
  110. {
  111. $type = 1;
  112. $arr['type'] = $type;
  113. $result = $this->checkData($arr);
  114. if (1 != $result['status']) {
  115. return $result;
  116. }
  117. $refId = isset($arr['ref_id']) ? $arr['ref_id'] : 0;
  118. Db::startTrans();
  119. try {
  120. $uaData = [
  121. 'uid' => $arr['uid'],
  122. 'ref_id' => $refId,
  123. 'type' => $arr['type'],
  124. 'source_type' => $arr['source_type'],
  125. ];
  126. $usId = $this->m_ua->insinfo($uaData);
  127. if (!$usId) {
  128. throw new \Exception("保存失败", 1);
  129. }
  130. Db::commit();
  131. return backarr(1, "保存成功");
  132. } catch (\Exception $e) {
  133. Db::rollback();
  134. return backarr(0, $e->getMessage());
  135. }
  136. }
  137. /***
  138. * 保存用户搜索行为
  139. * 2021090927
  140. * wj
  141. */
  142. public function saveusersearch($arr)
  143. {
  144. $type = 3;
  145. $arr['type'] = $type;
  146. $result = $this->checkData($arr);
  147. if (1 != $result['status']) {
  148. return $result;
  149. }
  150. if (!isset($arr['content']) || empty($arr['content'])) {
  151. return backarr(0, "无查询内容");
  152. }
  153. $refId = isset($arr['ref_id']) ? $arr['ref_id'] : 0;
  154. Db::startTrans();
  155. try {
  156. $detailData = [
  157. 'uid' => $arr['uid'],
  158. 'content' => $arr['content'],
  159. 'sourcetype' => $arr['source_type'],
  160. ];
  161. $detailId = $this->m_us->insinfo($detailData);
  162. if (!$detailId) {
  163. throw new \Exception("详细保存失败");
  164. }
  165. $uaData = [
  166. 'uid' => $arr['uid'],
  167. 'ref_id' => $refId,
  168. 'type' => $arr['type'],
  169. 'source_type' => $arr['source_type'],
  170. 'detail_id' => $detailId,
  171. ];
  172. $usId = $this->m_ua->insinfo($uaData);
  173. if (!$usId) {
  174. throw new \Exception("保存失败", 1);
  175. }
  176. Db::commit();
  177. return backarr(1, "保存成功");
  178. } catch (\Exception $e) {
  179. Db::rollback();
  180. return backarr(0, $e->getMessage());
  181. }
  182. }
  183. private function checkData($arr)
  184. {
  185. $fillField = ['uid', 'source_type'];
  186. foreach ($fillField as $key => $value) {
  187. if (!isset($arr[$value]) || empty($arr[$value])) {
  188. return backarr(0, "请求参数错误");
  189. }
  190. }
  191. $info = $this->checkUser($arr['uid']);
  192. if (empty($info)) {
  193. return backarr(0, "用户不存在");
  194. }
  195. return backarr(1, "");
  196. }
  197. /***
  198. * 判断用户是否存在
  199. * 2021090927
  200. * wj
  201. */
  202. private function checkUser($id)
  203. {
  204. $m_w = new userinfomodel();
  205. $info = $m_w->getInfo(['id' => $id]);
  206. return $info;
  207. }
  208. /*
  209. * 20211129
  210. * steelxu
  211. * 按用户获取主动联系的清单
  212. */
  213. public function getconnecttotalbyusreid($arr)
  214. {
  215. $userid = $arr['userid'];
  216. $list = $this->m_uc->seltotalbyuserid($userid);
  217. if ($list) {
  218. return backarr(1, "查询成功", $list);
  219. } else {
  220. return backarr(0, "无数据");
  221. }
  222. }
  223. /*
  224. * 20211130
  225. * steelxu5
  226. * 按用户获取当日主动联系的清单及评价情况
  227. */
  228. public function getconnectinfolistbyuiddate($arr)
  229. {
  230. $userid = $arr['userid'];
  231. $calldate = $arr['calldate'];
  232. $clist = $this->m_uc->selinfolistbyuiddate($userid, $calldate);
  233. $t_i = new inventmodel();
  234. $t_j = new jobhuntingmodel();
  235. $t_e = new evaluatemodel();
  236. foreach ($clist as &$callrecord) {
  237. $sourcetype = $callrecord['sourcetype'];
  238. $sourceid = $callrecord['sourceid'];
  239. $sourceuser = $callrecord['reciveruserid'];
  240. if ($sourcetype == 1) {
  241. $sourceinfo = $t_i->selinfobyid($sourceid);
  242. } else {
  243. $sourceinfo = $t_j->selinfobyid($sourceid);
  244. }
  245. $callrecord['sourceinfo'] = $sourceinfo;
  246. if ($callrecord['senderevaluate'] == 1) {
  247. $einfo = $t_e->selinfobyuidetype($userid, 1);
  248. $callrecord['einfo'] = $einfo;
  249. }
  250. }
  251. if ($clist) {
  252. return backarr(1, "查询成功", $clist);
  253. } else {
  254. return backarr(0, "无数据");
  255. }
  256. }
  257. /*
  258. * 20211201
  259. * steelxu5
  260. */
  261. public function savenewconnectevaluate($arr)
  262. {
  263. $arr['evaluatetime'] = date('Y-m-d H:i:s');
  264. $t_e = new evaluatemodel();
  265. $id = $t_e->insinfo($arr);
  266. if (!isset($arr['sourceid']) || !isset($arr['sourcetype'])) {
  267. return backarr(0, "请求错误");
  268. }
  269. $sourceid = $arr['sourceid'];
  270. $sourcetype = $arr['sourcetype'];
  271. $ecount = $this->m_uc->updatesenderevaluebysid($sourceid, $sourcetype);
  272. if ($id) {
  273. return backarr(1, "更新成功", $id);
  274. } else {
  275. return backarr(0, "提交失败");
  276. }
  277. }
  278. /**
  279. * 根据查询条件获取联系列表
  280. * 20211209
  281. * wj
  282. */
  283. public function getconnectlist($arr)
  284. {
  285. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  286. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  287. $where = [];
  288. if (isset($arr['swname']) && !empty($arr['swname']) && is_string($arr['swname'])) {
  289. $where['swname'] = $arr['swname'];
  290. }
  291. if (isset($arr['stelno']) && !empty($arr['stelno']) && is_string($arr['stelno'])) {
  292. $where['stelno'] = $arr['stelno'];
  293. }
  294. if (isset($arr['rwname']) && !empty($arr['rwname']) && is_string($arr['rwname'])) {
  295. $where['rwname'] = $arr['rwname'];
  296. }
  297. if (isset($arr['rtelno']) && !empty($arr['rtelno']) && is_string($arr['rtelno'])) {
  298. $where['rtelno'] = $arr['rtelno'];
  299. }
  300. if (isset($arr['code']) && !empty($arr['code']) && is_string($arr['code'])) {
  301. $where['code'] = $arr['code'];
  302. }
  303. if (isset($arr['calltime']) && !empty($arr['calltime']) && is_array($arr['calltime'])) {
  304. if (count(array_filter($arr['calltime'])) == 2) {
  305. $where['calltime'] = $arr['calltime'];
  306. }
  307. }
  308. if (isset($arr['worktype']) && !empty($arr['worktype']) && is_string($arr['worktype'])) {
  309. $where['worktype'] = $arr['worktype'];
  310. }
  311. $count = $this->m_uc->getconnectlist($where, true);
  312. $count = $count[0]['count'];
  313. if ($count <= 0) {
  314. return backarr(0, '无数据');
  315. }
  316. $list = $this->m_uc->getconnectlist($where, false, $page, $size);
  317. $data = [
  318. 'count' => $count,
  319. 'list' => $list,
  320. ];
  321. return backarr(1, '查询成功', $data);
  322. }
  323. /**
  324. * 根据查询条件获取联系列表
  325. * 20211217
  326. * wj
  327. */
  328. public function getconnectbydaylist($arr)
  329. {
  330. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  331. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  332. $where = [];
  333. $callday = date('Ymd');
  334. if (isset($arr['callday']) && !empty($arr['callday']) && is_string($arr['callday'])) {
  335. $callday = date("Ymd", strtotime($arr['callday']));
  336. }
  337. if (isset($arr['swname']) && !empty($arr['swname']) && is_string($arr['swname'])) {
  338. $where['swname'] = $arr['swname'];
  339. }
  340. if (isset($arr['stelno']) && !empty($arr['stelno']) && is_string($arr['stelno'])) {
  341. $where['stelno'] = $arr['stelno'];
  342. }
  343. if (isset($arr['rwname']) && !empty($arr['rwname']) && is_string($arr['rwname'])) {
  344. $where['rwname'] = $arr['rwname'];
  345. }
  346. if (isset($arr['rtelno']) && !empty($arr['rtelno']) && is_string($arr['rtelno'])) {
  347. $where['rtelno'] = $arr['rtelno'];
  348. }
  349. if (isset($arr['code']) && !empty($arr['code']) && is_string($arr['code'])) {
  350. $where['code'] = $arr['code'];
  351. }
  352. /*if (isset($arr['calltime']) && !empty($arr['calltime']) && is_array($arr['calltime'])) {
  353. if (count(array_filter($arr['calltime'])) == 2) {
  354. $where['calltime'] = $arr['calltime'];
  355. }
  356. }*/
  357. if (isset($arr['worktype']) && !empty($arr['worktype']) && is_string($arr['worktype'])) {
  358. $where['worktype'] = $arr['worktype'];
  359. }
  360. $daystr = $callday;
  361. $isExist = $this->m_ucd->isexist($daystr);
  362. if (!$isExist) {
  363. $where['callday'] = $daystr;
  364. $count = $this->m_uc->getconnectlist($where, true);
  365. $count = $count[0]['count'];
  366. if ($count <= 0) {
  367. return backarr(0, '无数据');
  368. }
  369. } else {
  370. $this->m_ucd->setTableName($daystr);
  371. $count = $this->m_ucd->getconnectlist($where, true);
  372. $count = $count[0]['count'];
  373. if ($count <= 0) {
  374. return backarr(0, '无数据');
  375. }
  376. $list = $this->m_ucd->getconnectlist($where, false, $page, $size);
  377. }
  378. $data = [
  379. 'count' => $count,
  380. 'list' => $list,
  381. ];
  382. return backarr(1, '查询成功', $data);
  383. }
  384. /***
  385. * 保存用户点击行为 保存工作类型
  386. * 20211209
  387. * wj
  388. */
  389. public function saveuserclickworktype($arr)
  390. {
  391. $arr['source_type'] = 'worktype';
  392. $result = $this->checkData($arr);
  393. if (1 != $result['status']) {
  394. return $result;
  395. }
  396. $refId = isset($arr['ref_id']) ? $arr['ref_id'] : 0;
  397. $uaData = [
  398. 'uid' => $arr['uid'],
  399. 'ref_id' => $refId,
  400. 'type' => 1,
  401. 'source_type' => $arr['source_type'],
  402. 'record_time' => date('Y-m-d H:i:s'),
  403. ];
  404. $usId = $this->m_ua->insinfo($uaData);
  405. if (empty($usId)) {
  406. return backarr(0, "保存失败");
  407. }
  408. return backarr(1, "保存成功");
  409. }
  410. /*
  411. * 20211220
  412. * wj
  413. * 统计联系电话的时间段
  414. */
  415. public function getconnecttimebucket($arr)
  416. {
  417. $date = isset($arr['date']) && !empty($arr['date']) ? $arr['date'] : date('Ymd');
  418. $daystr = date('Ymd', strtotime($date));
  419. $isExist = $this->m_ucd->isexist($daystr);
  420. if (!$isExist) {
  421. $where['callday'] = $daystr;
  422. $list = $this->m_uc->getconnecttimebucket($where);
  423. if (empty($list)) {
  424. return backarr(0, '无数据');
  425. }
  426. } else {
  427. $this->m_ucd->setTableName($daystr);
  428. $list = $this->m_ucd->getconnecttimebucket($arr);
  429. if (empty($list)) {
  430. return backarr(0, '无数据');
  431. }
  432. }
  433. return backarr(1, '查询成功', $list);
  434. }
  435. /*
  436. * 20211222
  437. * wj
  438. * 统计联系电话次数
  439. */
  440. public function getconnectbyinvent($arr)
  441. {
  442. $date = isset($arr['date']) && !empty($arr['date']) ? $arr['date'] : date('Ymd');
  443. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  444. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  445. $daystr = date('Ymd', strtotime($date));
  446. $isExist = $this->m_ucd->isexist($daystr);
  447. if (!$isExist) {
  448. $where['callday'] = $daystr;
  449. $count = $this->m_uc->getconnectbyinvent($where, true);
  450. if ($count <= 0) {
  451. return backarr(0, '无数据');
  452. }
  453. $list = $this->m_uc->getconnectbyinvent($where, false, $page, $size);
  454. } else {
  455. $this->m_ucd->setTableName($daystr);
  456. $count = $this->m_ucd->getconnectbyinvent($arr, true);
  457. if ($count <= 0) {
  458. return backarr(0, '无数据');
  459. }
  460. $list = $this->m_ucd->getconnectbyinvent($arr, false, $page, $size);
  461. }
  462. $date = [
  463. 'count' => $count,
  464. 'list' => $list,
  465. ];
  466. return backarr(1, '查询成功', $date);
  467. }
  468. }