inventmodel.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-09-27 08:46:31
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-12-30 13:41:17
  7. */
  8. namespace app\index\model;
  9. use think\Model;
  10. class inventmodel extends Model
  11. {
  12. protected $table = 't_invent';
  13. public function insertData($data)
  14. {
  15. $id = $this->insertGetId($data);
  16. return empty($id) ? false : $id;
  17. }
  18. public function getInfo($where, $field = "*", $row = true)
  19. {
  20. $info = $this->field($field)->where($where);
  21. if ($row) {
  22. $info = $info->find();
  23. } else {
  24. $info = $info->select();
  25. }
  26. return empty($info) ? false : $info;
  27. }
  28. public function getList($where = [], $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  29. {
  30. $sqlObj = $this->where($where);
  31. if ("count" != $field) {
  32. $sqlObj = $sqlObj->field($field)->order($order)->group($group)->page($page, $size);
  33. if ($row) {
  34. $data = $sqlObj->find();
  35. } else {
  36. $data = $sqlObj->select();
  37. }
  38. } else {
  39. $data = $sqlObj = $sqlObj->count();
  40. }
  41. return $data;
  42. }
  43. public function updateinfo($where, $updateData)
  44. {
  45. $row = $this->where($where)->update($updateData);
  46. return empty($row) ? false : $row;
  47. }
  48. public function deleteinfo($where)
  49. {
  50. $row = $this->where($where)->delete();
  51. return empty($row) ? false : $row;
  52. }
  53. public function incField($where, $field, $step = 1)
  54. {
  55. $row = $this->where($where)->setInc($field, $step);
  56. return empty($row) ? false : $row;
  57. }
  58. /*
  59. * 20211002
  60. * 根据发布者ID获取清单
  61. * 应用于发布者查看本人发布的消息
  62. */
  63. public function sellistbyuid($uid)
  64. {
  65. $where_arr['createuid'] = $uid;
  66. $rlist = $this->where($where_arr)->order('id', 'desc')->select();
  67. $rlist = collection($rlist)->toArray();
  68. return $rlist;
  69. }
  70. /**
  71. * 根据条件查询
  72. */
  73. public function getlistjoinuser($where, $field = "*", $page = 1, $size = 10, $order = "id desc", $group = "", $row = false)
  74. {
  75. $sql = $this->alias('i')->join('t_userinfo u', 'i.createuid=u.id')->join('t_webuser w', 'i.releaseid=w.id', 'LEFT');
  76. $whereUse = [];
  77. if (isset($where['telno']) && !empty($where['telno'])) {
  78. $whereUse['u.telno'] = ['like', '%' . $where['telno'] . '%'];
  79. }
  80. if (isset($where['wname']) && !empty($where['wname'])) {
  81. $whereUse['u.wname'] = ['like', '%' . $where['wname'] . '%'];
  82. }
  83. if (isset($where['isactive']) && is_numeric($where['isactive'])) {
  84. $whereUse['i.isactive'] = $where['isactive'];
  85. }
  86. if (isset($where['ispass']) && is_numeric($where['ispass'])) {
  87. $whereUse['i.ispass'] = $where['ispass'];
  88. }
  89. if (isset($where['code']) && !empty($where['code'])) {
  90. $whereUse['i.code'] = ['like', '%' . $where['code'] . '%'];
  91. }
  92. if (isset($where['worktype']) && !empty($where['worktype'])) {
  93. $whereUse['i.worktype'] = $where['worktype'];
  94. }
  95. if (isset($where['release_user']) && !empty($where['release_user'])) {
  96. if ('null' == $where['release_user']) {
  97. $sql->whereNull('i.releaseid');
  98. } else {
  99. $whereUse['w.user_name'] = ['like', '%' . $where['release_user'] . '%'];
  100. }
  101. }
  102. if (isset($where['createdate']) && is_array($where['createdate'])) {
  103. $whereUse['createdate'] = ['between', $where['createdate']];
  104. }
  105. if ($field == 'count') {
  106. $data = $sql->where($whereUse)->count();
  107. } else {
  108. $field = ['u.wname', 'u.telno', 'u.isactive', 'w.user_name release_user', 'i.*'];
  109. if ($row) {
  110. $data = $sql->where($whereUse)->field($field)->page($page, $size)->order($order)->find();
  111. } else {
  112. $data = $sql->where($whereUse)->field($field)->page($page, $size)->order($order)->group($group)->select();
  113. }
  114. }
  115. return empty($data) ? false : $data;
  116. }
  117. /**
  118. * 获取总数
  119. * 20211117
  120. * wj
  121. */
  122. public function getcount()
  123. {
  124. $count = $this->where([])->count();
  125. return $count;
  126. }
  127. /**
  128. * 获取分析数据
  129. * 20211117
  130. * wj
  131. */
  132. public function statistics()
  133. {
  134. $sql = "select isactive,ispass,count(*) as count from " . $this->table . " group by isactive,ispass";
  135. $list = $this->query("select * from (" . $sql . ") as t");
  136. return $list;
  137. }
  138. /*
  139. * 20211130
  140. * steelxu5
  141. * 根据ID获取信息
  142. */
  143. public function selinfobyid($id)
  144. {
  145. $where_arr['id'] = $id;
  146. $rec = $this->where($where_arr)->find();
  147. return $rec;
  148. }
  149. /***
  150. * 移动端根据多个条件获取列表
  151. * 20211215
  152. * wj
  153. */
  154. public function getlistbymultiplecondition($where = [], $page = 1, $size = 10, $order = "id desc")
  155. {
  156. $whereUse = ['isactive=1', 'ispass=1'];
  157. if (!empty($where)) {
  158. foreach ($where as $key => $value) {
  159. if ('city' == $key) {
  160. $whereUse[] = "city like '%" . $value . "%'";
  161. }
  162. if ('disc' == $key) {
  163. $whereUse[] = "disc like '%" . $value . "%'";
  164. }
  165. if ('town' == $key) {
  166. $whereUse[] = "town like '%" . $value . "%'";
  167. }
  168. if ('address' == $key) {
  169. $whereUse[] = "address like '%" . $value . "%'";
  170. }
  171. if ('worktype' == $key) {
  172. $whereUse[] = "worktype like '%" . $value . "%'";
  173. }
  174. if ('lng' == $key) {
  175. $value = (double) $value;
  176. $radii = (double) $where['radii'];
  177. $whereUse[] = "ABS(gps_lng-" . $value . ")<=" . $radii;
  178. }
  179. if ('lat' == $key) {
  180. $value = (double) $value;
  181. $radii = (double) $where['radii'];
  182. $whereUse[] = "ABS(gps_lat-" . $value . ")<=" . $radii;
  183. }
  184. }
  185. }
  186. $whereStr = implode(' and ', $whereUse);
  187. $index = ($page - 1) * $size;
  188. $sql = "select * from t_invent where " . $whereStr . " order by " . $order . " limit " . $index . ',' . $size;
  189. $list = $this->query("select * from (" . $sql . ") as t");
  190. return $list;
  191. }
  192. /**
  193. * 获取一定时间内无联系数量
  194. * 20211222
  195. * wj
  196. */
  197. public function getnocalldata($min = 5, $where = [], $count = false, $page = 1, $size = 10)
  198. {
  199. if (empty($min) || !is_numeric($min)) {
  200. $min = 5;
  201. }
  202. $sql = "select u.wname,u.telno,i.*,ROUND((UNIX_TIMESTAMP(now())-UNIX_TIMESTAMP(i.passtime))/60,0) time
  203. from t_invent as i join t_userinfo as u on i.createuid=u.id
  204. where
  205. i.concount<=0 and i.ispass=1 and i.isactive=1";
  206. /*$sql = "select u.wname,u.telno,i.*
  207. from t_invent as i join t_userinfo as u on i.createuid=u.id
  208. where i.passtime>= now()-interval " . $min . " minute and i.concount<=0 and i.ispass=1 and i.isactive=1";*/
  209. $whereUse = [];
  210. if (!empty($where)) {
  211. foreach ($where as $key => $value) {
  212. if ('wname' == $key) {
  213. $whereUse[] = "u.wname like '%" . $value . "%'";
  214. }
  215. if ('telno' == $key) {
  216. $whereUse[] = "u.telno like '%" . $value . "%'";
  217. }
  218. }
  219. }
  220. if (!empty($whereUse)) {
  221. $whereStr = implode(' and ', $whereUse);
  222. $sql .= " and " . $whereStr;
  223. }
  224. $sql .= ' ORDER BY i.id desc';
  225. if ($count) {
  226. $list = $this->query("select count(*) count from (" . $sql . ") as t");
  227. $count = $list[0]['count'];
  228. return $count;
  229. }
  230. $index = ($page - 1) * $size;
  231. $list = $this->query("select * from (" . $sql . ") as t limit " . $index . "," . $size);
  232. return $list;
  233. }
  234. }