MDriver.Class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: kang
  5. * Date: 2021/4/14
  6. * Time: 9:36
  7. */
  8. namespace JinDouYun\Model\System;
  9. use JinDouYun\Dao\System\DDriver;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use Mall\Framework\Core\ResultWrapper;
  13. use JinDouYun\Model\MBaseModel;
  14. class MDriver extends MBaseModel
  15. {
  16. private $objDDriver;
  17. private $enterpriseId;
  18. private $userCenterId;
  19. public function __construct($enterpriseId, $userCenterId)
  20. {
  21. $this->enterpriseId = $enterpriseId;
  22. $this->userCenterId = $userCenterId;
  23. parent::__construct($this->enterpriseId, $this->userCenterId);
  24. $this->objDDriver = new DDriver('default');
  25. }
  26. /**
  27. * 添加司机信息
  28. * @param $params
  29. * @return ResultWrapper
  30. * @throws Exception
  31. */
  32. public function addDriver($params)
  33. {
  34. $dbResult = $this->objDDriver->get(['phone' => $params['phone']]);
  35. if($dbResult === false){
  36. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  37. }
  38. if(!empty($dbResult)){
  39. return ResultWrapper::fail('该司机号码已存在', ErrorCode::$paramError);
  40. }
  41. unset($dbResult);
  42. $dbResult = $this->objDDriver->insert($params);
  43. if($dbResult === false){
  44. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  45. }
  46. return ResultWrapper::success($dbResult);
  47. }
  48. /**
  49. * 获取指定司机信息
  50. */
  51. public function getDriverInfo($driverId)
  52. {
  53. if(isset($driverId) && !empty($driverId)){
  54. $where = [
  55. 'id'=> $driverId,
  56. 'deleteStatus'=> StatusCode::$standard
  57. ];
  58. }
  59. $dbResult = $this->objDDriver->get($where);
  60. if($dbResult === false){
  61. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  62. }
  63. return ResultWrapper::success($dbResult);
  64. }
  65. /**
  66. * 编辑司机信息
  67. *
  68. * @return ResultWrapper
  69. */
  70. public function editDriver($params)
  71. {
  72. if( empty($params['id']) ){
  73. return ResultWrapper::fail('没有指定要修改的司机信息', ErrorCode::$paramError);
  74. }
  75. $driverId = $params['id'];
  76. unset($params['id']);
  77. $dbResult = $this->objDDriver->update($params, $driverId);
  78. if($dbResult === false){
  79. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  80. }else{
  81. return ResultWrapper::success($dbResult);
  82. }
  83. }
  84. /**
  85. * 删除司机信息
  86. *
  87. * @return ResultWrapper
  88. */
  89. public function delDriver($driverId)
  90. {
  91. $updateData = [
  92. 'deleteStatus' => StatusCode::$delete,
  93. ];
  94. $dbResult = $this->objDDriver->update($updateData, 'id ='.$driverId. ' and enterpriseId ='.$this->enterpriseId);
  95. if($dbResult === false){
  96. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  97. }else{
  98. return ResultWrapper::success($dbResult);
  99. }
  100. }
  101. /**
  102. * 获取后台所有司机信息列表
  103. * @param array $selectParams 过滤条件
  104. * @return ResultWrapper
  105. */
  106. public function getAllDriver($selectParams)
  107. {
  108. $limit = $selectParams['limit'];
  109. unset($selectParams['limit']);
  110. $offset = $selectParams['offset'];
  111. unset($selectParams['offset']);
  112. $selectParams['deleteStatus'] = StatusCode::$standard;
  113. $selectParams['enterpriseId'] = $this->enterpriseId;
  114. $dbResult = $this->objDDriver->select($selectParams, '*', 'createTime desc',$limit,$offset);
  115. if($dbResult === false){
  116. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  117. }
  118. $total = $this->objDDriver->count($selectParams);
  119. $return = [
  120. 'data' => $dbResult,
  121. 'total' => ($total)?intval($total):0,
  122. ];
  123. return ResultWrapper::success($return);
  124. }
  125. /**
  126. * 启用司机(不分页)
  127. * @return ResultWrapper
  128. */
  129. public function getAllOpenDriver()
  130. {
  131. $selectParams['deleteStatus'] = StatusCode::$standard;
  132. $selectParams['state'] = StatusCode::$standard;
  133. $selectParams['enterpriseId'] = $this->enterpriseId;
  134. $dbResult = $this->objDDriver->select($selectParams, '*', 'createTime desc');
  135. if($dbResult === false){
  136. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  137. }
  138. return ResultWrapper::success($dbResult);
  139. }
  140. /**
  141. * 获取司机数据
  142. * @param array $where
  143. * @param string $fields
  144. * @param false $isOne
  145. * @return ResultWrapper
  146. */
  147. public function getDriverData($where = [], $fields = '*', $isOne = false)
  148. {
  149. $where['enterpriseId'] = $this->enterpriseId;
  150. $where['deleteStatus'] = StatusCode::$standard;
  151. if($isOne){
  152. $dbResult = $this->objDDriver->get($where, $fields);
  153. }else{
  154. $dbResult = $this->objDDriver->select($where, $fields);
  155. }
  156. if($dbResult === false){
  157. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  158. }
  159. return ResultWrapper::success($dbResult);
  160. }
  161. /**
  162. * 修改司机数据
  163. * @param $update
  164. * @param $where
  165. * @return ResultWrapper
  166. */
  167. public function updateDriverData($update, $where)
  168. {
  169. $where['enterpriseId'] = $this->enterpriseId;
  170. $dbResult = $this->objDDriver->update($update, $where);
  171. if($dbResult === false){
  172. return ResultWrapper::fail($this->objDDriver->error(), ErrorCode::$dberror);
  173. }
  174. return ResultWrapper::success($dbResult);
  175. }
  176. }