inventlogic.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 16:07:27
  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 inventlogic extends baselogic
  14. {
  15. /**
  16. * 设置请求数据规则
  17. * 20220107
  18. * wj
  19. */
  20. protected function setrules()
  21. {
  22. $list = [
  23. 'newinfo' => [
  24. ['name' => 'companyid', 'title' => 'companyid', 'require' => true, 'type' => 'numeric'],
  25. ['name' => 'openid', 'title' => 'openid', 'type' => 'string'],
  26. ],
  27. 'getlistbywhere' => [
  28. ['name' => 'companyid', 'title' => 'companyid', 'require' => true, 'type' => 'numeric'],
  29. ['name' => 'passstate', 'title' => 'passstate', 'type' => 'numeric', 'regex' => '/[0|1|2]{1}/'],
  30. ['name' => 'activestate', 'title' => 'activestate', 'type' => 'numeric', 'regex' => '/[0|1]{1}/'],
  31. ['name' => 'title', 'title' => 'title', 'type' => 'string', 'regex' => '/*{5,}/'],
  32. ],
  33. 'updatebyid' => [
  34. ['name' => 'id', 'title' => 'companyid', 'require' => true, 'type' => 'numeric'],
  35. ],
  36. 'getinfobyid' => [
  37. ['name' => 'id', 'title' => 'companyid', 'require' => true, 'type' => 'numeric'],
  38. ],
  39. ];
  40. return $list;
  41. }
  42. /**
  43. * 新建数据
  44. * 20220119
  45. * wj
  46. */
  47. public function newinfo($arr)
  48. {
  49. $result = $this->checkparam(__FUNCTION__, $arr);
  50. if (1 != $result['status']) {
  51. return $result;
  52. }
  53. $companyid = $arr['companyid'];
  54. $m_c = new companymodel();
  55. $cinfo = $m_c->getinfobyid($companyid);
  56. if (empty($cinfo)) {
  57. return backarr(0, "企业信息不存在");
  58. }
  59. $openid = $arr['openid'];
  60. $m_u = new usermodel();
  61. $uinfo = $m_u->getinfobyopenid($openid);
  62. if (empty($uinfo)) {
  63. return backarr(0, "用户信息不存在");
  64. }
  65. $m_i = new inventmodel();
  66. $arr['company_id'] = $companyid;
  67. $arr['create_user_id'] = $uinfo['id'];
  68. $id = $m_i->insertData($arr);
  69. if (empty($id)) {
  70. return backarr(0, "新增失败");
  71. }
  72. return backarr(1, "新增成功", ['id' => $id]);
  73. }
  74. /**
  75. * 获取列表数据 根据条件
  76. * 20220119
  77. * wj
  78. */
  79. public function getlistbywhere($arr)
  80. {
  81. $result = $this->checkparam(__FUNCTION__, $arr);
  82. if (1 != $result['status']) {
  83. return $result;
  84. }
  85. $companyid = $arr['companyid'];
  86. $m_c = new companymodel();
  87. $cinfo = $m_c->getinfobyid($companyid);
  88. if (empty($cinfo)) {
  89. return backarr(0, "企业信息不存在");
  90. }
  91. $m_i = new inventmodel();
  92. $where = ['company_id' => $companyid];
  93. if (isset($arr['title'])) {
  94. $where['title'] = ['like' => '%' . $arr['title'] . '%'];
  95. }
  96. if (isset($arr['activestate'])) {
  97. $where['active_state'] = $arr['passstate'];
  98. }
  99. if (isset($arr['passstate'])) {
  100. $where['pass_state'] = $arr['passstate'];
  101. }
  102. $page = isset($arr['page']) && !empty($arr['page']) ? $arr['page'] : 1;
  103. $size = isset($arr['size']) && !empty($arr['size']) ? $arr['size'] : 10;
  104. $count = $m_i->getList($where, 'count');
  105. if ($count <= 0) {
  106. return backarr(0, "无数据");
  107. }
  108. $list = $m_i->getList($where, '*', $page, $size);
  109. return backarr(1, "查询成功", $list);
  110. }
  111. /**
  112. * 修改数据根据id
  113. * 20220119
  114. * wj
  115. */
  116. public function updatebyid($arr)
  117. {
  118. $result = $this->checkparam(__FUNCTION__, $arr);
  119. if (1 != $result['status']) {
  120. return $result;
  121. }
  122. $id = $arr['id'];
  123. $m_i = new inventmodel();
  124. $row = $m_i->updatebyid($id, $arr);
  125. if (empty($row)) {
  126. return backarr(0, "修改失败");
  127. }
  128. return backarr(1, "获取成功", ['id' => $id]);
  129. }
  130. /**
  131. * 获取数据根据id
  132. * 20220119
  133. * wj
  134. */
  135. public function getinfobyid($arr)
  136. {
  137. $result = $this->checkparam(__FUNCTION__, $arr);
  138. if (1 != $result['status']) {
  139. return $result;
  140. }
  141. $id = $arr['id'];
  142. $m_i = new inventmodel();
  143. $iinfo = $m_i->getinfobyid($id);
  144. if (empty($iinfo)) {
  145. return backarr(0, "数据不存在");
  146. }
  147. return backarr(1, "获取成功", $iinfo);
  148. }
  149. }