companylogic.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2022-01-18 11:12:23
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2022-01-19 15:51:59
  7. */
  8. namespace app\admin\logic;
  9. use app\admin\model\companymodel;
  10. use think\facade\Log;
  11. class companylogic extends baselogic
  12. {
  13. /**
  14. * 设置请求数据规则
  15. * 20220107
  16. * wj
  17. */
  18. protected function setrules()
  19. {
  20. $list = [
  21. 'auditcompany' => [
  22. ['name' => 'idlist', 'title' => 'idlist', 'require' => true, 'type' => 'array'],
  23. ['name' => 'ispass', 'title' => 'ispass', 'require' => true, 'type' => 'numeric', 'regex' => '/[1|2]{1}/'],
  24. ],
  25. 'getlistbywhere' => [
  26. ['name' => 'ispass', 'title' => 'ispass', 'type' => 'numeric', 'regex' => '/[0|1|2]{1}/'],
  27. ['name' => 'companyname', 'title' => 'companyname', 'type' => 'string'],
  28. ['name' => 'createdate', 'title' => 'createdate', 'type' => 'array'],
  29. ['name' => 'page', 'title' => 'page', 'type' => 'numeric'],
  30. ['name' => 'size', 'title' => 'size', 'type' => 'numeric'],
  31. ],
  32. ];
  33. return $list;
  34. }
  35. /**
  36. * 审核公司
  37. * 20220208
  38. * wj
  39. */
  40. public function auditcompany($arr)
  41. {
  42. $result = $this->checkparam(__FUNCTION__, $arr);
  43. if (1 != $result['status']) {
  44. return $result;
  45. }
  46. $ids = $arr['idlist'];
  47. if (is_string($ids)) {
  48. $ids = [$ids];
  49. }
  50. $ispass = $arr['ispass'];
  51. $m_c = new companymodel();
  52. $successIds = [];
  53. foreach ($ids as $key => $value) {
  54. $where = ['id' => $value];
  55. $info = $m_c->getInfo($where);
  56. if (empty($info)) {
  57. log::error("company_id " . $value . " 无对应企业");
  58. continue;
  59. }
  60. if ($ispass != $info['ispass']) {
  61. $successIds[] = $value;
  62. $update = ['ispass' => $ispass];
  63. $m_c->updateinfo($where, $update);
  64. }
  65. }
  66. $data = [
  67. 'successIds' => $successIds,
  68. ];
  69. return backarr(1, "操作成功", $data);
  70. }
  71. /**
  72. * 获取公司列表
  73. * 20220208
  74. * wj
  75. */
  76. public function getlistbywhere($arr)
  77. {
  78. $arr = $this->filterarray($arr);
  79. $result = $this->checkparam(__FUNCTION__, $arr);
  80. if (1 != $result['status']) {
  81. return $result;
  82. }
  83. $where = [];
  84. if (isset($arr['ispass'])) {
  85. $where[] = ['ispass', '=', $arr['ispass']];
  86. }
  87. if (isset($arr['companyname'])) {
  88. $where[] = ['companyname', 'like', '%' . $arr['companyname'] . '%'];
  89. }
  90. if (isset($arr['createdate'])) {
  91. $createdate = $arr['createdate'];
  92. if (count($createdate) == count(array_filter($createdate))) {
  93. $where[] = ['create_time', '>=', $createdate[0]];
  94. $where[] = ['create_time', '<=', $createdate[1]];
  95. }
  96. }
  97. $m_c = new companymodel();
  98. $count = $m_c->getList($where, 'count');
  99. if ($count <= 0) {
  100. return backarr(0, "无数据");
  101. }
  102. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  103. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  104. $list = $m_c->getList($where, '*', $page, $size);
  105. $data = [
  106. 'list' => $list,
  107. 'total' => $count,
  108. ];
  109. return backarr(1, "查询成功", $data);
  110. }
  111. /**
  112. * 根据id获取企业信息
  113. * 20220209
  114. * wj
  115. */
  116. public function getinfobyid($arr)
  117. {
  118. $arr = $this->filterarray($arr);
  119. $result = $this->checkparam(__FUNCTION__, $arr);
  120. if (1 != $result['status']) {
  121. return $result;
  122. }
  123. $where = [];
  124. $id = $arr['id'];
  125. $where['id'] = $id;
  126. $m_c = new companymodel();
  127. $info = $m_c->getInfo($where);
  128. if (empty($info)) {
  129. return backarr(0, "无数据");
  130. }
  131. $info = $this->formatinfo($info);
  132. return backarr(1, "success", $info);
  133. }
  134. /**
  135. * 格式化企业信息
  136. * 20220209
  137. * wj
  138. */
  139. private function formatinfo($info)
  140. {
  141. if (isset($info['enterprisephoto']) && is_string($info['enterprisephoto'])) {
  142. if (!empty($info['enterprisephoto'])) {
  143. $jsonArr = json_decode($info['enterprisephoto'], true);
  144. /*$pregstr = '/^(http:\/\/*)|(https:\/\/*)/';
  145. foreach ($jsonArr as $key => $value) {
  146. $matchResult = preg_match($pregstr, $value, $matchArr);
  147. if ($matchResult) {
  148. foreach ($matchArr as $mkey => $mvalue) {
  149. $jsonArr[$key] = str_replace($mvalue, "", $value);
  150. }
  151. }
  152. }*/
  153. $info['enterprisephoto'] = $jsonArr;
  154. }
  155. }
  156. return $info;
  157. }
  158. }