HouseApi.php 7.0 KB

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