LivingAllowanceApi.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\enterprise\api;
  3. use app\common\model\LivingAllowance as laModel;
  4. use app\common\api\DictApi;
  5. use app\common\state\LivingAllowanceState;
  6. /**
  7. * Description of LivingAllowanceApi
  8. *
  9. * @author sgq
  10. */
  11. class LivingAllowanceApi {
  12. /**
  13. * 判断是否可以编辑
  14. * @param type $id
  15. * @return boolean
  16. */
  17. public static function checkIsEditable($id) {
  18. $info = self::getOne($id);
  19. if (!$info || !in_array($info["checkState"], [0, LivingAllowanceState::FST_SAVE, LivingAllowanceState::BASE_REVERIFY_PASS, LivingAllowanceState::SCND_SAVE]))
  20. return false;
  21. return true;
  22. }
  23. static public function chkIsOwner($id, $uid) {
  24. $info = self::getOne($id);
  25. if ($info["enterprise_id"] != $uid)
  26. return null;
  27. return $info;
  28. }
  29. public static function getOne($id) {
  30. return laModel::findOrEmpty($id)->toArray();
  31. }
  32. public static function getList($request) {
  33. $order = trim($request->param("order")) ?: "desc";
  34. $offset = trim($request->param("offset")) ?: 0;
  35. $limit = trim($request->param("limit")) ?: 10;
  36. $name = trim($request->param("name"));
  37. $idCard = trim($request->param("idCard"));
  38. $type = session("user")["type"];
  39. $where = [];
  40. if (session("user")["usertype"] == 2) {
  41. $where[] = ["enterpriseId", "=", session("user")["uid"]];
  42. }
  43. //$where[] = ["isImport", "=", $request->param("import") ?: 0];
  44. if ($name) {
  45. $where[] = ["name", "like", "%" . $name . "%"];
  46. }
  47. if ($idCard) {
  48. $where[] = ["idCard", "like", "%" . $idCard . "%"];
  49. }
  50. $count = laModel::where($where)->count();
  51. $list = laModel::where($where)->limit($offset, $limit)->order("createTime " . $order)->select()->toArray();
  52. $masterTypes = DictApi::selectByParentCode("un_master_education"); //申报对象类型
  53. $degrees = DictApi::selectByParentCode("highest_degree"); //最高学历
  54. $enterprise = \app\common\model\Enterprise::find(session("user")["uid"]);
  55. foreach ($list as $key => $item) {
  56. $list[$key]["declareTypeName"] = $masterTypes[$item["declareType"]];
  57. $list[$key]["highEducation"] = $degrees[$item["highEducation"]];
  58. $list[$key]["enterpriseName"] = $enterprise["name"];
  59. }
  60. return ["total" => $count, "rows" => $list];
  61. }
  62. }