workerlogic.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * @Author: wang jun
  4. * @Date: 2021-09-27 09:02:06
  5. * @Last Modified by: wang jun
  6. * @Last Modified time: 2021-09-27 11:15:36
  7. */
  8. namespace app\index\logic;
  9. use app\index\model\userinfomodel;
  10. use app\index\model\workermodel;
  11. class workerlogic
  12. {
  13. private $workermodel;
  14. public function __construct()
  15. {
  16. $this->workermodel = new workermodel();
  17. $this->userinfomodel = new userinfomodel();
  18. }
  19. public function getinfobyid($id)
  20. {
  21. $where = ['id' => $id];
  22. $info = $this->workermodel->getInfo($where);
  23. return $info;
  24. }
  25. public function getinfobyuserid($userid)
  26. {
  27. $where = ['userid' => $userid];
  28. $info = $this->workermodel->getInfo($where);
  29. return $info;
  30. }
  31. public function insertinfo($info)
  32. {
  33. $userid = $info['userid'];
  34. if (empty($userid)) {
  35. return backjson(0, "请求数据错误");
  36. }
  37. $userinfo = $this->userinfomodel->getInfo(['id' => $userid], 'id');
  38. if (!$userinfo) {
  39. return backArr(0, "无用户信息");
  40. }
  41. $workinfo = $this->getinfobyuserid($userid);
  42. if ($workinfo) {
  43. return backArr(0, "用户信息已存在");
  44. }
  45. $id = $this->workermodel->insertData($info);
  46. if (!$id) {
  47. return backArr(0, "添加失败");
  48. }
  49. return backArr(1, "添加成功", ['id' => $id]);
  50. }
  51. public function updateinfobyid($id, $updateData)
  52. {
  53. $where = ['id' => $id];
  54. $result = $this->workermodel->updateinfo($where, $updateData);
  55. return $result;
  56. }
  57. public function updateinfobyuserid($userid, $updateData)
  58. {
  59. $where = ['userid' => $userid];
  60. $result = $this->workermodel->updateinfo($where, $updateData);
  61. return $result;
  62. }
  63. }