HouseApi.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. namespace app\common\api;
  3. use app\common\state\MainState;
  4. use think\facade\Db;
  5. use app\common\model\HousePurchase as houseModel;
  6. use app\common\model\HousePurchaseChildren as houseChildModel;
  7. use app\common\model\HousePurchaseHouseInfo as houseInfoModel;
  8. use app\common\model\HousePurchaseEnjoyOther as enjoyOtherModel;
  9. use app\common\model\HousePurchaseOtherHouse as otherHouseModel;
  10. use app\common\model\HousePurchaseSpouse as spouseModel;
  11. use app\common\state\HouseStateEnum;
  12. /**
  13. * Description of HouseApi
  14. *
  15. * @author sgq
  16. */
  17. class HouseApi {
  18. public static function getList($where = [], $field = "*") {
  19. return houseModel::where($where)->field($field)->select()->order("createTime desc")->toArray();
  20. }
  21. public static function getInfoById($id) {
  22. return houseModel::findOrEmpty($id)->toArray();
  23. }
  24. public static function getFstInfoById($idCard) {
  25. $where = [];
  26. $where[] = ["declareType", "=", 1];
  27. $where[] = ["publicState", "=", 5];
  28. $where[] = ["checkState", "=", HouseStateEnum::REVIEW_PASS];
  29. $where[] = ["cashType", "=", 1];
  30. $where[] = ["idCard", "=", $idCard];
  31. return houseModel::where($where)->order("firstSubmitTime asc")->find();
  32. }
  33. public static function getEnjoyTimesByIdCard($idCard) {
  34. $where = [];
  35. $where[] = ["declareType", "=", 1];
  36. $where[] = ["publicState", "=", 5];
  37. $where[] = ["cashType", "=", 1];
  38. $where[] = ["cashIdCards", "like", "%" . $idCard . "%"];
  39. $count = houseModel::where($where)->order("year desc")->count();
  40. return $count;
  41. }
  42. public static function getHouseInfo($idCard) {
  43. if (\StrUtil::isEmpOrNull($idCard)) {
  44. return null;
  45. }
  46. $where = [];
  47. $where[] = ["idCard", "=", $idCard];
  48. return houseInfoModel::where($where)->find();
  49. }
  50. public static function getSpouse($id) {
  51. $where = [];
  52. $where[] = ["pId", "=", $id];
  53. return spouseModel::where($where)->select()->toArray();
  54. }
  55. public static function getChildren($id) {
  56. $where = [];
  57. $where[] = ["pId", "=", $id];
  58. return houseChildModel::where($where)->select()->toArray();
  59. }
  60. public static function getChildrenById($id) {
  61. return houseChildModel::where($where)->find($id);
  62. }
  63. public static function getHistoryEnjoyOtherList($id, $idCard, $spouseIdcard = null) {
  64. $where = [];
  65. $idCards = [];
  66. $idCards[] = $idCard;
  67. if (\StrUtil::isNotEmpAndNull($spouseIdcard)) {
  68. $idCards[] = $spouseIdcard;
  69. }
  70. $where[] = ["cashType", "=", 1];
  71. $where[] = ["checkState", "=", HouseStateEnum::REVIEW_PASS];
  72. $where[] = ["publicState", ">=", 4];
  73. $where[] = ["id", "<>", $id];
  74. $whereRaw = sprintf("idCard in ('%s') or spouseIdcard in ('%s')", implode("','", $idCards), implode("','", $idCards));
  75. $ids = houseModel::field("id")->where($where)->whereRaw($whereRaw)->column("id");
  76. $historyOtherList = null;
  77. if ($ids) {
  78. $where = [];
  79. $where[] = ["pId", "in", $ids];
  80. $historyOtherList = enjoyOtherModel::where($where)->select()->toArray();
  81. }
  82. return $historyOtherList;
  83. }
  84. public static function getEnjoyOtherList($id) {
  85. $where = [];
  86. $where[] = ["pId", "=", $id];
  87. return enjoyOtherModel::where($where)->select()->toArray();
  88. }
  89. public static function getOtherHouseList($id, $type = 1) {
  90. $where = [];
  91. $where[] = ["pId", "=", $id];
  92. $where[] = ["type", "=", $type];
  93. return otherHouseModel::where($where)->select()->toArray();
  94. }
  95. /**
  96. * 部门审核列表
  97. * @param type $query
  98. * @param type $company
  99. * @param type $type
  100. * @param type $offset
  101. * @param type $limit
  102. */
  103. public static function selectForHousePurchase($query, $company, $type, $offset, $limit) {
  104. $where = [];
  105. if ($company["name"] != "super" && $company["code"] != "rsj") {
  106. $where[] = ["t1.companyId", "=", $company["id"]];
  107. }
  108. if (($company["name"] == "super" || $company["code"] == "rsj") && \StrUtil::isNotEmpAndNull($query["companyName"])) {
  109. $where[] = ["t3.name", "like", "%" . $query["companyName"] . "%"];
  110. }
  111. if (\StrUtil::isNotEmpAndNull($query["year"])) {
  112. $where[] = ["t2.year", "=", $query["year"]];
  113. }
  114. if (\StrUtil::isNotEmpAndNull($query["name"])) {
  115. $where[] = ["t2.name", "like", "%" . $query["name"] . "%"];
  116. }
  117. if (\StrUtil::isNotEmpAndNull($query["idCard"])) {
  118. $where[] = ["t2.idCard", "like", "%" . $query["idCard"] . "%"];
  119. }
  120. if (\StrUtil::isNotEmpAndNull($query["spouseName"])) {
  121. $where[] = ["t2.spouseName", "like", "%" . $query["spouseName"] . "%"];
  122. }
  123. if (\StrUtil::isNotEmpAndNull($query["spouseIdcard"])) {
  124. $where[] = ["t2.spouseIdcard", "like", "%" . $query["spouseIdcard"] . "%"];
  125. }
  126. if (\StrUtil::isNotEmpAndNull($query["childName"])) {
  127. $where[] = ["t2.childName", "like", "%" . $query["childName"] . "%"];
  128. }
  129. if (\StrUtil::isNotEmpAndNull($query["childIdCard"])) {
  130. $where[] = ["t2.childIdCard", "like", "%" . $query["childIdCard"] . "%"];
  131. }
  132. if (\StrUtil::isNotEmpAndNull($query["talentArrange"])) {
  133. $where[] = ["t2.talentArrange", "=", $query["talentArrange"]];
  134. }
  135. if (\StrUtil::isNotEmpAndNull($query["marryStatus"])) {
  136. $where[] = ["t2.marryStatus", "=", $query["marryStatus"]];
  137. }
  138. if (\StrUtil::isNotEmpAndNull($query["state"])) {
  139. $where[] = ["t1.state", "=", $query["state"]];
  140. }
  141. if (\StrUtil::isNotEmpAndNull($query["isConflict"])) {
  142. $where[] = ["t2.isConflict", "=", $query["isConflict"]];
  143. }
  144. if (\StrUtil::isNotEmpAndNull($query["isRecover"])) {
  145. $where[] = ["t2.isRecover", "=", $query["isRecover"]];
  146. }
  147. $where[] = ["t1.type", "=", $type];
  148. $count = Db::table("un_talent_depcheckstate")->alias("t1")
  149. ->leftJoin("un_housepurchase t2", "t2.id=t1.mainId")
  150. ->leftJoin("sys_company t3", "t3.id=t1.companyId")
  151. ->where($where)
  152. ->count();
  153. $list = Db::table("un_talent_depcheckstate")->alias("t1")
  154. ->field("t2.*,t1.companyId,t1.state,t3.`name` AS companyName,t5.description AS checkMsg")
  155. ->leftJoin("un_housepurchase t2", "t2.id=t1.mainId")
  156. ->leftJoin("sys_company t3", "t3.id=t1.companyId")
  157. ->leftJoin("(SELECT t4.mainId,t4.createTime,t4.companyId,t4.description FROM (SELECT * FROM new_talent_checklog WHERE type = {$type} AND step = 2 AND state != 8 ORDER BY createTime DESC LIMIT 100000) t4 GROUP BY t4.mainId,t4.companyId ORDER BY t4.createTime DESC) t5", "t1.mainId = t5.mainId AND t1.companyId = t5.companyId")
  158. ->where($where)
  159. ->limit($offset, $limit)
  160. ->order("t1.createTime DESC")
  161. ->select()->toArray();
  162. return ["total" => $count, "rows" => $list];
  163. }
  164. public static function deleteById($id) {
  165. $data["id"] = $id;
  166. $data["delete"] = 1;
  167. $data["deleteUser"] = session("user")["uid"];
  168. $data["deleteTime"] = date("Y-m-d H:i:s");
  169. if (houseModel::update($data)) {
  170. enjoyOtherModel::where("pId", $id)->delete();
  171. return true;
  172. }
  173. return false;
  174. }
  175. public static function deleteChildrenById($id) {
  176. return houseChildModel::where("id", $id)->delete();
  177. }
  178. }