MPersonnel.Class.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * 商铺管理模块
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/10/31
  7. * Time: 15:02
  8. */
  9. namespace JinDouYun\Model\Enterprise;
  10. use Exception;
  11. use JinDouYun\Dao\Enterprise\DPersonnel;
  12. use Mall\Framework\Core\ErrorCode;
  13. use Mall\Framework\Core\StatusCode;
  14. use Mall\Framework\Core\ResultWrapper;
  15. use JinDouYun\Model\MBaseModel;
  16. use Monolog\Handler\IFTTTHandler;
  17. class MPersonnel extends MBaseModel
  18. {
  19. private $obj;
  20. private $cutTable = 250000;
  21. private $enterpriseId;
  22. private $userCenterId;
  23. private $objMShopPartner;
  24. private $objMStaff;
  25. public function __construct($enterpriseId, $userCenterId = '')
  26. {
  27. $this->enterpriseId = $enterpriseId;
  28. $this->userCenterId = $userCenterId;
  29. parent::__construct($this->enterpriseId, $this->userCenterId);
  30. $this->obj = new DPersonnel('default');
  31. }
  32. /**
  33. * 列表
  34. * @param $where
  35. * @return mixed
  36. */
  37. public function list($where)
  38. {
  39. $limit = $where['limit'];
  40. unset($where['limit']);
  41. $offset = $where['offset'];
  42. unset($where['offset']);
  43. $dbResult = $this->obj->select($where, '*', 'id DESC', $limit, $offset);
  44. $count = $this->obj->count($where);
  45. if ($dbResult === false) {
  46. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  47. }
  48. $return = [
  49. 'data' => $dbResult,
  50. 'total' => $count,
  51. ];
  52. if($return === false){
  53. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  54. }else{
  55. return ResultWrapper::success($return);
  56. }
  57. }
  58. /**
  59. * 详情
  60. * @param $where
  61. * @return mixed
  62. */
  63. public function details($where)
  64. {
  65. if(empty($where)){
  66. return ResultWrapper::success($where);
  67. }
  68. $dbResult = $this->obj->get($where);
  69. if($dbResult === false){
  70. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  71. }
  72. return ResultWrapper::success(self::formatInfo($dbResult));
  73. }
  74. /**
  75. * Doc: (des="添加")
  76. * User: XMing
  77. * Date: 2020/7/15
  78. * Time: 10:42 上午
  79. * @throws Exception
  80. * @param array $params
  81. * @return ResultWrapper
  82. */
  83. public function insert(array $params)
  84. {
  85. $res = $this->obj->insert($params);
  86. if ($res){
  87. return ResultWrapper::success('添加成功');
  88. }else{
  89. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  90. }
  91. }
  92. public function update($params, $id)
  93. {
  94. $data = $this->obj->get($id);
  95. if (!$data){
  96. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  97. }
  98. $dbResult = $this->obj->update($params,$id);
  99. if($dbResult === false){
  100. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  101. }
  102. return ResultWrapper::success('修改成功');
  103. }
  104. /**
  105. * 格式数据详情
  106. * @param $data
  107. * @return mixed
  108. */
  109. public function formatInfo($data)
  110. {
  111. return $data;
  112. }
  113. public function delete($where)
  114. {
  115. $res = $this->obj->delete($where);
  116. if ($res){
  117. return ResultWrapper::success('删除成功');
  118. }
  119. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  120. }
  121. }