HouseApi.php 8.0 KB

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