EnterpriseVerifyMgrApi.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\api;
  3. use app\common\model\EnterpriseVerifyMgr;
  4. class EnterpriseVerifyMgrApi {
  5. public static function getOne($id) {
  6. return EnterpriseVerifyMgr::findOrEmpty($id);
  7. }
  8. public static function getList($params) {
  9. $order = $params["order"] ?: "desc";
  10. $offset = $params["offset"] ?: 0;
  11. $limit = $params["limit"] ?: 10;
  12. $where[] = ["m.delete", "=", 0];
  13. $count = EnterpriseVerifyMgr::alias("m")->leftJoin("sys_company c", "c.id=m.companyId")->where($where)->count();
  14. $list = EnterpriseVerifyMgr::alias("m")->leftJoin("sys_company c", "c.id=m.companyId")->where($where)->limit($offset, $limit)->order("m.updateTime desc,m.createTime desc")->field("m.*,c.name as companyName")->select()->toArray();
  15. $enterpriseTags = DictApi::selectByParentCode("enterprise_tag");
  16. $organizationTags = DictApi::selectByParentCode("organization_tag");
  17. $institutionTags = DictApi::selectByParentCode("institution_tag");
  18. foreach ($list as $key => $item) {
  19. $list[$key]["enterpriseTagName"] = $enterpriseTags[$item["enterpriseTag"]];
  20. $list[$key]["organizationTagName"] = $organizationTags[$item["organizationTag"]];
  21. $list[$key]["institutionTagName"] = $institutionTags[$item["institutionTag"]];
  22. }
  23. return ["total" => $count, "rows" => $list];
  24. }
  25. public static function getAll() {
  26. $where[] = ["delete", "=", 0];
  27. $list = EnterpriseVerifyMgr::where($where)->order("sn asc")->select()->toArray();
  28. return $list;
  29. }
  30. public static function edit($params) {
  31. $data["enterpriseTag"] = $params["enterpriseTag"];
  32. $data["organizationTag"] = $params["organizationTag"];
  33. $data["institutionTag"] = $params["institutionTag"];
  34. $data["companyId"] = $params["companyId"];
  35. $data["description"] = $params["description"];
  36. $data["uniCode"] = implode(",", array_unique(array_filter(explode(",", $params["uniCode"]))));
  37. if ($params["id"]) {
  38. $data["id"] = $params["id"];
  39. $data["updateTime"] = date("Y-m-d H:i:s");
  40. $data["updateUser"] = session("user")["uid"];
  41. return EnterpriseVerifyMgr::update($data);
  42. } else {
  43. $data["id"] = getStringId();
  44. $data["createTime"] = date("Y-m-d H:i:s");
  45. $data["createUser"] = session("user")["uid"];
  46. return EnterpriseVerifyMgr::insert($data);
  47. }
  48. }
  49. public static function delete($id) {
  50. $data["id"] = $id;
  51. $data["delete"] = 1;
  52. $data["updateUser"] = session("user")["uid"];
  53. $data["updateTime"] = date("Y-m-d H:i:s");
  54. return EnterpriseVerifyMgr::update($data);
  55. }
  56. public static function chkExist($tag, $id = 0) {
  57. $where = [];
  58. if ($id) {
  59. $where[] = ["id", "<>", $id];
  60. }
  61. $where[] = ["delete", "=", 0];
  62. $where[] = ["enterpriseTag", "=", $tag];
  63. return EnterpriseVerifyMgr::where($where)->find();
  64. }
  65. public static function chkUnicodeExist($codes, $id = 0) {
  66. $where = [];
  67. if ($id) {
  68. $where[] = ["id", "<>", $id];
  69. }
  70. $codes = array_unique(array_filter(explode(",", $codes)));
  71. $where[] = ["delete", "=", 0];
  72. $whereRaw = sprintf("concat(',',uniCode,',') regexp(',%s,')", implode(",|,", $codes));
  73. return EnterpriseVerifyMgr::where($where)->whereRaw($whereRaw)->find();
  74. }
  75. }