DistributionCentre.Class.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: kang
  5. * Date: 2021/5/26
  6. * Time: 10:28
  7. */
  8. namespace JinDouYun\Controller\Delivery;
  9. use JinDouYun\Model\Delivery\MDelivery;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Delivery\MDistributionCentre;
  14. class DistributionCentre extends BaseController
  15. {
  16. private $objMDistributionCentre;
  17. public function __construct($isCheckAcl = true, $isMustLogin = true)
  18. {
  19. parent::__construct($isCheckAcl, $isMustLogin);
  20. $this->objMDistributionCentre = new MDistributionCentre($this->onlineEnterpriseId, $this->onlineUserId);
  21. }
  22. /**
  23. * 待司机配送获取参数
  24. *
  25. * @return array
  26. */
  27. public function commonFieldFilter()
  28. {
  29. $params = $this->request->getRawJson();
  30. if (empty($params)) {
  31. $this->sendOutput('参数为空', ErrorCode::$paramError);
  32. }
  33. $returnData = [
  34. 'enterpriseId' => $this->onlineEnterpriseId,
  35. 'documentDate' => getArrayItem($params,'documentDate'), // 单据日期
  36. 'documentNo' => getArrayItem($params,'documentNo'), // 单据编号
  37. 'sourceNo' => getArrayItem($params,'sourceNo'), // 来源编号
  38. 'documentType' => getArrayItem($params,'documentType'), // 单据类型
  39. 'customerId' => getArrayItem($params,'customerId'), // 客户id
  40. 'customerName' => getArrayItem($params,'customerName'), // 客户名称
  41. 'warehouseId' => getArrayItem($params,'warehouseId'), // 仓库id
  42. 'deliveryWarehouse'=> getArrayItem($params,'deliveryWarehouse'), // 发货仓库
  43. 'manager' => getArrayItem($params,'manager'), // 经手人
  44. 'producer' => getArrayItem($params,'producer'), // 制单人
  45. 'receiver' => getArrayItem($params,'receiver'), // 收货人
  46. 'mobile' => getArrayItem($params,'mobile'), // 联系人电话
  47. 'modeOfProduction' => getArrayItem($params,'modeOfProduction'), // 产生方式
  48. 'driverId' => getArrayItem($params,'driverId'), // 司机id
  49. 'distributionDriver'=> getArrayItem($params,'distributionDriver'), // 配送司机
  50. ];
  51. //必填项
  52. foreach ($returnData as $key => $value) {
  53. if (empty($value) && $value !== 0) {
  54. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  55. }
  56. }
  57. //选填项
  58. $returnData['deliveryState'] = getArrayItem($params,'deliveryState'); // 配送状态
  59. $returnData['deliveryQuantity'] = getArrayItem($params,'deliveryQuantity'); // 发货数量
  60. $returnData['deliveryAmount'] = getArrayItem($params,'deliveryAmount'); // 发货金额
  61. $returnData['returnAmount'] = getArrayItem($params,'returnAmount'); // 退货金额
  62. $returnData['returnGoodsNum'] = getArrayItem($params,'returnGoodsNum',0); // 退货数量
  63. $returnData['containerLocation']= getArrayItem($params,'containerLocation'); // 集货位
  64. $returnData['binningNum'] = getArrayItem($params,'binningNum'); // 装箱数量
  65. $returnData['receivingAddress'] = getArrayItem($params,'packingNum'); // 收货地址
  66. $returnData['distributionRoute']= getArrayItem($params,'distributionRoute');// 配送线路
  67. $returnData['expectedDelivery'] = getArrayItem($params,'expectedDelivery'); // 预计发货
  68. $returnData['remarks'] = getArrayItem($params,'remarks'); // 备注
  69. $returnData['packingNum'] = getArrayItem($params,'packingNum'); // 包装数量
  70. $returnData['returnWarehouse'] = getArrayItem($params,'returnWarehouse'); // 退货仓库
  71. $receiveData['deleteStatus'] = StatusCode::$standard;
  72. $returnData['createTime'] = time();//创建时间
  73. return $returnData;
  74. }
  75. /**
  76. * 添加待配送单
  77. */
  78. public function addDistribution()
  79. {
  80. $distributionData = $this->commonFieldFilter();
  81. $result = $this->objMDistributionCentre ->addDistribution($distributionData);
  82. if($result->isSuccess()){
  83. parent::sendOutput($result->getData());
  84. }else{
  85. parent::sendOutput($result->getData(), $result->getErrorCode());
  86. }
  87. }
  88. /**
  89. * 待司机配送删除
  90. */
  91. public function delDistribution()
  92. {
  93. $distributionId = $this->request->param('request_id');
  94. if ( !$distributionId ) {
  95. $this->sendOutput('参数错误', ErrorCode::$paramError );
  96. }
  97. $result = $this->objMDistributionCentre->delDistribution($distributionId);
  98. if($result->isSuccess()){
  99. parent::sendOutput($result->getData());
  100. }else{
  101. parent::sendOutput($result->getData(), $result->getErrorCode());
  102. }
  103. }
  104. /**
  105. * 获取所有的待司机配送单
  106. */
  107. public function getAllDistribution()
  108. {
  109. $params = $this->request->getRawJson();
  110. if (empty($params)) {
  111. $this->sendOutput('参数为空', ErrorCode::$paramError);
  112. }
  113. $params['page'] = isset($params['page']) ? $params['page'] : 1;
  114. $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
  115. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  116. $selectParams['limit'] = $pageParams['limit'];
  117. $selectParams['offset'] = $pageParams['offset'];
  118. $returnData = $this->objMDistributionCentre->getAllDistribution($selectParams);
  119. if ($returnData->isSuccess()) {
  120. $returnData = $returnData->getData();
  121. $pageData = [
  122. 'pageIndex' => $params['page'],
  123. 'pageSize' => $params['pageSize'],
  124. 'pageTotal' => $returnData['total'],
  125. ];
  126. parent::sendOutput($returnData['data'], 0, $pageData);
  127. } else {
  128. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  129. }
  130. }
  131. /**
  132. * 添加配送任务
  133. */
  134. public function addTask()
  135. {
  136. $params = $this->request->getRawJson();
  137. if (empty($params)) {
  138. $this->sendOutput('参数为空', ErrorCode::$paramError);
  139. }
  140. $taskData = [
  141. 'enterpriseId' => $this->onlineEnterpriseId,
  142. 'deliveryDate' => getArrayItem($params,'deliveryDate'), // 单据日期
  143. 'driverId' => getArrayItem($params,'driverId'), // 司机id
  144. 'driverName' => getArrayItem($params,'driverName'), // 配送司机
  145. 'deliveryTaskData'=> getArrayItem($params,'deliveryTaskData',[]), // 配送任务主数据
  146. ];
  147. foreach ($taskData as $key => $value) {
  148. if (empty($value) && $value !== 0) {
  149. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  150. }
  151. }
  152. $taskData['TaskNo'] = getArrayItem($params,'TaskNo'); // 任务编号
  153. $taskData['deliveryStatus'] = getArrayItem($params,'deliveryStatus',1); // 配送状态
  154. $taskData['deliveryEndTime'] = getArrayItem($params,'deliveryEndTime'); // 结束配送时间
  155. $taskData['carId'] = getArrayItem($params,'carId'); // 配送车辆id
  156. $taskData['deliveryCar'] = getArrayItem($params,'deliveryCar'); // 配送车辆
  157. $taskData['deliveryBoy'] = getArrayItem($params,'deliveryBoy'); // 送货员
  158. $taskData['deliveryOrderNum'] = getArrayItem($params,'deliveryOrderNum'); // 配送单量
  159. $taskData['returnGoodsOrderNum'] = getArrayItem($params,'returnGoodsOrderNum'); // 退货数量
  160. $taskData['deliverGoodsQuantity'] = getArrayItem($params,'deliverGoodsQuantity'); // 发货数量
  161. $taskData['deliveryAmount'] = getArrayItem($params,'deliveryAmount'); // 发货金额
  162. $taskData['signedQuantity'] = getArrayItem($params,'signedQuantity'); // 签收数量
  163. $taskData['signedAmount'] = getArrayItem($params,'signedAmount'); // 签收金额
  164. $taskData['rejectionQuantity'] = getArrayItem($params,'rejectionQuantity'); // 拒收数量
  165. $taskData['rejectionAmount'] = getArrayItem($params,'rejectionAmount'); // 拒收金额
  166. $taskData['returnGoodsQuantity'] = getArrayItem($params,'returnGoodsQuantity'); // 退货数量
  167. $taskData['returnGoodsAmount'] = getArrayItem($params,'returnGoodsAmount'); // 退货金额
  168. $taskData['binningQuantity'] = getArrayItem($params,'binningQuantity'); //装箱数量
  169. $taskData['deliveryMileage'] = getArrayItem($params,'deliveryMileage'); //配送里程
  170. $taskData['remark'] = getArrayItem($params,'remark'); // 备注
  171. $taskData['deliveryStartTime'] = time(); // 开始配送时间
  172. $taskData['deleteStatus'] = StatusCode::$standard;
  173. $taskData['createTime'] = time();//创建时间
  174. $result = $this->objMDistributionCentre ->addTask($taskData);
  175. if($result->isSuccess()){
  176. parent::sendOutput($result->getData());
  177. }else{
  178. parent::sendOutput($result->getData(), $result->getErrorCode());
  179. }
  180. }
  181. /**
  182. * 配送任务完成配送
  183. */
  184. public function taskComplete()
  185. {
  186. $taskCompleteId = $this->request->param('request_id');
  187. if ( !$taskCompleteId ) {
  188. $this->sendOutput('参数错误', ErrorCode::$paramError );
  189. }
  190. $result = $this->objMDistributionCentre->taskComplete($taskCompleteId);
  191. if($result->isSuccess()){
  192. parent::sendOutput($result->getData());
  193. }else{
  194. parent::sendOutput($result->getData(), $result->getErrorCode());
  195. }
  196. }
  197. }