Driver.Class.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: kang
  5. * Date: 2021/4/14
  6. * Time: 9:38
  7. */
  8. namespace JinDouYun\Controller\System;
  9. use Mall\Framework\Core\ErrorCode;
  10. use Mall\Framework\Core\StatusCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\System\MDriver;
  13. class Driver extends BaseController
  14. {
  15. private $objMDriver;
  16. public function __construct($isCheckAcl = true, $isMustLogin = true)
  17. {
  18. parent::__construct($isCheckAcl, $isMustLogin);
  19. $this->objMDriver = new MDriver($this->onlineEnterpriseId,$this->onlineUserId);
  20. }
  21. /**
  22. * 添加和编辑司机信息管理公共字段处理方法
  23. *
  24. * @return array
  25. */
  26. public function commonFieldFilter()
  27. {
  28. $params = $this->request->getRawJson();
  29. if( empty($params) ){
  30. $this->sendOutput('参数为空', ErrorCode::$paramError );
  31. }
  32. $DriverData = [
  33. 'enterpriseId'=> $this->onlineEnterpriseId,
  34. 'driverName' => getArrayItem($params,'driverName'),
  35. 'phone' => getArrayItem($params,'phone'),
  36. 'plateNumber' => getArrayItem($params,'plateNumber'),
  37. 'state' => getArrayItem($params,'state',StatusCode::$standard),
  38. ];
  39. foreach($DriverData as $key => $value){
  40. if(empty($value) && $value !== 0){
  41. $this->sendOutput($key.'参数错误', ErrorCode::$paramError );
  42. }
  43. }
  44. $DriverData['remark'] = getArrayItem($params,'remark');
  45. return $DriverData;
  46. }
  47. /**
  48. * 添加司机信息
  49. */
  50. public function addDriver()
  51. {
  52. $DriverData = $this->commonFieldFilter();
  53. $result = $this->objMDriver->addDriver($DriverData);
  54. if($result->isSuccess()){
  55. parent::sendOutput($result->getData());
  56. }else{
  57. parent::sendOutput($result->getData(), $result->getErrorCode());
  58. }
  59. }
  60. /**
  61. * 获取指定司机信息
  62. */
  63. public function getDriverInfo()
  64. {
  65. $driverId = $this->request->param('request_id');
  66. if ( !$driverId ) {
  67. $this->sendOutput('参数错误', ErrorCode::$paramError );
  68. }
  69. $result = $this->objMDriver->getDriverInfo($driverId);
  70. if($result->isSuccess()){
  71. $this->sendOutput($result->getData());
  72. }else{
  73. $this->sendOutput($result->getData(), $result->getErrorCode());
  74. }
  75. }
  76. /**
  77. * 编辑司机资料
  78. */
  79. public function editDriver()
  80. {
  81. $params = $this->request->getRawJson();
  82. if(empty($params)){
  83. $this->sendOutput('参数错误', ErrorCode::$paramError);
  84. }
  85. $result = $this->objMDriver->editDriver($params);
  86. if($result->isSuccess()){
  87. parent::sendOutput($result->getData());
  88. }else{
  89. parent::sendOutput($result->getData(), $result->getErrorCode());
  90. }
  91. }
  92. /**
  93. * 删除司机信息
  94. */
  95. public function delDriver()
  96. {
  97. $driverId = $this->request->param('request_id');
  98. if ( !$driverId ) {
  99. $this->sendOutput('参数错误', ErrorCode::$paramError );
  100. }
  101. $result = $this->objMDriver->delDriver($driverId);
  102. if($result->isSuccess()){
  103. parent::sendOutput($result->getData());
  104. }else{
  105. parent::sendOutput($result->getData(), $result->getErrorCode());
  106. }
  107. }
  108. /**
  109. * 后台所有司机信息列表
  110. */
  111. public function getAllDriver()
  112. {
  113. $params = $this->request->getRawJson();
  114. if (empty($params)) {
  115. $this->sendOutput('参数为空', ErrorCode::$paramError);
  116. }
  117. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  118. $selectParams['limit'] = $pageParams['limit'];
  119. $selectParams['offset'] = $pageParams['offset'];
  120. if(isset($params['state']) && !empty($params['state'])){
  121. $selectParams['state'] = $params['state'];
  122. }
  123. $result = $this->objMDriver->getAllDriver($selectParams);
  124. if($result->isSuccess()){
  125. $returnData = $result->getData();
  126. $pageData = [
  127. 'pageIndex' => $params['page'],
  128. 'pageSize' => $params['pageSize'],
  129. 'pageTotal' => $returnData['total'],
  130. ];
  131. parent::sendOutput($returnData['data'], 0, $pageData);
  132. }else{
  133. parent::sendOutput($result->getData(), $result->getErrorCode());
  134. }
  135. }
  136. /**
  137. * 后台所有启用司机信息列表
  138. */
  139. public function getAllOpenDriver()
  140. {
  141. $result = $this->objMDriver->getAllOpenDriver();
  142. if($result->isSuccess()){
  143. parent::sendOutput($result->getData(), 0);
  144. }else{
  145. parent::sendOutput($result->getData(), $result->getErrorCode());
  146. }
  147. }
  148. }