12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181 |
- <?php
- /**
- * 订单中心
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/10/31
- * Time: 15:46
- */
- namespace JinDouYun\Controller\Order;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Cart\MCart;
- use JinDouYun\Model\Goods\MGoods;
- use JinDouYun\Model\GoodsManage\MSku;
- use JinDouYun\Model\Order\MOrder;
- use Jindouyun\Model\Order\MOrderStatistics;
- /**
- * 这个是后台的需要url后加用户对应的customerId (与购物车一样)
- * Class Order
- * @package JinDouYun\Controller\Order
- */
- class Order extends BaseController
- {
- /**
- * @var MOrder
- */
- private $objMOrder;
- /**
- * @var MCart
- */
- private $objMCart;
- private $loginUserCenterId;
- /**
- * Order 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->objMOrder = new MOrder($this->onlineUserId, $this->onlineEnterpriseId, $this->loginUserCenterId);
- $this->objMCart = new MCart($this->onlineUserId, $this->onlineEnterpriseId, false);
- }
- /**
- * 添加,编辑订单公共数据
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $orderData = [
- 'payType' => isset($params['payType']) ? $params['payType'] : StatusCode::$payType['cashPay'],
- 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : '',
- 'receiveAddressId' => isset($params['receiveAddressId']) ? $params['receiveAddressId'] : '',//收货地址id
- 'source' => isset($params['source']) ? $params['source'] : 0,//订单来源
- 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : '',//商品数据json(包含信息有以下字段)
- ];
- foreach ($orderData as $key => $value) {
- if (empty($value) && $value !== 0) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $orderData['remark'] = isset($params['remark']) ? $params['remark'] : '';//订单备注
- $allGoodsData = [
- 'totalMoney' => isset($orderData['goodsData']['totalMoney']) ? $orderData['goodsData']['totalMoney'] : '',
- 'payMoney' => isset($orderData['goodsData']['payMoney']) ? $orderData['goodsData']['payMoney'] : '',
- 'preferential' => isset($orderData['goodsData']['preferential']) ? $orderData['goodsData']['preferential'] : '',
- 'checkNum' => isset($orderData['goodsData']['checkNum']) ? $orderData['goodsData']['checkNum'] : '',
- 'goodsData' => isset($orderData['goodsData']['goodsData']) ? $orderData['goodsData']['goodsData'] : '',
- ];
- foreach ($allGoodsData as $key => $value) {
- if (empty($value) && $value !== 0) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $allShopData = $allGoodsData['goodsData'];
- $goodsData = [];
- foreach ($allShopData as $key => $val) {
- $goodsData[$key] = [
- 'shopId' => isset($val['shopId']) ? $val['shopId'] : '',
- 'shopName' => isset($val['shopName']) ? $val['shopName'] : '',
- 'totalMoney' => isset($val['totalMoney']) ? $val['totalMoney'] : '',
- 'payMoney' => isset($val['payMoney']) ? $val['payMoney'] : '',
- 'shopGoodsData' => isset($val['shopGoodsData']) ? $val['shopGoodsData'] : '',
- ];
- foreach ($goodsData[$key] as $k => $v) {
- if (empty($v)) {
- parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
- }
- if ($k == 'shopGoodsData'){
- if (isset($v['totalMoney']) && $v['totalMoney'] == 0){
- parent::sendOutput($v['goodsName'] . ',价格为0,不能进行购买', ErrorCode::$paramError);
- }
- }
- }
- }
- return $orderData;
- }
- /**
- * Doc: (des="后台代客下单")
- * User: XMing
- * Date: 2020/11/3
- * Time: 10:52 上午
- * @throws \Exception
- */
- public function add()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'payType' => isset($params['payType']) ? $params['payType'] : StatusCode::$payType['cashPay'],
- 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : null,
- 'addressId' => isset($params['addressId']) ? $params['addressId'] : 0,
- 'source' => StatusCode::$source['manage'],
- 'lists' => isset($params['lists']) ? $params['lists'] : null,//商品
- 'totalMoney' => isset($params['totalMoney']) ? $params['totalMoney'] : null,
- 'payMoney' => isset($params['payMoney']) ? $params['payMoney'] : null,
- 'totalReduceMoney' => isset($params['totalReduceMoney']) ? $params['totalReduceMoney'] : null,
- 'userCenterId' => isset($params['userCenterId']) ? $params['userCenterId'] : null,
- 'customerId' => isset($params['customerId']) ? $params['customerId'] : null,
- 'customerName' => isset($params['customerName']) ? $params['customerName'] : null,
- 'selfRuleId' => isset($params['selfRuleId']) ? $params['selfRuleId'] : 0,
- 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
- 'operatorId' => $this->loginUserCenterId,
- ];
- foreach ($data as $key => $value) {
- if (is_null($value) && empty($value['selfRuleId'])) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['selfRuleData'] = getArrayItem($params, 'selfRuleData', []);
- $data['accountList'] = isset($params['accountList']) ? $params['accountList'] : [];
- $data['currentAccountName'] = isset($params['currentAccountName']) ? $params['currentAccountName'] : '';
- $data['receivedMoney'] = isset($params['receivedMoney']) ? $params['receivedMoney'] : 0;
- $data['remark'] = isset($params['remark']) ? $params['remark'] : '';
- $objMGoods = new MGoods($this->onlineEnterpriseId,true,$data['userCenterId']);
- $objMSku = new MSku($this->onlineUserId,$this->onlineEnterpriseId);
- $lists = $data['lists'];
- foreach ($lists as &$item){
- // 对抄码商品做单位转换处理
- if ($item['isEq'] == StatusCode::$standard){
- // 查询抄码商品的主单位sku数据
- $masterSkuResult = $objMSku->getMasterById($item['basicGoodsId']);
- if (!$masterSkuResult->isSuccess()){
- parent::sendOutput($masterSkuResult->getData(),$masterSkuResult->getErrorCode());
- }
- $masterSku = $masterSkuResult->getData();
- if (empty($masterSku)){
- parent::sendOutput('超码商品主单位获取异常',ErrorCode::$paramError);
- }
- //抄码商品为了支持主单位购买 不进行换算
- if($item['skuId'] != $masterSku['id']){
- //辅单位
- $conversion = $item['conversion'];
- $item['otherNum'] = $item['buyNum'];
- $u_1_buy = $item['buyNum'];//辅单位购买数量
- $item['buyNum'] = bcmul($item['buyNum'],$conversion,2);
- $item['salePrice'] = bcdiv($item['salePrice'],$conversion,2);
- $u = isset($masterSku['unitName']) ? $masterSku['unitName'] : '';//主单位名字
- $u_1 = $item['unitName'];//辅单位名字
- $uId_1 = $item['skuId'];//辅单位id
- $uId = $masterSku['id'];//主单位id
- $extends = ['uId' => $uId, 'uId_1' => $uId_1, 'u' => $u, 'u_1' => $u_1,'u_1_buy'=> $u_1_buy,'conversion' => $conversion];
- $item['extends'] = $extends;
- $item['skuId'] = $extends['uId'];
- $item['unitName'] = $extends['u'];
- }
- }
- }
- $data['lists'] = $lists;
- $result = $this->objMOrder->add($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="编辑")
- * User: XMing
- * Date: 2020/11/5
- * Time: 9:39 上午
- * @throws \Exception
- */
- public function edit()
- {
- $orderId = $this->request->param('request_id');
- if (!$orderId) {
- parent::sendOutput('参数错误', ErrorCode::$paramError);
- }
- $params = $this->request->getRawJson();
- if (empty($params)){
- parent::sendOutput('参数为空',ErrorCode::$paramError);
- }
- $params['goodsData'] = self::transFormatGoods($params['goodsData']);
- $result = $this->objMOrder->edit($params,$orderId);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="格式化参数,转换为统一参数")
- * User: XMing
- * Date: 2021/1/5
- * Time: 10:00 上午
- * @param array $lists
- * @return array
- */
- public function transFormatGoods(array $lists): array
- {
- if (empty($lists)){
- return $lists;
- }
- foreach ($lists as &$list){
- if (isset($list['goodsBasicId']) && !empty($list['goodsBasicId'])){
- $list['materielId'] = $list['goodsBasicId'];
- }
- if (isset($list['basicGoodsId']) && !empty($list['basicGoodsId'])){
- $list['materielId'] = $list['basicGoodsId'];
- }
- if (!isset($list['materielId']) || empty($list['materielId'])){
- self::sendOutput('materielId参数错误',ErrorCode::$paramError);
- }
- }
- return $lists;
- }
- /**
- * 获取指定订单详情
- * @throws \Exception
- */
- public function getOrderInfoById()
- {
- $orderId = $this->request->param('orderId');
- if (!$orderId) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMOrder->getOrderInfoById($orderId);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="批量获取订单详情")
- * User: XMing
- * Date: 2021/3/31
- * Time: 10:22 上午
- * @throws \Exception
- */
- public function getOrderInfoByIds()
- {
- $params = $this->request->getRawJson();
- if (!isset($params['ids']) || empty($params['ids'])){
- parent::sendOutput('ids参数错误',ErrorCode::$paramError);
- }
- $orderIds = $params['ids'];
- $arrayLists = [];
- foreach ($orderIds as $id){
- $result = $this->objMOrder->getOrderInfoById($id);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- $arrayLists[] = (array)$result->getData();
- }
- parent::sendOutput($arrayLists);
- }
- /**
- * Doc: (des="获取所有订单")
- * User: XMing
- * Date: 2020/7/15
- * Time: 10:34 上午
- * @waitAudit:等待审核 orderStatus != 6 auditStatus = 1
- * @waitOutStock:待出库 orderStatus != 6 auditPass = 2
- * @hasOutStock:已出库 orderStatus = 4 auditPass = 2
- * @finish:已完成 orderStatus = 5 auditPass 2
- * @close:已关闭 orderStatus = 6
- * @all:全部订单
- * @throws \Exception
- * @throws \Exception
- * @return mixed
- */
- public function getAllOrder()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
- 'page' => isset($paramsData['page']) ? $paramsData['page'] : 1,
- ];
- foreach ($params as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $params['search'] = isset($paramsData['search']) ? $paramsData['search'] : [];
- $offset = ($params['page'] - 1) * $params['pageSize'];
- $selectParams = [
- 'limit' => $params['pageSize'],
- 'offset' => $offset,
- ];
- (isset($paramsData['state']) && !empty($paramsData['state'])) && $selectParams['state'] = $paramsData['state'];//参数说明见方法注解
- (isset($paramsData['orderStatus']) && !empty($paramsData['orderStatus'])) && $selectParams['orderStatus'] = $paramsData['orderStatus'];
- (isset($paramsData['outStatus']) && !empty($paramsData['outStatus'])) && $selectParams['outStatus'] = $paramsData['outStatus'];
- isset($paramsData['returnStatus']) && $selectParams['returnStatus'] = $paramsData['returnStatus'];
- isset($paramsData['shopId']) && $selectParams['shopId'] = $paramsData['shopId'];
- if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
- $is_export = false;
- if (isset($paramsData['export']) && $paramsData['export'] == 1) $is_export = true;
- //根据订单编号查找商品
- if( !empty($paramsData['order'])){
- $selectParams['no'] = explode('-',$paramsData['order']);
- $selectParams['no'] = $selectParams ['no'][1].'-'.$selectParams ['no'][2];
- unset($selectParams['order']);
- }
- $orderData = $this->objMOrder->getAllOrder($selectParams, $params['search'], $is_export);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
-
-
- /**
- * Doc: (des="获取检索订单数据")
- * 订单列表搜索商品名称、商品编码、收货人、电话
- * @waitAudit:等待审核 orderStatus != 6 auditStatus = 1
- * @waitOutStock:待出库 orderStatus != 6 auditPass = 2
- * @hasOutStock:已出库 orderStatus = 4 auditPass = 2
- * @finish:已完成 orderStatus = 5 auditPass 2
- * @close:已关闭 orderStatus = 6
- *
- */
- public function keywordSearch()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
- 'page' => isset($paramsData['page']) ? $paramsData['page'] : 1,
- ];
- $offset = ($params['page'] - 1) * $params['pageSize'];
- $selectParams = [
- 'limit' => $params['pageSize'],
- 'offset' => $offset,
- ];
- foreach ($selectParams as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $selectParams['keywordType'] = getArrayItem($paramsData,'keywordType',1);
- $selectParams['keyword'] = getArrayItem($paramsData,'keyword','');
- $selectParams['startTime'] = getArrayItem($paramsData,'startTime','');
- $selectParams['endTime'] = getArrayItem($paramsData,'endTime','');
- $selectParams['userCenterId'] = getArrayItem($paramsData,'userCenterId','');
- $selectParams['customerId'] = getArrayItem($paramsData,'customerId','');
- $selectParams['shopId'] = getArrayItem($paramsData,'shopId','');
- $selectParams['payType'] = getArrayItem($paramsData,'payType',''); // 支付方式 1微信 2支付宝 3货到付款 4上门自提
- $selectParams['customerType'] = getArrayItem($paramsData,'customerType','');
- $selectParams['source'] = getArrayItem($paramsData,'source',''); // 订单来源 订单来源 默认1 ios 2android 3小程序 4后台创建
- $selectParams['state'] = getArrayItem($paramsData,'state',[]);//参数说明见方法注解
- $selectParams['payStatus'] = getArrayItem($paramsData,'payStatus');//支付状态 默认4 未支付 5已支付
- $selectParams['outStatus'] = getArrayItem($paramsData,'outStatus',''); //出库状态 4:未出库 5:已出库 6部分出库
- $selectParams['returnStatus'] = getArrayItem($paramsData,'returnStatus',[]); //退货状态 0:未退货 1:部分退货 2:全部退货
- $export = getArrayItem($paramsData,'export','');
- $orderData = $this->objMOrder->keywordSearch($selectParams,$export);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- /**
- * 销售订单汇总
- * @throws \Exception
- */
- public function getAllOrderData()
- {
- $params = $this->request->getRawJson();
- $page = $params['page'] ?: 1;
- $pageSize = $params['pageSize'] ?: 10;
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- isset($params['outStatus']) && $selectParams['outStatus'] = $params['outStatus'];
- isset($params['goodsName']) && $selectParams['goodsName'] = $params['goodsName'];
- isset($params['categoryId']) && $selectParams['categoryId'] = $params['categoryId'];
- isset($params['customerId']) && $selectParams['customerId'] = $params['customerId'];
- isset($params['shopId']) && $selectParams['shopId'] = $params['shopId'];
- isset($params['start']) && $selectParams['start'] = $params['start'];
- isset($params['end']) && $selectParams['end'] = $params['end'];
- $this->shopId && $selectParams['shopId'] = $this->shopId;
- $selectParams['onReturn'] = isset($params['onReturn']) ? $params['onReturn'] : 0;
- $type = isset($params['type']) ? $params['type'] : 0;
- $export = isset($params['export']) ? $params['export'] : 0;
- $objMOrderStatistics = new MOrderStatistics($this->onlineUserId, $this->onlineEnterpriseId);
- $orderData = $objMOrderStatistics->getAllOrderData($selectParams, $type, $export);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- //测试定时统计
- public function setOrderView()
- {
- $objMOrderStatistics = new MOrderStatistics($this->onlineUserId, $this->onlineEnterpriseId);
- $dbResult = $objMOrderStatistics->setOrderView();
- if (!$dbResult->isSuccess()) {
- parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
- }
- parent::sendOutput($dbResult->getData());
- }
- /**
- * Doc: (des="更新订单审核状态,通过/驳回(不支持批量)")
- * User: XMing
- * Date: 2020/7/14
- * Time: 6:29 下午
- * @throws \Exception
- */
- public function updateAuditStatus()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'id' => isset($paramsData['orderId']) ? $paramsData['orderId'] : '',
- 'audit' => isset($paramsData['audit']) ? $paramsData['audit'] : '',
- 'auditId' => $this->onlineUserId,
- 'auditStatus' => isset($paramsData['auditStatus']) ? $paramsData['auditStatus'] : '',//2通过 3驳回
- ];
- foreach ($params as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMOrder->updateAuditStatus($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 更新订单审核状态,(批量操作)
- * @throws \Exception
- */
- public function batchUpdateAuditStatus()
- {
- $paramsData = $this->request->getRawJson();
- $params = [
- 'ids' => isset($paramsData['orderIds']) ? $paramsData['orderIds'] : [],
- 'audit' => isset($paramsData['audit']) ? $paramsData['audit'] : '',
- 'auditId' => $this->onlineUserId,
- 'auditStatus' => isset($paramsData['auditStatus']) ? $paramsData['auditStatus'] : '',//2通过 3驳回
- ];
- foreach ($params as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMOrder->batchUpdateAuditStatus($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 更新订单状态
- * @throws \Exception
- */
- public function updateOrderStatus()
- {
- $params = $this->request->getRawJson();
- $params = [
- 'orderId' => $params['orderId'],
- 'orderStatus' => isset($params['orderStatus']) ? $params['orderStatus'] : StatusCode::$orderStatus['close'], // 不传时为取消订单
- 'cancelReason' => isset($params['cancelReason']) ? $params['cancelReason'] : '',
- 'cancelRejectReason' => isset($params['cancelRejectReason']) ? $params['cancelRejectReason'] : '',
- ];
- if (!$params['orderId']) {
- $this->sendOutput('orderId参数错误', ErrorCode::$paramError);
- }
- if( $params['orderStatus'] == StatusCode::$orderStatus['close'] && empty($params['cancelReason']) ){
- parent::sendOutput('请输入取消订单原因', ErrorCode::$paramError);
- }
- $orderId = $params['orderId'];unset($params['orderId']);
- $result = $this->objMOrder->updateOrderStatus($orderId, $params,[
- 'Token' => $this->token,
- 'Authorization' => $this->authorization
- ]);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 搜索
- * @waitAudit:等待审核 orderStatus != 6 auditStatus = 1
- * @waitOutStock:待出库 orderStatus != 6 auditPass = 2
- * @hasOutStock:已出库 orderStatus = 4 auditPass = 2
- * @finish:已完成 orderStatus = 5 auditPass 2
- * @close:已关闭 orderStatus = 6
- * @all:全部
- * @throws \Exception
- */
- public function search()
- {
- $params = $this->request->getRawJson();
- $selectParams = [
- 'state' => isset($params['state']) ? $params['state'] : '',//状态标示,见方法注解
- 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',//订单编号,收货人,商品名称 ,销售员
- 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
- 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
- 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
- 'startTime' => isset($params['start']) ? $params['start'] : '',
- 'endTime' => isset($params['end']) ? $params['end'] : '',
- 'orderStatus' => isset($params['orderStatus']) ? $params['orderStatus'] : '',
- 'payType' => isset($params['payType']) ? $params['payType'] : '',
- 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
- 'customerType' => isset($params['customerType']) ? $params['customerType'] : '',
- 'source' => isset($params['source']) ? $params['source'] : '',
- 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : '',
- 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : '',
- 'outStatus' => isset($params['outStatus']) ? $params['outStatus'] : '',
- 'returnStatus' => isset($params['returnStatus']) ? $params['returnStatus'] : '',
- 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
- 'orderType' => isset($params['orderType']) ? $params['orderType'] : '',
- ];
- $is_export = false;
- if (isset($params['export']) && $params['export'] == 1) $is_export = true;
- if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
- $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- $result = $this->objMOrder->getAllOrder($selectParams,[],$is_export);
- //$result = $this->objMOrder->search($selectParams, $is_export);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 增加打印次数
- */
- public function printIncr()
- {
- $orderId = $this->request->param('orderId');
- if (!$orderId) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMOrder->printIncr($orderId);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * (订单在待出库的状态下->确认收款->订单支付状态已付款->订单状态待出库(出库应该判断,订单是否已支付))
- * 修改订单的支付状态
- * @throws \Exception
- */
- public function updateOrderPayData()
- {
- $orderId = $this->request->param('orderId');
- if (!$orderId) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMOrder->checkOutOrderStatus($orderId);
- if (!$result->isSuccess()) {
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- $result = $this->objMOrder->updateOrderPayData([
- 'payStatus' => StatusCode::$standard,
- 'payTime' => time(),
- // 'orderStatus' => StatusCode::$orderStatus['waitDelivery']
- ], ['id' => [$orderId]]);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * todo(保存修改数据(废弃))
- * @throws \Exception
- */
- public function saveEdit()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMOrder->saveEdit($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 订单编辑(现在只能编辑订单支付金额)
- * @throws \Exception
- * @Deprecated
- */
- public function orderEdit()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'orderId' => isset($params['orderId']) ? $params['orderId'] : '',
- 'editAmount' => isset($params['editAmount']) ? $params['editAmount'] : '',//编辑后实付款金额
- ];
- foreach ($params as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMOrder->orderEdit($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="")
- * User: XMing
- * Date: 2020/12/21
- * Time: 11:06 上午
- * @throws \Exception
- */
- public function addSalesOrder()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'totalMoney' => isset($params['totalMoney']) ? $params['totalMoney'] : 0,//商品总金额
- 'totalReduceMoney' => isset($params['totalReduceMoney']) ? $params['totalReduceMoney'] : 0,
- 'payMoney' => isset($params['payAmount']) ? $params['payAmount'] : 0,//实付金额
- 'customerId' => isset($params['customerId']) ? $params['customerId'] : 0,//客户id
- 'userCenterId' => $this->onlineUserId,//客户当前用户id
- 'customerName' => isset($params['customerName']) ? $params['customerName'] : '',//客户名称
- 'customerType' => isset($params['customerType']) ? $params['customerType'] : 0,//客户类型
- 'receiveAddressId' => isset($params['receiveAddressId']) ? $params['receiveAddressId'] : 0,//客户类型
- 'source' => isset($params['source']) ? $params['source'] : StatusCode::$source['manage'],//订单来源
- 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : StatusCode::$deliveryType['selfMention'],
- 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : [],//商品数据,
- 'isEnablePrint' => isset($params['isEnablePrint']) ? $params['isEnablePrint'] : StatusCode::$delete,
- 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
- 'operatorId' => $this->loginUserCenterId,
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !='' && $value != 0) {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['accountList'] = isset($params['accountList']) ? $params['accountList'] : [];
- $data['currentAccountName'] = isset($params['currentAccountName']) ? $params['currentAccountName'] : '';
- $data['receivedMoney'] = isset($params['receivedMoney']) ? $params['receivedMoney'] : 0;
- $data['lists'] = $data['goodsData'];
- unset($data['goodsData']);
- //验证商品
- $dbResult = $this->objMCart->checkCart($data['lists']);
- if (!$dbResult->isSuccess()) {
- parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
- }
- $data['remark'] = isset($params['remark']) ? $params['remark'] : '';//销售单备注
- $data['orderType'] = StatusCode::$orderType['salesSlip'];
- $result = $this->objMOrder->add($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * Doc: (des="分配业务员")
- * User: XMing
- * Date: 2020/8/26
- * Time: 3:35 下午
- * @throws \Exception
- */
- public function setSalesMan()
- {
- $params = $this->request->getRawJson();
- $data = [
- 'orderId' => isset($params['orderId']) ? $params['orderId'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $data['ifSalesMan'] = isset($params['ifSalesMan']) ? $params['ifSalesMan'] : StatusCode::$delete;
- isset($params['salesManId']) && $data['salesManId'] = $params['salesManId'];
- isset($params['salesManName']) && $data['salesManName'] = $params['salesManName'];
- $result = $this->objMOrder->setSalesMan($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- /**
- * 销售毛利汇总
- * @throws \Exception
- */
- public function getOrderProfit()
- {
- $params = $this->request->getRawJson();
- $data = [
- 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
- 'goodsId' => isset($params['goodsId']) ? $params['goodsId'] : '',
- 'start' => isset($params['start']) ? $params['start'] : '',
- 'end' => isset($params['end']) ? $params['end'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $data['limit'] = $pageParams['limit'];
- $data['offset'] = $pageParams['offset'];
- if(isset($params['customerId']) && !empty($params['customerId'])){
- $data['customerId'] = $params['customerId'];
- }
- $export = isset($params['export']) ? $params['export'] : 0;
- $result = $this->objMOrder->getOrderProfit($data,$export);
- 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(), ErrorCode::$dberror);
- }
- }
- /**
- * Doc: (des="收银台创建订单 会直接创建收款单")
- * User: XMing
- * Date: 2020/9/1
- * Time: 5:24 下午
- * @throws \Exception
- */
- public function cashierOrder()
- {
- $userCenterId = $this->request->param('userCenterId');
- if (empty($userCenterId)){
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $objMOrder = new MOrder($userCenterId,$this->onlineEnterpriseId,$this->onlineUserId,false,true);
- $params = $this->request->getRawJson();
- if (empty($params)){
- parent::sendOutput('参数为空',ErrorCode::$paramError);
- }
- $orderData = [
- 'payType' => isset($params['payType']) ? $params['payType'] : null,
- 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : null,
- 'userCenterId' => $userCenterId,
- 'customerId' => isset($params['customerId']) ? $params['customerId'] : 0,
- 'customerName' => isset($params['customerName']) ? $params['customerName'] : '',
- 'source' => isset($params['source']) ? $params['source'] : null,//订单来源
- 'cashierUid' => $this->onlineUserId,//当前收银员id
- 'isEnablePrint' => isset($params['isEnablePrint']) ? $params['isEnablePrint'] : StatusCode::$delete,
- 'guideUids' => isset($params['guideUids']) ? $params['guideUids'] : 0,//导购员ids
- 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : [],//商品数据json(包含信息有以下字段)
- 'remark' => isset($params['orderRemark']) ? $params['orderRemark'] : '',
- 'accountList' => isset($params['accountList']) ? $params['accountList'] : null,//收款账户
- 'currentAccountName' => isset($params['currentAccountName']) ? $params['currentAccountName'] : '',
- 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
- 'operatorId' => $this->loginUserCenterId,
- ];
- foreach ($orderData as $key => $value) {
- if (empty($value) && $value !== 0 && $value != '') {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $objMOrder->cashierOrder($orderData);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * Doc: (des="第一步--创建订单")
- * User: XMing
- * Date: 2020/10/12
- * Time: 4:01 下午
- * @throws \Exception
- */
- public function create()
- {
- $userCenterId = $this->request->param('userCenterId');
- if (empty($userCenterId)){
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $objMOrder = new MOrder($userCenterId,$this->onlineEnterpriseId,$this->onlineUserId,false,true);
- $params = $this->request->getRawJson();
- if (empty($params)){
- parent::sendOutput('参数为空',ErrorCode::$paramError);
- }
- $orderData = [
- 'payType' => '',
- 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : null,
- 'userCenterId' => $userCenterId,
- 'customerId' => isset($params['customerId']) ? $params['customerId'] : 0,
- 'customerName' => isset($params['customerName']) ? $params['customerName'] : '',
- 'source' => isset($params['source']) ? $params['source'] : null,//订单来源
- 'cashierUid' => $this->onlineUserId,//当前收银员id
- 'isEnablePrint' => isset($params['isEnablePrint']) ? $params['isEnablePrint'] : StatusCode::$delete,
- 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : [],//商品数据json(包含信息有以下字段)
- 'remark' => isset($params['orderRemark']) ? $params['orderRemark'] : '',
- 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
- 'operatorId' => $this->loginUserCenterId,
- ];
- foreach ($orderData as $key => $value) {
- if (empty($value) && $value !== 0 && $value != '') {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $objMOrder->create($orderData);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * Doc: (des="第二步--确认订单收款")
- * User: XMing
- * Date: 2020/10/12
- * Time: 3:48 下午
- * @throws \Exception
- */
- public function confirm()
- {
- $userCenterId = $this->request->param('userCenterId');
- if (empty($userCenterId)){
- $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
- }
- $objMOrder = new MOrder($userCenterId,$this->onlineEnterpriseId,$this->onlineUserId,false,true);
- $params = $this->request->getRawJson();
- if (empty($params)){
- parent::sendOutput('参数为空',ErrorCode::$paramError);
- }
- $data = [
- 'payType' => isset($params['payType']) ? $params['payType'] : null,//支付方式
- 'orderId' => isset($params['orderId']) ? $params['orderId'] : null,//订单id
- 'cashierUid' => $this->onlineUserId,//当前收银员id
- 'guideUids' => isset($params['guideUids']) ? $params['guideUids'] : 0,//导购员ids
- 'accountList' => isset($params['accountList']) ? $params['accountList'] : null,//收款账户
- 'currentAccountName' => isset($params['currentAccountName']) ? $params['currentAccountName'] : '',//收款账户名称
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0 && $value != '') {
- parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $objMOrder->confirm($data);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * Doc: (des="通过核销码获取订单")
- * User: XMing
- * Date: 2020/9/4
- * Time: 2:06 下午
- * @throws \Exception
- */
- public function getOrderByVerifyCode()
- {
- $params = $this->request->getRawJson();
- if (!isset($params['verifyCode']) || empty($params['verifyCode'])){
- parent::sendOutput('verifyCode参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMOrder->getOrderByVerifyCode($params['verifyCode']);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * Doc: (des="订单核销")
- * User: XMing
- * Date: 2020/9/4
- * Time: 2:25 下午
- * @throws \Exception
- */
- public function verification()
- {
- $orderId = $this->request->param('request_id');
- if (empty($orderId)){
- parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMOrder->verification($orderId,[
- 'Token' => $this->token,
- 'Authorization' => $this->authorization
- ]);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * Doc: (des="修改订单的发货信息")
- * User: XMing
- * Date: 2020/9/9
- * Time: 11:43 上午
- * @throws \Exception
- */
- public function editOrderExpress()
- {
- $orderId = $this->request->param('request_id');
- if (empty($orderId)){
- parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
- }
- $params = $this->request->getRawJson();
- $result = $this->objMOrder->editOrderExpress('',$params,$orderId);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- public function fix_es()
- {
- $this->objMOrder->fix_ex();
- }
- /**
- * Doc: (des="")
- * User: XMing
- * Date: 2021/1/20
- * Time: 7:51 下午
- */
- public function statistics()
- {
- $page = $this->request->param('page') ?: 1;
- $pageSize = $this->request->param('pageSize') ?: 10;
- $params['start'] = $this->request->param('start');
- $params['end'] = $this->request->param('end');
- $offset = ($page - 1) * $pageSize;
- $params['limit'] = $pageSize;
- $params['offset'] = $offset;
- $orderData = $this->objMOrder->getStatistics($params);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- /**
- * Doc: (des="已经审核未出库的订单,审核驳回")
- * User: XMing
- * Date: 2021/2/25
- * Time: 9:39 上午
- * @throws \Exception
- */
- public function revokeAudit()
- {
- $orderId = $this->request->param('request_id');
- if (empty($orderId)){
- parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMOrder->revokeAudit($orderId);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * Doc: (des="再次出库")
- * User: XMing
- * Date: 2021/3/9
- * Time: 5:06 下午
- * @throws \Exception
- */
- public function reStockOut()
- {
- $orderId = $this->request->param('request_id');
- if (empty($orderId)){
- parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMOrder->reStockOut($orderId);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * Doc: (des="缺货订单列表")
- * User: XMing
- * Date: 2021/3/11
- * Time: 6:42 下午
- * @throws \Exception
- */
- public function getDistributionAll()
- {
- $params = $this->request->getRawJson();
- $page = isset($params['page']) ? $params['page'] : 1;
- $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
- $offset = ($page - 1) * $pageSize;
- $params['limit'] = $pageSize;
- $params['offset'] = $offset;
- $orderData = $this->objMOrder->getDistributionAll($params);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- /**
- * 一键退款
- * @throws \Exception
- */
- public function retAmount()
- {
- $params = $this->request->getRawJson();
- if (empty($params)){
- parent::sendOutput('参数错误',ErrorCode::$paramError);
- }
- if (!isset($params['orderId']) || empty($params['orderId'])){
- parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMOrder->retAmount($params['orderId']);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 设置物流信息
- *
- */
- public function addLogistics()
- {
- $params = $this->request->getRawJson();
- if (empty($params)){
- parent::sendOutput('参数错误',ErrorCode::$paramError);
- }
-
- if (!isset($params['orderId']) || empty($params['orderId'])){
- parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMOrder->addLogistics($params);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- }
|