inventlogic.php 4.8 KB

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