companylogic.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 10:28:59
  7. * 微信类
  8. */
  9. namespace app\index\logic;
  10. use app\index\model\companymodel;
  11. use app\index\model\usermodel;
  12. class companylogic extends baselogic
  13. {
  14. /**
  15. * 设置请求数据规则
  16. * 20220107
  17. * wj
  18. */
  19. protected function setrules()
  20. {
  21. $list = [
  22. 'newinfo' => [
  23. ['name' => 'openid', 'title' => 'openid', 'require' => true, 'type' => 'string'],
  24. ],
  25. 'getinfobyid' => [
  26. ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'string'],
  27. ],
  28. 'updatebyid' => [
  29. ['name' => 'id', 'title' => 'id', 'require' => true, 'type' => 'string'],
  30. ],
  31. ];
  32. return $list;
  33. }
  34. /**
  35. * 新建信息
  36. * wj
  37. * 20220118
  38. */
  39. public function newinfo($arr)
  40. {
  41. $result = $this->checkparam(__FUNCTION__, $arr);
  42. if (1 != $result['status']) {
  43. return $result;
  44. }
  45. $m_u = new usermodel();
  46. $m_c = new companymodel();
  47. $openid = $arr['openid'];
  48. $info = $m_u->getinfobyopenid($openid);
  49. if (empty($info)) {
  50. return backarr(0, "用户不存在");
  51. }
  52. if (empty($info['is_company'])) {
  53. return backarr(0, "非企业用户");
  54. }
  55. unset($arr['openid']);
  56. $id = $m_c->insertData($arr);
  57. $updateDate = ['company_id' => $id];
  58. $row = $m_u->updatebyid($info['id'], $updateDate);
  59. return backarr(1, "新增成功", ['id' => $id]);
  60. }
  61. /**
  62. * 根据id获取企业信息
  63. * wj
  64. * 20220118
  65. */
  66. public function getinfobyid($arr)
  67. {
  68. $result = $this->checkparam(__FUNCTION__, $arr);
  69. if (1 != $result['status']) {
  70. return $result;
  71. }
  72. $id = $arr['id'];
  73. $m_c = new companymodel();
  74. $info = $m_c->getinfobyid($id);
  75. if (empty($info)) {
  76. return backarr(0, "无数据");
  77. }
  78. return backarr(1, "获取成功", $info);
  79. }
  80. /**
  81. * 根据id修改企业信息
  82. * wj
  83. * 20220118
  84. */
  85. public function updatebyid($arr)
  86. {
  87. $result = $this->checkparam(__FUNCTION__, $arr);
  88. if (1 != $result['status']) {
  89. return $result;
  90. }
  91. $id = $arr['id'];
  92. unset($arr['id']);
  93. $m_c = new companymodel();
  94. $row = $m_c->updatebyid($id, $arr);
  95. if (empty($row)) {
  96. return backarr(0, "修改失败");
  97. }
  98. return backarr(1, "获取成功", ['id' => $id]);
  99. }
  100. }