123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Gss
- * Date: 2021/5/19 0019
- * Time: 10:51
- */
- namespace JinDouYun\Model\Order;
- use JinDouYun\Controller\Market\VipCard;
- use JinDouYun\Controller\Order\Order;
- use JinDouYun\Dao\Order\DOrder;
- use JinDouYun\Dao\Order\DOrderGoods;
- use JinDouYun\Dao\Order\DOrderIndex;
- use JinDouYun\Dao\Order\DOrderPicking;
- use JinDouYun\Dao\Order\DOrderReceive;
- use JinDouYun\Model\MBaseModel;
- use JinDouYun\Model\SysAreaChina\MSysAreaChina;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- class MOrderPicking extends MBaseModel
- {
- /**
- * @var int 用户id
- */
- private $onlineUserId;
- /**
- * @var int 企业id
- */
- private $onlineEnterpriseId;
- /**
- * @var int 单表数据量
- */
- private $cutTable = 200000;
- private $loginUserCenterId;
- private $isCashier;
- private $isFront;
- private $objDOrderPicking;
- /**
- * MOrder constructor.
- * @param $onlineUserId
- * @param $onlineEnterpriseId
- * @param null $loginUserCenterId
- * @param bool $isFront
- * @throws \Exception
- */
- public function __construct($onlineUserId, $onlineEnterpriseId, $loginUserCenterId = null, $isFront = false, $isCashier = false)
- {
- $this->isCashier = $isCashier;
- $this->isFront = $isFront;
- $this->onlineUserId = $onlineUserId;
- $this->onlineEnterpriseId = $onlineEnterpriseId;
- $this->loginUserCenterId = $loginUserCenterId;
- parent::__construct($this->onlineEnterpriseId, $loginUserCenterId);
- $this->objDOrderPicking = new DOrderPicking('default');
- self::orderPickSubTable($onlineEnterpriseId, $onlineUserId);
- }
- /**
- * 订单拣货表切表
- */
- public function orderPickSubTable($enterpriseId, $userId)
- {
- $tableName = $this->objDOrderPicking->getTableName('qianniao_order_picking_' . $enterpriseId, $userId, $this->cutTable);
- $this->objDOrderPicking->setTable($tableName);
- }
- /**
- * 获取订单拣货表表名
- */
- public function getOrderPickTable($enterpriseId, $userId){
- return $this->objDOrderPicking->getTableName('qianniao_order_picking_' . $enterpriseId, $userId, $this->cutTable);
- }
- /**
- * 列表
- */
- public function getAllOrderPicking($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $whereSql = '';
- if (isset($selectParams['no']) && !empty($selectParams['no'])) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' no like "%' . $selectParams['no'] .'%"';
- }
- //时间删选 有timeName字段优先
- if( isset($selectParams['timeName']) && !empty($selectParams['timeName']) ){
- $timeName = $selectParams['timeName'];
- $timestamp = gettimestamp($timeName,time());
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' createTime BETWEEN ' . $timestamp['start'] . ' AND '. $timestamp['end'];
- }else{
- if ( (isset($selectParams['startTime']) && !empty($selectParams['startTime']))&&(isset($selectParams['endTime']) && !empty($selectParams['endTime'])) ) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' createTime BETWEEN ' . $selectParams['startTime'] . ' AND '. $selectParams['endTime'];
- }
- }
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' orderStatus != ' . StatusCode::$orderStatus['finish'].' and orderStatus != '.StatusCode::$orderStatus['close'].' and pickingStatus = '.StatusCode::$orderPickStatus['notPicking'] ;
- $objOrder = new DOrder();
- $objDOrderIndex = new DOrderIndex();
- $objDOrderReceive = new DOrderReceive();
- $objMSysAreaChina = new MSysAreaChina();
- $indexSql = 'select * from qianniao_order_index_'.$this->onlineEnterpriseId.$whereSql . ' ORDER BY createTime DESC LIMIT ' . $offset . ' , ' . $limit;
- $indexDbResult = $objDOrderIndex->query($indexSql);
- if ($indexDbResult === false) {
- return ResultWrapper::fail($objDOrderIndex->error(), ErrorCode::$dberror);
- }
- $totalSql = 'SELECT COUNT(1) as count FROM qianniao_order_index_'.$this->onlineEnterpriseId.$whereSql;
- $dbTotalResult = $objDOrderIndex->query($totalSql);
- if ($dbTotalResult === false) {
- return ResultWrapper::fail($objDOrderIndex->error(), ErrorCode::$dberror);
- }
- if(empty($dbTotalResult)){
- return ResultWrapper::success([]);
- }
- $allOrderData = [];//订单集
- $allOrderReceiveData = [];//订单收货地址集
- $allGroupData = []; // 订单id
- if(!empty($indexDbResult)){
- foreach ($indexDbResult as $indexKey => $indexValue) {
- $tableNum = ceil($indexValue['userCenterId'] / $this->cutTable);
- $allGroupData[$tableNum][] = $indexValue['id'];
- }
- //
- foreach ($allGroupData as $k => $orderId) {
- $objOrder->setTable('qianniao_order_' . $this->onlineEnterpriseId . '_' . $k);
- $tmpOrderId = implode(',',$orderId);
- $orderSql = 'select o.*, p.sort,p.outNum,p.notOutNum,p.orderNum,p.notPickingNum,p.pickingNum,p.otherNum,p.mangeId,p.mangeName from '.$objOrder->get_Table().' as o left join '.$this->objDOrderPicking->get_Table().' as p on o.id=p.orderId where o.id in ('.$tmpOrderId.') ORDER BY o.createTime desc';
- $dbResult = $objOrder->query($orderSql);
- // $dbResult = $objOrder->select(['id' => $orderId], '*', 'createTime desc');//查询订单
- if ($dbResult === false) {
- return ResultWrapper::fail($objOrder->error(), ErrorCode::$dberror);
- }
- $objDOrderReceive->setTable('qianniao_order_receive_' . $this->onlineEnterpriseId . '_' . $k);
- $orderReceiveResult = $objDOrderReceive->select(['orderId' => $orderId], '*', 'createTime desc');//订单收货
- if ($orderReceiveResult === false) {
- return ResultWrapper::fail($objDOrderReceive->error(), ErrorCode::$dberror);
- }
- $allOrderData = array_merge($dbResult, $allOrderData);
- $allOrderReceiveData = array_merge($orderReceiveResult, $allOrderReceiveData);
- }
- }
- //根据订单处理地址信息
- foreach ($allOrderReceiveData as $receiveKey => $receiveValue){
- // 渲染地址
- if (isset($receiveValue['provinceCode']) && isset($receiveValue['cityCode']) && isset($receiveValue['districtCode'])) {
- $areaName = $objMSysAreaChina->getNameByCode([
- $receiveValue['provinceCode'],
- $receiveValue['cityCode'],
- $receiveValue['districtCode']
- ]);
- $allOrderReceiveData[$receiveKey]['area']['provinceName'] = isset($areaName[$receiveValue['provinceCode']]) ? $areaName[$receiveValue['provinceCode']] : '';
- $allOrderReceiveData[$receiveKey]['area']['cityName'] = isset($areaName[$receiveValue['cityCode']]) ? $areaName[$receiveValue['cityCode']] : '';
- $allOrderReceiveData[$receiveKey]['area']['districtName'] = isset($areaName[$receiveValue['districtCode']]) ? $areaName[$receiveValue['districtCode']] : '';
- }
- $allOrderReceiveData[$receiveValue['orderId']] = $allOrderReceiveData[$receiveKey];
- unset($allOrderReceiveData[$receiveKey]);
- }
- foreach ($allOrderData as $buildKey=>$buildValue){
- //物流信息展示
- if( !empty($buildValue['logisticsData']) ){
- $allOrderData[$buildKey]['logisticsData'] = json_decode($buildValue['logisticsData'],true);
- }
- //备注
- if( !empty($buildValue['extends']) ){
- $allOrderData[$buildKey]['extends'] = json_decode($buildValue['extends'],true);
- }
- //渲染编号
- if( !empty($buildValue['no']) ){
- $allOrderData[$buildKey]['no'] = StatusCode::$noPrefix[1].'-'.$buildValue['no'];
- }
- //配送方式
- if (isset($buildValue['deliveryType'])) {
- $allOrderData[$buildKey]['deliveryMsg'] = isset(StatusCode::$deliveryType[$buildValue['deliveryType']]) ? StatusCode::$deliveryType[$buildValue['deliveryType']] : '';
- }
- //根据订单id来组装地址
- $allOrderData[$buildKey]['orderReceiveData'] = $allOrderReceiveData[$buildValue['id']];
- }
- $return = [
- 'data' => $allOrderData,
- 'total' => $dbTotalResult[0]['count'],
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 订单拣货详情
- */
- public function getOrderPickingInfo($pickingId)
- {
- $objOrder = new DOrder();
- $objDOrderIndex = new DOrderIndex();
- $objDOrderReceive = new DOrderReceive();
- $objMSysAreaChina = new MSysAreaChina();
- $objDOrderGoods = new DOrderGoods();
- $indexDbResult = $objDOrderIndex->query('select * from qianniao_order_index_'.$this->onlineEnterpriseId.' where id = '.$pickingId);
- if ($indexDbResult === false) {
- return ResultWrapper::fail($objDOrderIndex->error(), ErrorCode::$dberror);
- }
- //订单表名
- $tableNum = ceil($indexDbResult[0]['userCenterId'] / $this->cutTable);
- //获取订单状态不是已完成,已关闭的
- $orderDate = $objOrder->query('select * from qianniao_order_'.$this->onlineEnterpriseId.'_'.$tableNum.' where id = '.$pickingId);
- if ($orderDate === false) {
- return ResultWrapper::fail($objOrder->error(), ErrorCode::$dberror);
- }
- $orderDate = array_shift($orderDate);
- //配送方式
- if (isset($orderDate['deliveryType'])) {
- $orderDate['deliveryMsg'] = isset(StatusCode::$deliveryType[$orderDate['deliveryType']]) ? StatusCode::$deliveryType[$orderDate['deliveryType']] : '';
- }
- //渲染编号
- if( !empty($orderDate['no']) ){
- $orderDate['no'] = StatusCode::$noPrefix[1].'-'.$orderDate['no'];
- }
- $objDOrderReceive->setTable('qianniao_order_receive_' . $this->onlineEnterpriseId . '_' . $tableNum);
- $orderReceiveData = $objDOrderReceive->get(['orderId' => $pickingId], '*', 'createTime desc');
- if ($orderReceiveData === false) {
- return ResultWrapper::fail($objDOrderReceive->error(), ErrorCode::$dberror);
- }
- //根据订单处理地址信息
- if (isset($orderReceiveData['provinceCode']) && isset($orderReceiveData['cityCode']) && isset($orderReceiveData['districtCode'])) {
- $areaName = $objMSysAreaChina->getNameByCode([
- $orderReceiveData['provinceCode'],
- $orderReceiveData['cityCode'],
- $orderReceiveData['districtCode']
- ]);
- $orderReceiveData['area']['provinceName'] = isset($areaName[$orderReceiveData['provinceCode']]) ? $areaName[$orderReceiveData['provinceCode']] : '';
- $orderReceiveData['area']['cityName'] = isset($areaName[$orderReceiveData['cityCode']]) ? $areaName[$orderReceiveData['cityCode']] : '';
- $orderReceiveData['area']['districtName'] = isset($areaName[$orderReceiveData['districtCode']]) ? $areaName[$orderReceiveData['districtCode']] : '';
- }
- $orderDate['orderReceive'] = $orderReceiveData;
- //获取订单商品信息
- $goodsDbResult = $objDOrderGoods->query('select * from qianniao_order_goods_'.$this->onlineEnterpriseId.'_'.$tableNum.' where orderId='.$pickingId .' and deleteStatus='.StatusCode::$standard);
- if ($goodsDbResult === false) {
- return ResultWrapper::fail($objDOrderGoods->error(), ErrorCode::$dberror);
- }
- $orderDate['goodsDate'] = $goodsDbResult;
- return ResultWrapper::success($orderDate);
- }
- /**
- * 待拣货明细
- */
- public function getAllPickingGoodsDetail($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $whereSql = '';
- if (isset($selectParams['no']) && !empty($selectParams['no'])) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' o.no like "%' . $selectParams['no'] .'%"';
- }
- if (isset($selectParams['goodsName']) && !empty($selectParams['goodsName'])) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' g.goodsName like "%'.$selectParams['goodsName'].'%"';
- }
- if (isset($selectParams['operatorId']) && !empty($selectParams['operatorId'])) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' o.operatorId =' . $selectParams['operatorId'];
- }
- if ( (isset($selectParams['start']) && !empty($selectParams['start']))&&(isset($selectParams['end']) && !empty($selectParams['end'])) ) {
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' o.createTime BETWEEN ' . $selectParams['start'] . ' AND '. $selectParams['end'];
- }
- $where = empty($whereSql) ? ' WHERE ' : ' AND ';
- $whereSql .= $where . ' o.orderStatus != ' . StatusCode::$orderStatus['finish'].' and o.orderStatus != '.StatusCode::$orderStatus['close'].' and o.pickingStatus = '.StatusCode::$orderPickStatus['notPicking'] ;
- $objMOrder = new MOrder($this->onlineUserId,$this->onlineEnterpriseId);
- $orderTable = $objMOrder->getOrderTable($this->onlineEnterpriseId,$this->onlineUserId);
- $tableNum = substr($orderTable,-1);
- $objDOrderIndex = new DOrderIndex();
- $orderSql = 'select o.`no`,o.customerId,o.customerName,o.operatorId,o.operatorName,o.createTime,g.* from '.$orderTable.' as o left join qianniao_order_goods_64_'.$tableNum.' as g on o.id=g.orderId '.$whereSql.' ORDER BY o.createTime desc LIMIT ' . $offset . ' , ' . $limit;
- $indexDbResult = $objDOrderIndex->query($orderSql);
- if ($indexDbResult === false) {
- return ResultWrapper::fail($objDOrderIndex->error(), ErrorCode::$dberror);
- }
- // 商品规格信息
- foreach ($indexDbResult as $key => $value){
- // 订单类型
- $indexDbResult[$key]['orderType'] = '销售订单';
- if( isset($value['specGroup']) ){
- if ($value['specGroup'] == 'null'){
- $indexDbResult[$key]['specGroup'] = json_encode([],true);
- }
- if (!empty($value['specGroup']) && $value['specGroup'] != 'null' && $value['specGroup'] != '[]'){
- $indexDbResult[$key]['specGroup'] = json_encode($value['specGroup'],true);
- }
- }
- }
- $totalSql = 'select COUNT(1) AS count from '.$orderTable.' as o left join qianniao_order_goods_64_'.$tableNum.' as g on o.id=g.orderId '.$whereSql;
- $dbTotalResult = $objDOrderIndex->query($totalSql);
- if ($dbTotalResult === false) {
- return ResultWrapper::fail($objDOrderIndex->error(), ErrorCode::$dberror);
- }
- if(empty($dbTotalResult)){
- return ResultWrapper::success([]);
- }
- $return = [
- 'data' => $indexDbResult,
- 'total' => $dbTotalResult[0]['count'],
- ];
- return ResultWrapper::success($return);
- }
- /**
- * 订单拣货表 新增订单时用
- */
- public function addOrderPick($params)
- {
- $orderPickingDate = [
- 'orderId' => getArrayItem($params,'orderId',0),
- 'sort' => getArrayItem($params,'sort',0),
- 'outNum' => getArrayItem($params,'outNum',0),
- 'notOutNum' => getArrayItem($params,'notOutNum',0),
- 'orderNum' => getArrayItem($params,'orderNum',0),
- 'notPickingNum' => getArrayItem($params,'notPickingNum',0),
- 'pickingNum' => getArrayItem($params,'pickingNum',0),
- 'outTime' => getArrayItem($params,'outTime',0),
- 'mangeId' => getArrayItem($params,'mangeId',0),
- 'mangeName' => getArrayItem($params,'mangeName',''),
- ];
- foreach ($orderPickingDate as $key => $value) {
- if (empty($value) && $value !== 0) {
- return ResultWrapper::fail('参数错误,拣货单创建失败', ErrorCode::$paramError);
- }
- }
- $orderPickingDate['createTime'] = time();
- $beginTransactionstatus = $this->objDOrderPicking->beginTransaction();
- $dbResult = $this->objDOrderPicking->insert($orderPickingDate);
- if ($dbResult === false) {
- $this->objDOrderPicking->rollBack();
- return ResultWrapper::fail($this->objDOrderPicking->error(), ErrorCode::$dberror);
- }
- if( $beginTransactionstatus ){
- $this->objDOrderPicking->commit();
- }
- return ResultWrapper::success($dbResult);
- }
- }
|