userconnectrecordmodel.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-09-28 11:13:58
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-12-24 16:48:36
  7. */
  8. namespace app\index\model;
  9. use think\Model;
  10. class userconnectrecordmodel extends Model
  11. {
  12. protected $table = 't_userconnectrecord';
  13. public function insinfo($arr)
  14. {
  15. if (!isset($arr['calltime']) || empty($arr['calltime'])) {
  16. $arr['calltime'] = date("Y-m-d H:i:s");
  17. }
  18. $id = $this->insertGetId($arr);
  19. return $id;
  20. }
  21. /***
  22. * 校验数据是否可添加
  23. * 20211215
  24. * wj
  25. */
  26. public function checkDataForInsert($arr)
  27. {
  28. $where = [
  29. 'senduserid' => $arr['senduserid'],
  30. 'calltime' => ['like', '%' . date('Y-m-d') . '%'],
  31. ];
  32. $row = $this->where($where)->count();
  33. if ($row > 0) {
  34. return backarr(0, "数据已存在");
  35. }
  36. return backarr(1, "数据可新增");
  37. }
  38. /*
  39. * 20211129
  40. * steelxu5
  41. * 根据主动联系人的用户id,返回联系数据
  42. * todo 当联系数据多时,后期需要改成按起始日期统计,分步加载,
  43. */
  44. public function seltotalbyuserid($userid)
  45. {
  46. $strsql = 'select substr(calltime,1,10) as calldate,count(id) as connectcount,sum(senderevaluate) as evaluatecount';
  47. $strsql = $strsql . " from t_userconnectrecord where senduserid=" . $userid;
  48. $strsql = $strsql . " group by substr(calltime,1,10)";
  49. $rlist = $this->query($strsql);
  50. $rlist = collection($rlist)->toArray();
  51. return $rlist;
  52. }
  53. /*
  54. * 20211130
  55. * steelxu5
  56. * 获取某一天的,某人的联系记录
  57. */
  58. public function selinfolistbyuiddate($userid, $date)
  59. {
  60. $strsql = 'select *';
  61. $strsql = $strsql . " from t_userconnectrecord where senduserid=" . $userid . " and calltime like '" . $date . "%' ";
  62. $rlist = $this->query($strsql);
  63. $rlist = collection($rlist)->toArray();
  64. return $rlist;
  65. }
  66. /*
  67. * 20211201
  68. * steelxu5
  69. * 更新评价状态
  70. */
  71. public function updatesenderevaluebysid($sourceid, $sourcetype)
  72. {
  73. $where_arr['sourcetype'] = $sourcetype;
  74. $where_arr['sourceid'] = $sourceid;
  75. $update_arr['senderevaluate'] = 1;
  76. $count = $this->where($where_arr)->update($update_arr);
  77. return $count;
  78. }
  79. /*
  80. * 20211209
  81. * wj
  82. * 获得联系电话列表
  83. */
  84. public function getconnectlist($where, $count = false, $page = 1, $size = 10)
  85. {
  86. $sql = "
  87. select uc.id,uc.senduserid,us.wname as swname,us.id as sid,us.telno as stelno,uc.reciveruserid,ur.id as rid,ur.wname as rwname,ur.telno as rtelno,i.code,i.id as iid,i.worktype,uc.calltime
  88. from t_userconnectrecord as uc
  89. join t_invent as i on uc.sourceid=i.id
  90. join t_userinfo as us on uc.senduserid=us.id
  91. join t_userinfo as ur on uc.reciveruserid=ur.id
  92. ORDER BY uc.calltime desc";
  93. $tabsql = "select * from (" . $sql . ") as tab";
  94. $usewhere = [];
  95. //打电话人
  96. if (isset($where['swname']) && !empty($where['swname']) && is_string($where['swname'])) {
  97. $usewhere[] = "swname like '%" . $where['swname'] . "%'";
  98. }
  99. //拨打电话
  100. if (isset($where['stelno']) && !empty($where['stelno']) && is_string($where['stelno'])) {
  101. $usewhere[] = "stelno like '%" . $where['stelno'] . "%'";
  102. }
  103. //被联系人
  104. if (isset($where['rwname']) && !empty($where['rwname']) && is_string($where['rwname'])) {
  105. $usewhere[] = "rwname like '%" . $where['rwname'] . "%'";
  106. }
  107. //被联系电话
  108. if (isset($where['rtelno']) && !empty($where['rtelno']) && is_string($where['rtelno'])) {
  109. $usewhere[] = "rtelno like '%" . $where['rtelno'] . "%'";
  110. }
  111. //招工code
  112. if (isset($where['code']) && !empty($where['code']) && is_string($where['code'])) {
  113. $usewhere[] = "code like '%" . $where['code'] . "%'";
  114. }
  115. //打电话时间段
  116. if (isset($where['calltime']) && !empty($where['calltime']) && is_array($where['calltime'])) {
  117. $usewhere[] = "calltime >= '" . $where['calltime'][0] . "'";
  118. $usewhere[] = "calltime < '" . $where['calltime'][1] . "'";
  119. }
  120. if (isset($where['callday']) && !empty($where['callday']) && is_string($where['callday'])) {
  121. $where['callday'] = date('Y-m-d', strtotime($where['callday']));
  122. $usewhere[] = "calltime like '%" . $where['callday'] . "%'";
  123. }
  124. //工作类型
  125. if (isset($where['worktype']) && !empty($where['worktype']) && is_string($where['worktype'])) {
  126. $usewhere[] = "worktype like '%" . $where['worktype'] . "%'";
  127. }
  128. if (!empty($usewhere)) {
  129. $tabwhere = implode(' and ', $usewhere);
  130. $tabsql .= ' where ' . $tabwhere;
  131. }
  132. if (!$count) {
  133. $index = ($page - 1) * $size;
  134. $tabsql .= " limit " . $index . "," . $size;
  135. }
  136. if ($count) {
  137. $list = $this->query("select count(*) count from (" . $tabsql . ") as t");
  138. } else {
  139. $list = $this->query("select * from (" . $tabsql . ") as t");
  140. }
  141. return $list;
  142. }
  143. /*
  144. * 20211220
  145. * wj
  146. * 统计联系电话的时间段
  147. */
  148. public function getconnecttimebucket($where)
  149. {
  150. $tabsql = "select DATE_FORMAT(calltime,'%H') as hour,count(*) count from t_userconnectrecord as uc join t_invent as i on uc.sourceid=i.id";
  151. $group = " group by hour ORDER BY hour asc";
  152. $usewhere = [];
  153. if (isset($where['callday']) && !empty($where['callday']) && is_string($where['callday'])) {
  154. $where['callday'] = date('Y-m-d', strtotime($where['callday']));
  155. $usewhere[] = "calltime like '%" . $where['callday'] . "%'";
  156. } else {
  157. $dayStr = date('Y-m-d');
  158. $usewhere[] = "calltime like '%" . $dayStr . "%'";
  159. }
  160. if (!empty($usewhere)) {
  161. $tabwhere = implode(' and ', $usewhere);
  162. $tabsql .= ' where ' . $tabwhere;
  163. }
  164. $tabsql .= $group;
  165. $list = $this->query("select * from (" . $tabsql . ") as t");
  166. return $list;
  167. }
  168. /*
  169. * 20211222
  170. * wj
  171. * 统计联系电话联系数量
  172. */
  173. public function getconnectbyinvent($where, $count = false, $page = 1, $size = 10)
  174. {
  175. $tabsql = "select uc.sourceid,i.id,i.createdate,i.code,i.info,i.isactive,i.ispass,count(uc.id) count from " . $this->table . " as uc join t_invent as i on uc.sourceid=i.id";
  176. $group = " GROUP BY uc.sourceid ORDER BY i.id desc";
  177. $usewhere = [
  178. #'i.isactive' => 1,
  179. 'i.ispass' => 1,
  180. ];
  181. if (isset($where['callday']) && !empty($where['callday']) && is_string($where['callday'])) {
  182. $where['callday'] = date('Y-m-d', strtotime($where['callday']));
  183. $usewhere[] = "calltime like '%" . $where['callday'] . "%'";
  184. } else {
  185. $dayStr = date('Y-m-d');
  186. $usewhere[] = "calltime like '%" . $dayStr . "%'";
  187. }
  188. if (!empty($usewhere)) {
  189. $tabwhere = implode(' and ', $usewhere);
  190. $tabsql .= ' where ' . $tabwhere;
  191. }
  192. $tabsql .= $group;
  193. if ($count) {
  194. $list = $this->query("select count(*) count from (" . $tabsql . ") as t");
  195. $count = $list[0]['count'];
  196. return $count;
  197. } else {
  198. $index = ($page - 1) * $size + 1;
  199. $list = $this->query("select * from (" . $tabsql . ") as t limit " . $index . "," . $size);
  200. }
  201. return $list;
  202. }
  203. }