123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Gss
- * Date: 2021/5/17 0017
- * Time: 17:38
- */
- namespace JinDouYun\Controller\Stock;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Stock\MPicking;
- class Picking extends BaseController
- {
- private $objPicking;
- private $loginUserCenterId;
- /**
- * PICKING constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->loginUserCenterId = $this->onlineUserId;//获取登录后台用户的id
- $userCenterId = $this->request->param('request_id');//客户对应的userCenterId
- $this->onlineUserId = empty($userCenterId) ? $this->onlineUserId : $userCenterId;//防止产生0后缀的表
- $this->objPicking = new MPicking($this->onlineUserId, $this->onlineEnterpriseId, $this->loginUserCenterId);
- }
- /**
- * 添加、编辑拣货单公告方法
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- //组装数据
- $pickingDate = [
- 'shopId' => isset($params['shopId']) ? $params['shopId'] : 0,
- 'shopName' => isset($params['shopName']) ? $params['shopName'] : '',
- 'merchantId' => isset($params['merchantId']) ? $params['merchantId'] : 0,
- 'originId' => isset($params['originId']) ? $params['originId'] : 0,
- 'originNo' => isset($params['originNo']) ? $params['originNo'] : '',
- // 'warehouseId' => isset($params['warehouseId']) ? $params['warehouseId'] : 0,
- // 'warehouseName' => isset($params['warehouseName']) ? $params['warehouseName'] : '',
- 'personnel' => isset($params['personnel']) ? $params['personnel'] : 0,
- 'personnelName' => isset($params['personnelName']) ? $params['personnelName'] : '',
- 'currentUnitId' => isset($params['currentUnitId']) ? $params['currentUnitId'] : 0,
- 'currentUnit' => isset($params['currentUnit']) ? $params['currentUnit'] : '',
- 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : '',
- 'managerId' => isset($params['managerId']) ? $params['managerId'] : 0,
- 'managerName' => isset($params['managerName']) ? $params['managerName'] : 0,
- 'goodsData' => getArrayItem($params,'goodsData', [])
- ];
- foreach ($pickingDate as $key => $value) {
- if (empty($value) && $value !== 0) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- return $pickingDate;
- }
- /**
- * 新增拣货单
- */
- public function addPicking()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- //组装数据
- $pickingDate = $this->commonFieldFilter();
- $pickingDate['sort'] = getArrayItem($params,'sort',0);
- $pickingDate['number'] = 0;// 数量
- $pickingDate['goodsLine'] = count($pickingDate['goodsData']); // 商品行数
- $pickingDate['totalMoney'] = 0; // 销售金额
- $pickingDate['notPickingNum'] = 0; // 未拣货数量
- $pickingDate['pickingNum'] = 0; // 拣货数量
- $pickingDate['InspectionNum'] = 0; // 拣货数量
- $pickingDate['InspectionedNum'] = 0; // 拣货数量
- $pickingDate['outNum'] = 0; // 发货数量
- $pickingDate['notOutNum'] = 0; // 未发货数量
- $pickingDate['outTime'] = 0; // 发货时间
- $pickingDate['address'] = getArrayItem($params,'address',''); // 地址
- $pickingDate['pickingStatus'] = 4; // 拣货状态
- $pickingDate['pickingType'] = 1; // 拣货类型
- //循环获取商品数量,销售金额
- foreach ($pickingDate['goodsData'] as $key =>$value ){
- $pickingDate['number'] = bcadd($pickingDate['number'],$value['orderNum']);
- $pickingDate['notPickingNum'] = bcadd($pickingDate['notPickingNum'],$value['orderNum']);
- $pickingDate['totalMoney'] = bcadd($pickingDate['totalMoney'],$value['totalMoney']);
- $pickingDate['notOutNum'] = bcadd($pickingDate['notOutNum'],$value['orderNum']);
- $pickingDate['InspectionNum'] = bcadd($pickingDate['InspectionNum'],$value['orderNum']);
- }
- $pickingDate['remark'] = isset($params['remark']) ? $params['remark'] : '';//订单备注
- $pickingDate['createTime'] = time(); //创建时间
- //组装商品数据
- $pickingDate['goodsData'] = self::formatGoodsDate($pickingDate,$pickingDate['goodsData']);
- $result = $this->objPicking->addPicking($pickingDate);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 拣货单列表
- */
- public function getAllPicking()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['no'] = getArrayItem($params,'no','');//编号
- $selectParams['warehouseId'] = getArrayItem($params,'warehouseId','');//仓库
- $selectParams['personnel'] = getArrayItem($params,'personnel',''); //拣货人
- $selectParams['originId'] = getArrayItem($params,'originId',''); //来源单据
- $selectParams['originNo'] = getArrayItem($params,'originNo',''); //来源单据
- $selectParams['currentUnitId'] = getArrayItem($params,'currentUnitId',''); //往来单位id
- $selectParams['managerId'] = getArrayItem($params,'managerId',''); //往来单位id
- $selectParams['timeName'] = getArrayItem($params,'timeName',''); //时间判断
- $selectParams['start'] = getArrayItem($params,'start',''); //开始时间
- $selectParams['end'] = getArrayItem($params,'end',''); //结束时间
- if( isset($selectParams['no']) || !empty($selectParams['no']) ){
- $tmpSelectParams['no'] = explode('-',$selectParams['no']);
- if(count($tmpSelectParams['no'])==3){
- $selectParams['no'] = $tmpSelectParams['no'][1].'-'.$tmpSelectParams['no'][2];
- }
- }
- if( isset($selectParams['originNo']) || !empty($selectParams['originNo']) ){
- $tmpSelectParams['originNo'] = explode('-',$selectParams['originNo']);
- if(count($tmpSelectParams['originNo'])==3){
- $selectParams['originNo'] = $tmpSelectParams['originNo'][1].'-'.$tmpSelectParams['originNo'][2];
- }
- }
- $result = $this->objPicking->getAllPicking($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * @param $pickingDate
- * @param $goodsDate
- * @return mixed
- * 拣货单详情
- */
- public function getPickingInfo()
- {
- $pickingId = $this->request->param('request_id');
- if (!$pickingId) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objPicking->getPickingInfo($pickingId);
- if ($result->isSuccess()) {
- $this->sendOutput($result->getData());
- } else {
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 拣货明细(根据商品维度进行统计)
- */
- public function getAllPickingGoodsDetail()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $selectParams['no'] = getArrayItem($params,'no','');//编号
- $selectParams['goodsName'] = getArrayItem($params,'goodsName','');//商品
- $selectParams['originId'] = getArrayItem($params,'originId',''); //来源单据
- $selectParams['originNo'] = getArrayItem($params,'originNo',''); //来源单据
- $selectParams['pickingStatus'] = getArrayItem($params,'pickingStatus',[]);//状态
- $selectParams['warehouseId'] = getArrayItem($params,'warehouseId','');//仓库
- $selectParams['personnel'] = getArrayItem($params,'personnel',''); //拣货人
- $selectParams['currentUnitId'] = getArrayItem($params,'currentUnitId',''); //往来单位id
- $selectParams['managerId'] = getArrayItem($params,'managerId',''); //往来单位id
- $selectParams['timeName'] = getArrayItem($params,'timeName',''); //开始时间
- $selectParams['start'] = getArrayItem($params,'start',''); //开始时间
- $selectParams['end'] = getArrayItem($params,'end',''); //结束时间
- if( isset($selectParams['no']) || !empty($selectParams['no']) ){
- $tmpSelectParams['no'] = explode('-',$selectParams['no']);
- if(count($tmpSelectParams['no'])==3){
- $selectParams['no'] = $tmpSelectParams['no'][1].'-'.$tmpSelectParams['no'][2];
- }
- }
- if( isset($selectParams['originNo']) || !empty($selectParams['originNo']) ){
- $tmpSelectParams['originNo'] = explode('-',$selectParams['originNo']);
- if(count($tmpSelectParams['originNo'])==3){
- $selectParams['originNo'] = $tmpSelectParams['originNo'][1].'-'.$tmpSelectParams['originNo'][2];
- }
- }
- $result = $this->objPicking->getAllPickingGoodsDetail($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * @param $pickingDate
- * @param $goodsDate
- * @return mixed
- * 编辑拣货单
- */
- public function editPicking()
- {
- $pickingId = $this->request->param('request_id');
- if(empty($pickingId)){
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $params['id'] = $pickingId;
- $result = $this->objPicking->editPicking($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 完成拣货
- */
- public function updatePicking()
- {
- $params = $this->request->getRawJson();
- if (empty($params['id'])) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objPicking->updatePicking($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- // 格式化商品信息
- public function formatGoodsDate($pickingDate,$goodsDate){
- foreach($goodsDate as $key =>$value){
- $goodsDate[$key]['shopId'] = $pickingDate['shopId'];
- $goodsDate[$key]['shopName'] = $pickingDate['shopName'];
- $goodsDate[$key]['merchantId'] = $pickingDate['merchantId']; // 商户id
- $goodsDate[$key]['price'] = getArrayItem($goodsDate[$key],'price',0); // 单价
- $goodsDate[$key]['originPrice'] = getArrayItem($goodsDate[$key],'price',$goodsDate[$key]['price']); // 原始单价
- $goodsDate[$key]['orderNum'] = getArrayItem($goodsDate[$key],'orderNum',0); // 原始单价
- $goodsDate[$key]['pickingNum'] = $goodsDate[$key]['orderNum']; // 应拣货数量
- $goodsDate[$key]['otherNum'] = getArrayItem($goodsDate[$key],'otherNum',0); // 其他数量
- $goodsDate[$key]['totalMoney'] = bcmul($goodsDate[$key]['price'],$goodsDate[$key]['orderNum']); // 小计金额 单价 * 订单数量
- $goodsDate[$key]['goodsBasicId'] = getArrayItem($goodsDate[$key],'goodsBasicId',0); // 商品资料id
- $goodsDate[$key]['unitName'] = getArrayItem($goodsDate[$key],'unitName',''); // 单位名称
- $goodsDate[$key]['conversion'] = getArrayItem($goodsDate[$key],'conversion',''); // 换算比率
- $goodsDate[$key]['outCostPrice'] = getArrayItem($goodsDate[$key],'outCostPrice',''); // 成本
- $goodsDate[$key]['pickingStatus'] = getArrayItem($goodsDate[$key],'pickingStatus',1); // 拣货状态
- $goodsDate[$key]['isGiveaway'] = getArrayItem($goodsDate[$key],'isGiveaway',4); // 是否赠品 4:否 5:是
- $goodsDate[$key]['barCode'] = getArrayItem($goodsDate[$key],'barCode',""); // 商品条码
- $goodsDate[$key]['isEq'] = getArrayItem($goodsDate[$key],'isEq',4); // 是否是超码商品
- $goodsDate[$key]['categoryPath'] = getArrayItem($goodsDate[$key],'categoryPath',''); // 分类路径
- $goodsDate[$key]['pickingedNum'] = getArrayItem($goodsDate[$key],'pickingedNum',0); // 本次拣货数量
- $goodsDate[$key]['InspectionNum'] = getArrayItem($goodsDate[$key],'InspectionNum',$goodsDate[$key]['orderNum']); // 应验数量
- $goodsDate[$key]['InspectionedNum'] = getArrayItem($goodsDate[$key],'InspectionedNum',0); // 验货数量
- $goodsDate[$key]['InspectionStatus'] = getArrayItem($goodsDate[$key],'InspectionStatus',4); // 验货状态 5全部验货/4未验货/3部分验货
- $goodsDate[$key]['specGroup'] = isset($goodsDate[$key]['specGroup']) ? json_encode($goodsDate[$key]['specGroup']): null; // 规格明细
- $goodsDate[$key]['goodsImages'] = getArrayItem($goodsDate[$key],'goodsImages',''); // 商品图
- $goodsDate[$key]['remark'] = getArrayItem($goodsDate[$key],'remark',''); // 备注
- $goodsDate[$key]['extends'] = isset($goodsDate[$key]['extends']) ? json_encode($goodsDate[$key]['extends']) : null; // 扩展字段
- $goodsDate[$key]['createTime'] = time(); // 创建时间
- }
- return $goodsDate;
- }
- }
|