Picking.Class.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Gss
  5. * Date: 2021/5/17 0017
  6. * Time: 17:38
  7. */
  8. namespace JinDouYun\Controller\Stock;
  9. use Mall\Framework\Core\ErrorCode;
  10. use Mall\Framework\Core\StatusCode;
  11. use JinDouYun\Controller\BaseController;
  12. use JinDouYun\Model\Stock\MPicking;
  13. class Picking extends BaseController
  14. {
  15. private $objPicking;
  16. private $loginUserCenterId;
  17. /**
  18. * PICKING constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @throws \Exception
  22. */
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->loginUserCenterId = $this->onlineUserId;//获取登录后台用户的id
  27. $userCenterId = $this->request->param('request_id');//客户对应的userCenterId
  28. $this->onlineUserId = empty($userCenterId) ? $this->onlineUserId : $userCenterId;//防止产生0后缀的表
  29. $this->objPicking = new MPicking($this->onlineUserId, $this->onlineEnterpriseId, $this->loginUserCenterId);
  30. }
  31. /**
  32. * 添加、编辑拣货单公告方法
  33. */
  34. public function commonFieldFilter()
  35. {
  36. $params = $this->request->getRawJson();
  37. if (empty($params)) {
  38. parent::sendOutput('参数为空', ErrorCode::$paramError);
  39. }
  40. //组装数据
  41. $pickingDate = [
  42. 'shopId' => isset($params['shopId']) ? $params['shopId'] : 0,
  43. 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',
  44. 'merchantId' => isset($params['merchantId']) ? $params['merchantId'] : 0,
  45. 'originId' => isset($params['originId']) ? $params['originId'] : 0,
  46. 'originNo' => isset($params['originNo']) ? $params['originNo'] : '',
  47. // 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : 0,
  48. // 'warehouseName' => isset($params['warehouseName']) ? $params['warehouseName'] : '',
  49. 'personnel' => isset($params['personnel']) ? $params['personnel'] : 0,
  50. 'personnelName' => isset($params['personnelName']) ? $params['personnelName'] : '',
  51. 'currentUnitId' => isset($params['currentUnitId']) ? $params['currentUnitId'] : 0,
  52. 'currentUnit' => isset($params['currentUnit']) ? $params['currentUnit'] : '',
  53. 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : '',
  54. 'managerId' => isset($params['managerId']) ? $params['managerId'] : 0,
  55. 'managerName' => isset($params['managerName']) ? $params['managerName'] : 0,
  56. 'goodsData' => getArrayItem($params,'goodsData', [])
  57. ];
  58. foreach ($pickingDate as $key => $value) {
  59. if (empty($value) && $value !== 0) {
  60. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  61. }
  62. }
  63. return $pickingDate;
  64. }
  65. /**
  66. * 新增拣货单
  67. */
  68. public function addPicking()
  69. {
  70. $params = $this->request->getRawJson();
  71. if (empty($params)) {
  72. parent::sendOutput('参数为空', ErrorCode::$paramError);
  73. }
  74. //组装数据
  75. $pickingDate = $this->commonFieldFilter();
  76. $pickingDate['sort'] = getArrayItem($params,'sort',0);
  77. $pickingDate['number'] = 0;// 数量
  78. $pickingDate['goodsLine'] = count($pickingDate['goodsData']); // 商品行数
  79. $pickingDate['totalMoney'] = 0; // 销售金额
  80. $pickingDate['notPickingNum'] = 0; // 未拣货数量
  81. $pickingDate['pickingNum'] = 0; // 拣货数量
  82. $pickingDate['InspectionNum'] = 0; // 拣货数量
  83. $pickingDate['InspectionedNum'] = 0; // 拣货数量
  84. $pickingDate['outNum'] = 0; // 发货数量
  85. $pickingDate['notOutNum'] = 0; // 未发货数量
  86. $pickingDate['outTime'] = 0; // 发货时间
  87. $pickingDate['address'] = getArrayItem($params,'address',''); // 地址
  88. $pickingDate['pickingStatus'] = 4; // 拣货状态
  89. $pickingDate['pickingType'] = 1; // 拣货类型
  90. //循环获取商品数量,销售金额
  91. foreach ($pickingDate['goodsData'] as $key =>$value ){
  92. $pickingDate['number'] = bcadd($pickingDate['number'],$value['orderNum']);
  93. $pickingDate['notPickingNum'] = bcadd($pickingDate['notPickingNum'],$value['orderNum']);
  94. $pickingDate['totalMoney'] = bcadd($pickingDate['totalMoney'],$value['totalMoney']);
  95. $pickingDate['notOutNum'] = bcadd($pickingDate['notOutNum'],$value['orderNum']);
  96. $pickingDate['InspectionNum'] = bcadd($pickingDate['InspectionNum'],$value['orderNum']);
  97. }
  98. $pickingDate['remark'] = isset($params['remark']) ? $params['remark'] : '';//订单备注
  99. $pickingDate['createTime'] = time(); //创建时间
  100. //组装商品数据
  101. $pickingDate['goodsData'] = self::formatGoodsDate($pickingDate,$pickingDate['goodsData']);
  102. $result = $this->objPicking->addPicking($pickingDate);
  103. if ($result->isSuccess()) {
  104. parent::sendOutput($result->getData());
  105. } else {
  106. parent::sendOutput($result->getData(), $result->getErrorCode());
  107. }
  108. }
  109. /**
  110. * 拣货单列表
  111. */
  112. public function getAllPicking()
  113. {
  114. $params = $this->request->getRawJson();
  115. if (empty($params)) {
  116. $this->sendOutput('参数为空', ErrorCode::$paramError);
  117. }
  118. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  119. $selectParams['limit'] = $pageParams['limit'];
  120. $selectParams['offset'] = $pageParams['offset'];
  121. $selectParams['no'] = getArrayItem($params,'no','');//编号
  122. $selectParams['warehouseId'] = getArrayItem($params,'warehouseId','');//仓库
  123. $selectParams['personnel'] = getArrayItem($params,'personnel',''); //拣货人
  124. $selectParams['originId'] = getArrayItem($params,'originId',''); //来源单据
  125. $selectParams['originNo'] = getArrayItem($params,'originNo',''); //来源单据
  126. $selectParams['currentUnitId'] = getArrayItem($params,'currentUnitId',''); //往来单位id
  127. $selectParams['managerId'] = getArrayItem($params,'managerId',''); //往来单位id
  128. $selectParams['timeName'] = getArrayItem($params,'timeName',''); //时间判断
  129. $selectParams['start'] = getArrayItem($params,'start',''); //开始时间
  130. $selectParams['end'] = getArrayItem($params,'end',''); //结束时间
  131. if( isset($selectParams['no']) || !empty($selectParams['no']) ){
  132. $tmpSelectParams['no'] = explode('-',$selectParams['no']);
  133. if(count($tmpSelectParams['no'])==3){
  134. $selectParams['no'] = $tmpSelectParams['no'][1].'-'.$tmpSelectParams['no'][2];
  135. }
  136. }
  137. if( isset($selectParams['originNo']) || !empty($selectParams['originNo']) ){
  138. $tmpSelectParams['originNo'] = explode('-',$selectParams['originNo']);
  139. if(count($tmpSelectParams['originNo'])==3){
  140. $selectParams['originNo'] = $tmpSelectParams['originNo'][1].'-'.$tmpSelectParams['originNo'][2];
  141. }
  142. }
  143. $result = $this->objPicking->getAllPicking($selectParams);
  144. if ($result->isSuccess()) {
  145. $returnData = $result->getData();
  146. $pageData = [
  147. 'pageIndex' => $params['page'],
  148. 'pageSize' => $params['pageSize'],
  149. 'pageTotal' => $returnData['total'],
  150. ];
  151. parent::sendOutput($returnData['data'], 0, $pageData);
  152. } else {
  153. parent::sendOutput($result->getData(), $result->getErrorCode());
  154. }
  155. }
  156. /**
  157. * @param $pickingDate
  158. * @param $goodsDate
  159. * @return mixed
  160. * 拣货单详情
  161. */
  162. public function getPickingInfo()
  163. {
  164. $pickingId = $this->request->param('request_id');
  165. if (!$pickingId) {
  166. $this->sendOutput('参数错误', ErrorCode::$paramError);
  167. }
  168. $result = $this->objPicking->getPickingInfo($pickingId);
  169. if ($result->isSuccess()) {
  170. $this->sendOutput($result->getData());
  171. } else {
  172. $this->sendOutput($result->getData(), $result->getErrorCode());
  173. }
  174. }
  175. /**
  176. * 拣货明细(根据商品维度进行统计)
  177. */
  178. public function getAllPickingGoodsDetail()
  179. {
  180. $params = $this->request->getRawJson();
  181. if (empty($params)) {
  182. $this->sendOutput('参数为空', ErrorCode::$paramError);
  183. }
  184. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  185. $selectParams['limit'] = $pageParams['limit'];
  186. $selectParams['offset'] = $pageParams['offset'];
  187. $selectParams['no'] = getArrayItem($params,'no','');//编号
  188. $selectParams['goodsName'] = getArrayItem($params,'goodsName','');//商品
  189. $selectParams['originId'] = getArrayItem($params,'originId',''); //来源单据
  190. $selectParams['originNo'] = getArrayItem($params,'originNo',''); //来源单据
  191. $selectParams['pickingStatus'] = getArrayItem($params,'pickingStatus',[]);//状态
  192. $selectParams['warehouseId'] = getArrayItem($params,'warehouseId','');//仓库
  193. $selectParams['personnel'] = getArrayItem($params,'personnel',''); //拣货人
  194. $selectParams['currentUnitId'] = getArrayItem($params,'currentUnitId',''); //往来单位id
  195. $selectParams['managerId'] = getArrayItem($params,'managerId',''); //往来单位id
  196. $selectParams['timeName'] = getArrayItem($params,'timeName',''); //开始时间
  197. $selectParams['start'] = getArrayItem($params,'start',''); //开始时间
  198. $selectParams['end'] = getArrayItem($params,'end',''); //结束时间
  199. if( isset($selectParams['no']) || !empty($selectParams['no']) ){
  200. $tmpSelectParams['no'] = explode('-',$selectParams['no']);
  201. if(count($tmpSelectParams['no'])==3){
  202. $selectParams['no'] = $tmpSelectParams['no'][1].'-'.$tmpSelectParams['no'][2];
  203. }
  204. }
  205. if( isset($selectParams['originNo']) || !empty($selectParams['originNo']) ){
  206. $tmpSelectParams['originNo'] = explode('-',$selectParams['originNo']);
  207. if(count($tmpSelectParams['originNo'])==3){
  208. $selectParams['originNo'] = $tmpSelectParams['originNo'][1].'-'.$tmpSelectParams['originNo'][2];
  209. }
  210. }
  211. $result = $this->objPicking->getAllPickingGoodsDetail($selectParams);
  212. if ($result->isSuccess()) {
  213. $returnData = $result->getData();
  214. $pageData = [
  215. 'pageIndex' => $params['page'],
  216. 'pageSize' => $params['pageSize'],
  217. 'pageTotal' => $returnData['total'],
  218. ];
  219. parent::sendOutput($returnData['data'], 0, $pageData);
  220. } else {
  221. parent::sendOutput($result->getData(), $result->getErrorCode());
  222. }
  223. }
  224. /**
  225. * @param $pickingDate
  226. * @param $goodsDate
  227. * @return mixed
  228. * 编辑拣货单
  229. */
  230. public function editPicking()
  231. {
  232. $pickingId = $this->request->param('request_id');
  233. if(empty($pickingId)){
  234. $this->sendOutput('参数错误', ErrorCode::$paramError);
  235. }
  236. $params = $this->request->getRawJson();
  237. if (empty($params)) {
  238. parent::sendOutput('参数为空', ErrorCode::$paramError);
  239. }
  240. $params['id'] = $pickingId;
  241. $result = $this->objPicking->editPicking($params);
  242. if ($result->isSuccess()) {
  243. parent::sendOutput($result->getData());
  244. } else {
  245. parent::sendOutput($result->getData(), $result->getErrorCode());
  246. }
  247. }
  248. /**
  249. * 完成拣货
  250. */
  251. public function updatePicking()
  252. {
  253. $params = $this->request->getRawJson();
  254. if (empty($params['id'])) {
  255. parent::sendOutput('参数为空', ErrorCode::$paramError);
  256. }
  257. $result = $this->objPicking->updatePicking($params);
  258. if ($result->isSuccess()) {
  259. parent::sendOutput($result->getData());
  260. } else {
  261. parent::sendOutput($result->getData(), $result->getErrorCode());
  262. }
  263. }
  264. // 格式化商品信息
  265. public function formatGoodsDate($pickingDate,$goodsDate){
  266. foreach($goodsDate as $key =>$value){
  267. $goodsDate[$key]['shopId'] = $pickingDate['shopId'];
  268. $goodsDate[$key]['shopName'] = $pickingDate['shopName'];
  269. $goodsDate[$key]['merchantId'] = $pickingDate['merchantId']; // 商户id
  270. $goodsDate[$key]['price'] = getArrayItem($goodsDate[$key],'price',0); // 单价
  271. $goodsDate[$key]['originPrice'] = getArrayItem($goodsDate[$key],'price',$goodsDate[$key]['price']); // 原始单价
  272. $goodsDate[$key]['orderNum'] = getArrayItem($goodsDate[$key],'orderNum',0); // 原始单价
  273. $goodsDate[$key]['pickingNum'] = $goodsDate[$key]['orderNum']; // 应拣货数量
  274. $goodsDate[$key]['otherNum'] = getArrayItem($goodsDate[$key],'otherNum',0); // 其他数量
  275. $goodsDate[$key]['totalMoney'] = bcmul($goodsDate[$key]['price'],$goodsDate[$key]['orderNum']); // 小计金额 单价 * 订单数量
  276. $goodsDate[$key]['goodsBasicId'] = getArrayItem($goodsDate[$key],'goodsBasicId',0); // 商品资料id
  277. $goodsDate[$key]['unitName'] = getArrayItem($goodsDate[$key],'unitName',''); // 单位名称
  278. $goodsDate[$key]['conversion'] = getArrayItem($goodsDate[$key],'conversion',''); // 换算比率
  279. $goodsDate[$key]['outCostPrice'] = getArrayItem($goodsDate[$key],'outCostPrice',''); // 成本
  280. $goodsDate[$key]['pickingStatus'] = getArrayItem($goodsDate[$key],'pickingStatus',1); // 拣货状态
  281. $goodsDate[$key]['isGiveaway'] = getArrayItem($goodsDate[$key],'isGiveaway',4); // 是否赠品 4:否 5:是
  282. $goodsDate[$key]['barCode'] = getArrayItem($goodsDate[$key],'barCode',""); // 商品条码
  283. $goodsDate[$key]['isEq'] = getArrayItem($goodsDate[$key],'isEq',4); // 是否是超码商品
  284. $goodsDate[$key]['categoryPath'] = getArrayItem($goodsDate[$key],'categoryPath',''); // 分类路径
  285. $goodsDate[$key]['pickingedNum'] = getArrayItem($goodsDate[$key],'pickingedNum',0); // 本次拣货数量
  286. $goodsDate[$key]['InspectionNum'] = getArrayItem($goodsDate[$key],'InspectionNum',$goodsDate[$key]['orderNum']); // 应验数量
  287. $goodsDate[$key]['InspectionedNum'] = getArrayItem($goodsDate[$key],'InspectionedNum',0); // 验货数量
  288. $goodsDate[$key]['InspectionStatus'] = getArrayItem($goodsDate[$key],'InspectionStatus',4); // 验货状态 5全部验货/4未验货/3部分验货
  289. $goodsDate[$key]['specGroup'] = isset($goodsDate[$key]['specGroup']) ? json_encode($goodsDate[$key]['specGroup']): null; // 规格明细
  290. $goodsDate[$key]['goodsImages'] = getArrayItem($goodsDate[$key],'goodsImages',''); // 商品图
  291. $goodsDate[$key]['remark'] = getArrayItem($goodsDate[$key],'remark',''); // 备注
  292. $goodsDate[$key]['extends'] = isset($goodsDate[$key]['extends']) ? json_encode($goodsDate[$key]['extends']) : null; // 扩展字段
  293. $goodsDate[$key]['createTime'] = time(); // 创建时间
  294. }
  295. return $goodsDate;
  296. }
  297. }