companylogic.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. */
  9. namespace app\index\logic;
  10. use app\index\model\companymodel;
  11. use app\index\model\inventmodel;
  12. use app\index\model\usermodel;
  13. class companylogic extends baselogic
  14. {
  15. /**
  16. * 设置请求数据规则
  17. * 20220107
  18. * wj
  19. */
  20. protected function setrules()
  21. {
  22. $list = [
  23. 'newinfo' => [
  24. ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
  25. ['name' => 'organization_code', 'title' => 'organization_code', 'type' => 'string'],
  26. ['name' => 'companyname', 'title' => 'companyname', 'type' => 'string'],
  27. ],
  28. 'getinfobyid' => [
  29. ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'numeric'],
  30. ],
  31. 'updatebyid' => [
  32. ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'numeric'],
  33. ],
  34. 'getinfowitchinventbyid' => [
  35. ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'numeric'],
  36. ['name' => 'activestate', 'title' => 'activestate', 'regex' => '/[0|1|2]{1}/'],
  37. ],
  38. ];
  39. return $list;
  40. }
  41. /**
  42. * 新建信息
  43. * wj
  44. * 20220118
  45. */
  46. public function newinfo($arr)
  47. {
  48. $result = $this->checkparam(__FUNCTION__, $arr);
  49. if (1 != $result['status']) {
  50. return $result;
  51. }
  52. $m_u = new usermodel();
  53. $m_c = new companymodel();
  54. $openid = $arr['openid'];
  55. $info = $m_u->getinfobyopenid($openid);
  56. if (empty($info)) {
  57. return backarr(0, "用户不存在");
  58. }
  59. if (empty($info['is_company'])) {
  60. return backarr(0, "非企业用户");
  61. }
  62. unset($arr['openid']);
  63. $where = [];
  64. $cinfo = [];
  65. if (isset($arr['organization_code'])) {
  66. $where['organization_code'] = $arr['organization_code'];
  67. }
  68. if (isset($arr['companyname'])) {
  69. $where['companyname'] = $arr['companyname'];
  70. }
  71. if (empty(!$where)) {
  72. $cinfo = $m_c->getinfo($where, ['id']);
  73. }
  74. if (empty($cinfo)) {
  75. $id = $m_c->insertData($arr);
  76. } else {
  77. $id = $cinfo['id'];
  78. }
  79. $updateDate = ['company_id' => $id];
  80. $row = $m_u->updatebyid($info['id'], $updateDate);
  81. return backarr(1, "新增成功", ['id' => $id]);
  82. }
  83. /**
  84. * 根据id获取企业信息
  85. * wj
  86. * 20220118
  87. */
  88. public function getinfobyid($arr)
  89. {
  90. $result = $this->checkparam(__FUNCTION__, $arr);
  91. if (1 != $result['status']) {
  92. return $result;
  93. }
  94. $id = $arr['id'];
  95. $m_c = new companymodel();
  96. $info = $m_c->getinfobyid($id);
  97. if (empty($info)) {
  98. return backarr(0, "无数据");
  99. }
  100. return backarr(1, "获取成功", $info);
  101. }
  102. /**
  103. * 根据id获取企业信息包括岗位
  104. * wj
  105. * 20220119
  106. */
  107. public function getinfowitchinventbyid($arr)
  108. {
  109. $result = $this->checkparam(__FUNCTION__, $arr);
  110. if (1 != $result['status']) {
  111. return $result;
  112. }
  113. $id = $arr['id'];
  114. $m_c = new companymodel();
  115. $info = $m_c->getinfobyid($id);
  116. if (empty($info)) {
  117. return backarr(0, "无数据");
  118. }
  119. $info = $this->formatinfo($info);
  120. var_dump($info);exit;
  121. $m_i = new inventmodel();
  122. $where = ['company_id' => $info['id']];
  123. if (isset($arr['activestate'])) {
  124. $where['active_state'] = $arr['activestate'];
  125. }
  126. $ilist = $m_i->getlist($where, "*", 1, 0);
  127. $info['invent_list'] = $ilist;
  128. return backarr(1, "获取成功", $info);
  129. }
  130. /**
  131. * 根据id修改企业信息
  132. * wj
  133. * 20220118
  134. */
  135. public function updatebyid($arr)
  136. {
  137. $result = $this->checkparam(__FUNCTION__, $arr);
  138. if (1 != $result['status']) {
  139. return $result;
  140. }
  141. $id = $arr['id'];
  142. unset($arr['id']);
  143. $m_c = new companymodel();
  144. $row = $m_c->updatebyid($id, $arr);
  145. if (empty($row)) {
  146. return backarr(0, "修改失败");
  147. }
  148. return backarr(1, "获取成功", ['id' => $id]);
  149. }
  150. /**
  151. * 获取本次活动全部公司总数
  152. * 20220122
  153. * wj
  154. */
  155. public function getcountbyparty($arr)
  156. {
  157. $result = $this->checkparam(__FUNCTION__, $arr);
  158. if (1 != $result['status']) {
  159. return $result;
  160. }
  161. $partyid = $arr['partyid'];
  162. $m_c = new companymodel();
  163. $count = $m_c->getcountbyparty($partyid);
  164. return backarr(1, "获取成功", $count);
  165. }
  166. /**
  167. * 格式化 公司信息 仅小程序使用
  168. */
  169. private function formatinfo($info)
  170. {
  171. if (isset($info['enterprisephoto']) && is_string($info['enterprisephoto'])) {
  172. if (!empty($info['enterprisephoto'])) {
  173. $jsonArr = json_decode($info['enterprisephoto'], true);
  174. $pregstr = '/^(http:\/\/*)|(https:\/\/*)/';
  175. foreach ($jsonArr as $key => $value) {
  176. $matchResult = preg_match($pregstr, $value, $matchArr);
  177. if ($matchResult) {
  178. foreach ($matchArr as $mkey => $mvalue) {
  179. $jsonArr[$key] = str_replace($mvalue, "", $value);
  180. }
  181. }
  182. }
  183. $info['enterprisephoto'] = $jsonArr;
  184. }
  185. }
  186. return $info;
  187. }
  188. }