MStaffStock.Class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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\Department;
  10. use Exception;
  11. use JinDouYun\Dao\Department\DStaffStock;
  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 MStaffStock extends MBaseModel
  18. {
  19. private $obj;
  20. private $cutTable = 250000;
  21. private $enterpriseId;
  22. private $userCenterId;
  23. private $DCardBind;
  24. private $DCard;
  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 DStaffStock('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. $wherein = [];
  44. if (isset($where['name'])){
  45. $wherein[] = ['b.staffName|b.id', '=', $where['name']];
  46. }
  47. if (isset($where['pm'])){
  48. $wherein[] = ['a.pm', '=', $where['pm']];
  49. }
  50. if (isset($where['staff_id'])){
  51. $wherein[] = ['a.staff_id', '=', $where['staff_id']];
  52. }
  53. if (isset($where['start_time']))
  54. {
  55. $wherein[] = ['a.createTime', '>=', strtotime($where['start_time'])];
  56. }
  57. if (isset($where['end_time']))
  58. {
  59. $wherein[] = ['a.createTime', '<=', strtotime($where['end_time'])];
  60. }
  61. $join = 'Left Join qianniao_staff_'.$this->enterpriseId.' as b ON b.id = a.staff_id';
  62. $dbResult = $this->obj->select($wherein, 'a.*,b.staffName', 'a.id DESC', $limit, $offset, [], true, false, $join);
  63. $count = $this->obj->count($wherein, [], $join);
  64. $return = [
  65. 'data' => $dbResult == false ? [] : $dbResult,
  66. 'total' => $count,
  67. ];
  68. return ResultWrapper::success($return);
  69. }
  70. /**
  71. * 详情
  72. * @param $where
  73. * @return mixed
  74. */
  75. public function details($where)
  76. {
  77. if(empty($where)){
  78. return ResultWrapper::success($where);
  79. }
  80. $dbResult = $this->obj->get($where);
  81. if($dbResult === false){
  82. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  83. }
  84. return ResultWrapper::success(self::formatInfo($dbResult));
  85. }
  86. /**
  87. * Doc: (des="添加")
  88. * User: XMing
  89. * Date: 2020/7/15
  90. * Time: 10:42 上午
  91. * @throws Exception
  92. * @param array $params
  93. * @return ResultWrapper
  94. */
  95. public function insert(array $params)
  96. {
  97. $res = $this->obj->insert($params);
  98. if ($res){
  99. return ResultWrapper::success('添加成功');
  100. }else{
  101. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  102. }
  103. }
  104. public function update($params, $id)
  105. {
  106. $data = $this->obj->get($id);
  107. if (!$data){
  108. return ResultWrapper::fail('数据不存在', ErrorCode::$dberror);
  109. }
  110. $dbResult = $this->obj->update($params,$id);
  111. if($dbResult === false){
  112. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  113. }
  114. return ResultWrapper::success('修改成功');
  115. }
  116. /**
  117. * 格式数据详情
  118. * @param $data
  119. * @return mixed
  120. */
  121. public function formatInfo($data)
  122. {
  123. return $data;
  124. }
  125. public function delete($where)
  126. {
  127. $res = $this->obj->delete($where);
  128. if ($res){
  129. return ResultWrapper::success('删除成功');
  130. }
  131. return ResultWrapper::fail($this->obj->error(), ErrorCode::$dberror);
  132. }
  133. }