Order.Class.php 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
  1. <?php
  2. /**
  3. * 订单中心
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/10/31
  7. * Time: 15:46
  8. */
  9. namespace JinDouYun\Controller\Order;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Controller\BaseController;
  13. use JinDouYun\Model\Cart\MCart;
  14. use JinDouYun\Model\Goods\MGoods;
  15. use JinDouYun\Model\GoodsManage\MSku;
  16. use JinDouYun\Model\Order\MOrder;
  17. use Jindouyun\Model\Order\MOrderStatistics;
  18. /**
  19. * 这个是后台的需要url后加用户对应的customerId (与购物车一样)
  20. * Class Order
  21. * @package JinDouYun\Controller\Order
  22. */
  23. class Order extends BaseController
  24. {
  25. /**
  26. * @var MOrder
  27. */
  28. private $objMOrder;
  29. /**
  30. * @var MCart
  31. */
  32. private $objMCart;
  33. private $loginUserCenterId;
  34. /**
  35. * Order constructor.
  36. * @param bool $isCheckAcl
  37. * @param bool $isMustLogin
  38. * @throws \Exception
  39. */
  40. public function __construct($isCheckAcl = true, $isMustLogin = true)
  41. {
  42. parent::__construct($isCheckAcl, $isMustLogin);
  43. $this->loginUserCenterId = $this->onlineUserId;//获取登录后台用户的id
  44. $userCenterId = $this->request->param('request_id');//客户对应的userCenterId
  45. $this->onlineUserId = empty($userCenterId) ? $this->onlineUserId : $userCenterId;//防止产生0后缀的表
  46. $this->objMOrder = new MOrder($this->onlineUserId, $this->onlineEnterpriseId, $this->loginUserCenterId);
  47. $this->objMCart = new MCart($this->onlineUserId, $this->onlineEnterpriseId, false);
  48. }
  49. /**
  50. * 添加,编辑订单公共数据
  51. * @return array
  52. */
  53. public function commonFieldFilter()
  54. {
  55. $params = $this->request->getRawJson();
  56. if (empty($params)) {
  57. parent::sendOutput('参数为空', ErrorCode::$paramError);
  58. }
  59. $orderData = [
  60. 'payType' => isset($params['payType']) ? $params['payType'] : StatusCode::$payType['cashPay'],
  61. 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : '',
  62. 'receiveAddressId' => isset($params['receiveAddressId']) ? $params['receiveAddressId'] : '',//收货地址id
  63. 'source' => isset($params['source']) ? $params['source'] : 0,//订单来源
  64. 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : '',//商品数据json(包含信息有以下字段)
  65. ];
  66. foreach ($orderData as $key => $value) {
  67. if (empty($value) && $value !== 0) {
  68. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  69. }
  70. }
  71. $orderData['remark'] = isset($params['remark']) ? $params['remark'] : '';//订单备注
  72. $allGoodsData = [
  73. 'totalMoney' => isset($orderData['goodsData']['totalMoney']) ? $orderData['goodsData']['totalMoney'] : '',
  74. 'payMoney' => isset($orderData['goodsData']['payMoney']) ? $orderData['goodsData']['payMoney'] : '',
  75. 'preferential' => isset($orderData['goodsData']['preferential']) ? $orderData['goodsData']['preferential'] : '',
  76. 'checkNum' => isset($orderData['goodsData']['checkNum']) ? $orderData['goodsData']['checkNum'] : '',
  77. 'goodsData' => isset($orderData['goodsData']['goodsData']) ? $orderData['goodsData']['goodsData'] : '',
  78. ];
  79. foreach ($allGoodsData as $key => $value) {
  80. if (empty($value) && $value !== 0) {
  81. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  82. }
  83. }
  84. $allShopData = $allGoodsData['goodsData'];
  85. $goodsData = [];
  86. foreach ($allShopData as $key => $val) {
  87. $goodsData[$key] = [
  88. 'shopId' => isset($val['shopId']) ? $val['shopId'] : '',
  89. 'shopName' => isset($val['shopName']) ? $val['shopName'] : '',
  90. 'totalMoney' => isset($val['totalMoney']) ? $val['totalMoney'] : '',
  91. 'payMoney' => isset($val['payMoney']) ? $val['payMoney'] : '',
  92. 'shopGoodsData' => isset($val['shopGoodsData']) ? $val['shopGoodsData'] : '',
  93. ];
  94. foreach ($goodsData[$key] as $k => $v) {
  95. if (empty($v)) {
  96. parent::sendOutput($k . '参数错误', ErrorCode::$paramError);
  97. }
  98. if ($k == 'shopGoodsData'){
  99. if (isset($v['totalMoney']) && $v['totalMoney'] == 0){
  100. parent::sendOutput($v['goodsName'] . ',价格为0,不能进行购买', ErrorCode::$paramError);
  101. }
  102. }
  103. }
  104. }
  105. return $orderData;
  106. }
  107. /**
  108. * Doc: (des="后台代客下单")
  109. * User: XMing
  110. * Date: 2020/11/3
  111. * Time: 10:52 上午
  112. * @throws \Exception
  113. */
  114. public function add()
  115. {
  116. $params = $this->request->getRawJson();
  117. if (empty($params)) {
  118. parent::sendOutput('参数为空', ErrorCode::$paramError);
  119. }
  120. $data = [
  121. 'payType' => isset($params['payType']) ? $params['payType'] : StatusCode::$payType['cashPay'],
  122. 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : null,
  123. 'addressId' => isset($params['addressId']) ? $params['addressId'] : 0,
  124. 'source' => StatusCode::$source['manage'],
  125. 'lists' => isset($params['lists']) ? $params['lists'] : null,//商品
  126. 'totalMoney' => isset($params['totalMoney']) ? $params['totalMoney'] : null,
  127. 'payMoney' => isset($params['payMoney']) ? $params['payMoney'] : null,
  128. 'totalReduceMoney' => isset($params['totalReduceMoney']) ? $params['totalReduceMoney'] : null,
  129. 'userCenterId' => isset($params['userCenterId']) ? $params['userCenterId'] : null,
  130. 'customerId' => isset($params['customerId']) ? $params['customerId'] : null,
  131. 'customerName' => isset($params['customerName']) ? $params['customerName'] : null,
  132. 'selfRuleId' => isset($params['selfRuleId']) ? $params['selfRuleId'] : 0,
  133. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  134. 'operatorId' => $this->loginUserCenterId,
  135. ];
  136. foreach ($data as $key => $value) {
  137. if (is_null($value) && empty($value['selfRuleId'])) {
  138. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  139. }
  140. }
  141. $data['selfRuleData'] = getArrayItem($params, 'selfRuleData', []);
  142. $data['accountList'] = isset($params['accountList']) ? $params['accountList'] : [];
  143. $data['currentAccountName'] = isset($params['currentAccountName']) ? $params['currentAccountName'] : '';
  144. $data['receivedMoney'] = isset($params['receivedMoney']) ? $params['receivedMoney'] : 0;
  145. $data['remark'] = isset($params['remark']) ? $params['remark'] : '';
  146. $objMGoods = new MGoods($this->onlineEnterpriseId,true,$data['userCenterId']);
  147. $objMSku = new MSku($this->onlineUserId,$this->onlineEnterpriseId);
  148. $lists = $data['lists'];
  149. foreach ($lists as &$item){
  150. // 对抄码商品做单位转换处理
  151. if ($item['isEq'] == StatusCode::$standard){
  152. // 查询抄码商品的主单位sku数据
  153. $masterSkuResult = $objMSku->getMasterById($item['basicGoodsId']);
  154. if (!$masterSkuResult->isSuccess()){
  155. parent::sendOutput($masterSkuResult->getData(),$masterSkuResult->getErrorCode());
  156. }
  157. $masterSku = $masterSkuResult->getData();
  158. if (empty($masterSku)){
  159. parent::sendOutput('超码商品主单位获取异常',ErrorCode::$paramError);
  160. }
  161. //抄码商品为了支持主单位购买 不进行换算
  162. if($item['skuId'] != $masterSku['id']){
  163. //辅单位
  164. $conversion = $item['conversion'];
  165. $item['otherNum'] = $item['buyNum'];
  166. $u_1_buy = $item['buyNum'];//辅单位购买数量
  167. $item['buyNum'] = bcmul($item['buyNum'],$conversion,2);
  168. $item['salePrice'] = bcdiv($item['salePrice'],$conversion,2);
  169. $u = isset($masterSku['unitName']) ? $masterSku['unitName'] : '';//主单位名字
  170. $u_1 = $item['unitName'];//辅单位名字
  171. $uId_1 = $item['skuId'];//辅单位id
  172. $uId = $masterSku['id'];//主单位id
  173. $extends = ['uId' => $uId, 'uId_1' => $uId_1, 'u' => $u, 'u_1' => $u_1,'u_1_buy'=> $u_1_buy,'conversion' => $conversion];
  174. $item['extends'] = $extends;
  175. $item['skuId'] = $extends['uId'];
  176. $item['unitName'] = $extends['u'];
  177. }
  178. }
  179. }
  180. $data['lists'] = $lists;
  181. $result = $this->objMOrder->add($data);
  182. if ($result->isSuccess()) {
  183. parent::sendOutput($result->getData());
  184. }
  185. parent::sendOutput($result->getData(), $result->getErrorCode());
  186. }
  187. /**
  188. * Doc: (des="编辑")
  189. * User: XMing
  190. * Date: 2020/11/5
  191. * Time: 9:39 上午
  192. * @throws \Exception
  193. */
  194. public function edit()
  195. {
  196. $orderId = $this->request->param('request_id');
  197. if (!$orderId) {
  198. parent::sendOutput('参数错误', ErrorCode::$paramError);
  199. }
  200. $params = $this->request->getRawJson();
  201. if (empty($params)){
  202. parent::sendOutput('参数为空',ErrorCode::$paramError);
  203. }
  204. $params['goodsData'] = self::transFormatGoods($params['goodsData']);
  205. $result = $this->objMOrder->edit($params,$orderId);
  206. if ($result->isSuccess()) {
  207. parent::sendOutput($result->getData());
  208. }
  209. parent::sendOutput($result->getData(), $result->getErrorCode());
  210. }
  211. /**
  212. * Doc: (des="格式化参数,转换为统一参数")
  213. * User: XMing
  214. * Date: 2021/1/5
  215. * Time: 10:00 上午
  216. * @param array $lists
  217. * @return array
  218. */
  219. public function transFormatGoods(array $lists): array
  220. {
  221. if (empty($lists)){
  222. return $lists;
  223. }
  224. foreach ($lists as &$list){
  225. if (isset($list['goodsBasicId']) && !empty($list['goodsBasicId'])){
  226. $list['materielId'] = $list['goodsBasicId'];
  227. }
  228. if (isset($list['basicGoodsId']) && !empty($list['basicGoodsId'])){
  229. $list['materielId'] = $list['basicGoodsId'];
  230. }
  231. if (!isset($list['materielId']) || empty($list['materielId'])){
  232. self::sendOutput('materielId参数错误',ErrorCode::$paramError);
  233. }
  234. }
  235. return $lists;
  236. }
  237. /**
  238. * 获取指定订单详情
  239. * @throws \Exception
  240. */
  241. public function getOrderInfoById()
  242. {
  243. $orderId = $this->request->param('orderId');
  244. if (!$orderId) {
  245. $this->sendOutput('参数错误', ErrorCode::$paramError);
  246. }
  247. $result = $this->objMOrder->getOrderInfoById($orderId);
  248. if ($result->isSuccess()) {
  249. parent::sendOutput($result->getData());
  250. }
  251. parent::sendOutput($result->getData(), $result->getErrorCode());
  252. }
  253. /**
  254. * Doc: (des="批量获取订单详情")
  255. * User: XMing
  256. * Date: 2021/3/31
  257. * Time: 10:22 上午
  258. * @throws \Exception
  259. */
  260. public function getOrderInfoByIds()
  261. {
  262. $params = $this->request->getRawJson();
  263. if (!isset($params['ids']) || empty($params['ids'])){
  264. parent::sendOutput('ids参数错误',ErrorCode::$paramError);
  265. }
  266. $orderIds = $params['ids'];
  267. $arrayLists = [];
  268. foreach ($orderIds as $id){
  269. $result = $this->objMOrder->getOrderInfoById($id);
  270. if (!$result->isSuccess()) {
  271. parent::sendOutput($result->getData(),$result->getErrorCode());
  272. }
  273. $arrayLists[] = (array)$result->getData();
  274. }
  275. parent::sendOutput($arrayLists);
  276. }
  277. /**
  278. * Doc: (des="获取所有订单")
  279. * User: XMing
  280. * Date: 2020/7/15
  281. * Time: 10:34 上午
  282. * @waitAudit:等待审核 orderStatus != 6 auditStatus = 1
  283. * @waitOutStock:待出库 orderStatus != 6 auditPass = 2
  284. * @hasOutStock:已出库 orderStatus = 4 auditPass = 2
  285. * @finish:已完成 orderStatus = 5 auditPass 2
  286. * @close:已关闭 orderStatus = 6
  287. * @all:全部订单
  288. * @throws \Exception
  289. * @throws \Exception
  290. * @return mixed
  291. */
  292. public function getAllOrder()
  293. {
  294. $paramsData = $this->request->getRawJson();
  295. $params = [
  296. 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
  297. 'page' => isset($paramsData['page']) ? $paramsData['page'] : 1,
  298. ];
  299. foreach ($params as $key => $value) {
  300. if (empty($value) && $value !== 0) {
  301. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  302. }
  303. }
  304. $params['search'] = isset($paramsData['search']) ? $paramsData['search'] : [];
  305. $offset = ($params['page'] - 1) * $params['pageSize'];
  306. $selectParams = [
  307. 'limit' => $params['pageSize'],
  308. 'offset' => $offset,
  309. ];
  310. (isset($paramsData['state']) && !empty($paramsData['state'])) && $selectParams['state'] = $paramsData['state'];//参数说明见方法注解
  311. (isset($paramsData['orderStatus']) && !empty($paramsData['orderStatus'])) && $selectParams['orderStatus'] = $paramsData['orderStatus'];
  312. (isset($paramsData['outStatus']) && !empty($paramsData['outStatus'])) && $selectParams['outStatus'] = $paramsData['outStatus'];
  313. isset($paramsData['returnStatus']) && $selectParams['returnStatus'] = $paramsData['returnStatus'];
  314. isset($paramsData['shopId']) && $selectParams['shopId'] = $paramsData['shopId'];
  315. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  316. $is_export = false;
  317. if (isset($paramsData['export']) && $paramsData['export'] == 1) $is_export = true;
  318. //根据订单编号查找商品
  319. if( !empty($paramsData['order'])){
  320. $selectParams['no'] = explode('-',$paramsData['order']);
  321. $selectParams['no'] = $selectParams ['no'][1].'-'.$selectParams ['no'][2];
  322. unset($selectParams['order']);
  323. }
  324. $orderData = $this->objMOrder->getAllOrder($selectParams, $params['search'], $is_export);
  325. if ($orderData->isSuccess()) {
  326. $returnData = $orderData->getData();
  327. $pageData = [
  328. 'pageIndex' => $params['page'],
  329. 'pageSize' => $params['pageSize'],
  330. 'pageTotal' => $returnData['total'],
  331. ];
  332. parent::sendOutput($returnData['data'], 0, $pageData);
  333. }
  334. parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
  335. }
  336. /**
  337. * Doc: (des="获取检索订单数据")
  338. * 订单列表搜索商品名称、商品编码、收货人、电话
  339. * @waitAudit:等待审核 orderStatus != 6 auditStatus = 1
  340. * @waitOutStock:待出库 orderStatus != 6 auditPass = 2
  341. * @hasOutStock:已出库 orderStatus = 4 auditPass = 2
  342. * @finish:已完成 orderStatus = 5 auditPass 2
  343. * @close:已关闭 orderStatus = 6
  344. *
  345. */
  346. public function keywordSearch()
  347. {
  348. $paramsData = $this->request->getRawJson();
  349. $params = [
  350. 'pageSize' => isset($paramsData['pageSize']) ? $paramsData['pageSize'] : 10,
  351. 'page' => isset($paramsData['page']) ? $paramsData['page'] : 1,
  352. ];
  353. $offset = ($params['page'] - 1) * $params['pageSize'];
  354. $selectParams = [
  355. 'limit' => $params['pageSize'],
  356. 'offset' => $offset,
  357. ];
  358. foreach ($selectParams as $key => $value) {
  359. if (empty($value) && $value !== 0) {
  360. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  361. }
  362. }
  363. $selectParams['keywordType'] = getArrayItem($paramsData,'keywordType',1);
  364. $selectParams['keyword'] = getArrayItem($paramsData,'keyword','');
  365. $selectParams['startTime'] = getArrayItem($paramsData,'startTime','');
  366. $selectParams['endTime'] = getArrayItem($paramsData,'endTime','');
  367. $selectParams['userCenterId'] = getArrayItem($paramsData,'userCenterId','');
  368. $selectParams['customerId'] = getArrayItem($paramsData,'customerId','');
  369. $selectParams['shopId'] = getArrayItem($paramsData,'shopId','');
  370. $selectParams['payType'] = getArrayItem($paramsData,'payType',''); // 支付方式 1微信 2支付宝 3货到付款 4上门自提
  371. $selectParams['customerType'] = getArrayItem($paramsData,'customerType','');
  372. $selectParams['source'] = getArrayItem($paramsData,'source',''); // 订单来源 订单来源 默认1 ios 2android 3小程序 4后台创建
  373. $selectParams['state'] = getArrayItem($paramsData,'state',[]);//参数说明见方法注解
  374. $selectParams['payStatus'] = getArrayItem($paramsData,'payStatus');//支付状态 默认4 未支付 5已支付
  375. $selectParams['outStatus'] = getArrayItem($paramsData,'outStatus',''); //出库状态 4:未出库 5:已出库 6部分出库
  376. $selectParams['returnStatus'] = getArrayItem($paramsData,'returnStatus',[]); //退货状态 0:未退货 1:部分退货 2:全部退货
  377. $export = getArrayItem($paramsData,'export','');
  378. $orderData = $this->objMOrder->keywordSearch($selectParams,$export);
  379. if ($orderData->isSuccess()) {
  380. $returnData = $orderData->getData();
  381. $pageData = [
  382. 'pageIndex' => $params['page'],
  383. 'pageSize' => $params['pageSize'],
  384. 'pageTotal' => $returnData['total'],
  385. ];
  386. parent::sendOutput($returnData['data'], 0, $pageData);
  387. }
  388. parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
  389. }
  390. /**
  391. * 销售订单汇总
  392. * @throws \Exception
  393. */
  394. public function getAllOrderData()
  395. {
  396. $params = $this->request->getRawJson();
  397. $page = $params['page'] ?: 1;
  398. $pageSize = $params['pageSize'] ?: 10;
  399. $offset = ($page - 1) * $pageSize;
  400. $selectParams = [
  401. 'limit' => $pageSize,
  402. 'offset' => $offset,
  403. ];
  404. isset($params['outStatus']) && $selectParams['outStatus'] = $params['outStatus'];
  405. isset($params['goodsName']) && $selectParams['goodsName'] = $params['goodsName'];
  406. isset($params['categoryId']) && $selectParams['categoryId'] = $params['categoryId'];
  407. isset($params['customerId']) && $selectParams['customerId'] = $params['customerId'];
  408. isset($params['shopId']) && $selectParams['shopId'] = $params['shopId'];
  409. isset($params['start']) && $selectParams['start'] = $params['start'];
  410. isset($params['end']) && $selectParams['end'] = $params['end'];
  411. $this->shopId && $selectParams['shopId'] = $this->shopId;
  412. $selectParams['onReturn'] = isset($params['onReturn']) ? $params['onReturn'] : 0;
  413. $type = isset($params['type']) ? $params['type'] : 0;
  414. $export = isset($params['export']) ? $params['export'] : 0;
  415. $objMOrderStatistics = new MOrderStatistics($this->onlineUserId, $this->onlineEnterpriseId);
  416. $orderData = $objMOrderStatistics->getAllOrderData($selectParams, $type, $export);
  417. if ($orderData->isSuccess()) {
  418. $returnData = $orderData->getData();
  419. $pageData = [
  420. 'pageIndex' => $page,
  421. 'pageSize' => $pageSize,
  422. 'pageTotal' => $returnData['total'],
  423. ];
  424. parent::sendOutput($returnData['data'], 0, $pageData);
  425. }
  426. parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
  427. }
  428. //测试定时统计
  429. public function setOrderView()
  430. {
  431. $objMOrderStatistics = new MOrderStatistics($this->onlineUserId, $this->onlineEnterpriseId);
  432. $dbResult = $objMOrderStatistics->setOrderView();
  433. if (!$dbResult->isSuccess()) {
  434. parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
  435. }
  436. parent::sendOutput($dbResult->getData());
  437. }
  438. /**
  439. * Doc: (des="更新订单审核状态,通过/驳回(不支持批量)")
  440. * User: XMing
  441. * Date: 2020/7/14
  442. * Time: 6:29 下午
  443. * @throws \Exception
  444. */
  445. public function updateAuditStatus()
  446. {
  447. $paramsData = $this->request->getRawJson();
  448. $params = [
  449. 'id' => isset($paramsData['orderId']) ? $paramsData['orderId'] : '',
  450. 'audit' => isset($paramsData['audit']) ? $paramsData['audit'] : '',
  451. 'auditId' => $this->onlineUserId,
  452. 'auditStatus' => isset($paramsData['auditStatus']) ? $paramsData['auditStatus'] : '',//2通过 3驳回
  453. ];
  454. foreach ($params as $key => $value) {
  455. if (empty($value)) {
  456. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  457. }
  458. }
  459. $result = $this->objMOrder->updateAuditStatus($params);
  460. if ($result->isSuccess()) {
  461. parent::sendOutput($result->getData());
  462. }
  463. parent::sendOutput($result->getData(), $result->getErrorCode());
  464. }
  465. /**
  466. * 更新订单审核状态,(批量操作)
  467. * @throws \Exception
  468. */
  469. public function batchUpdateAuditStatus()
  470. {
  471. $paramsData = $this->request->getRawJson();
  472. $params = [
  473. 'ids' => isset($paramsData['orderIds']) ? $paramsData['orderIds'] : [],
  474. 'audit' => isset($paramsData['audit']) ? $paramsData['audit'] : '',
  475. 'auditId' => $this->onlineUserId,
  476. 'auditStatus' => isset($paramsData['auditStatus']) ? $paramsData['auditStatus'] : '',//2通过 3驳回
  477. ];
  478. foreach ($params as $key => $value) {
  479. if (empty($value)) {
  480. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  481. }
  482. }
  483. $result = $this->objMOrder->batchUpdateAuditStatus($params);
  484. if ($result->isSuccess()) {
  485. parent::sendOutput($result->getData());
  486. }
  487. parent::sendOutput($result->getData(), $result->getErrorCode());
  488. }
  489. /**
  490. * 更新订单状态
  491. * @throws \Exception
  492. */
  493. public function updateOrderStatus()
  494. {
  495. $params = $this->request->getRawJson();
  496. $params = [
  497. 'orderId' => $params['orderId'],
  498. 'orderStatus' => isset($params['orderStatus']) ? $params['orderStatus'] : StatusCode::$orderStatus['close'], // 不传时为取消订单
  499. 'cancelReason' => isset($params['cancelReason']) ? $params['cancelReason'] : '',
  500. 'cancelRejectReason' => isset($params['cancelRejectReason']) ? $params['cancelRejectReason'] : '',
  501. ];
  502. if (!$params['orderId']) {
  503. $this->sendOutput('orderId参数错误', ErrorCode::$paramError);
  504. }
  505. if( $params['orderStatus'] == StatusCode::$orderStatus['close'] && empty($params['cancelReason']) ){
  506. parent::sendOutput('请输入取消订单原因', ErrorCode::$paramError);
  507. }
  508. $orderId = $params['orderId'];unset($params['orderId']);
  509. $result = $this->objMOrder->updateOrderStatus($orderId, $params,[
  510. 'Token' => $this->token,
  511. 'Authorization' => $this->authorization
  512. ]);
  513. if ($result->isSuccess()) {
  514. parent::sendOutput($result->getData());
  515. }
  516. parent::sendOutput($result->getData(), $result->getErrorCode());
  517. }
  518. /**
  519. * 搜索
  520. * @waitAudit:等待审核 orderStatus != 6 auditStatus = 1
  521. * @waitOutStock:待出库 orderStatus != 6 auditPass = 2
  522. * @hasOutStock:已出库 orderStatus = 4 auditPass = 2
  523. * @finish:已完成 orderStatus = 5 auditPass 2
  524. * @close:已关闭 orderStatus = 6
  525. * @all:全部
  526. * @throws \Exception
  527. */
  528. public function search()
  529. {
  530. $params = $this->request->getRawJson();
  531. $selectParams = [
  532. 'state' => isset($params['state']) ? $params['state'] : '',//状态标示,见方法注解
  533. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',//订单编号,收货人,商品名称 ,销售员
  534. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  535. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  536. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  537. 'startTime' => isset($params['start']) ? $params['start'] : '',
  538. 'endTime' => isset($params['end']) ? $params['end'] : '',
  539. 'orderStatus' => isset($params['orderStatus']) ? $params['orderStatus'] : '',
  540. 'payType' => isset($params['payType']) ? $params['payType'] : '',
  541. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  542. 'customerType' => isset($params['customerType']) ? $params['customerType'] : '',
  543. 'source' => isset($params['source']) ? $params['source'] : '',
  544. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : '',
  545. 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : '',
  546. 'outStatus' => isset($params['outStatus']) ? $params['outStatus'] : '',
  547. 'returnStatus' => isset($params['returnStatus']) ? $params['returnStatus'] : '',
  548. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  549. 'orderType' => isset($params['orderType']) ? $params['orderType'] : '',
  550. ];
  551. $is_export = false;
  552. if (isset($params['export']) && $params['export'] == 1) $is_export = true;
  553. if (isset($this->shopId) && !empty($this->shopId)) $selectParams['shopId'] = $this->shopId;
  554. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  555. $selectParams['limit'] = $pageParams['limit'];
  556. $selectParams['offset'] = $pageParams['offset'];
  557. $result = $this->objMOrder->getAllOrder($selectParams,[],$is_export);
  558. //$result = $this->objMOrder->search($selectParams, $is_export);
  559. if ($result->isSuccess()) {
  560. $returnData = $result->getData();
  561. $pageData = [
  562. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  563. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  564. 'pageTotal' => $returnData['total'],
  565. ];
  566. parent::sendOutput($returnData['data'], 0, $pageData);
  567. }
  568. parent::sendOutput($result->getData(), $result->getErrorCode());
  569. }
  570. /**
  571. * 增加打印次数
  572. */
  573. public function printIncr()
  574. {
  575. $orderId = $this->request->param('orderId');
  576. if (!$orderId) {
  577. $this->sendOutput('参数错误', ErrorCode::$paramError);
  578. }
  579. $result = $this->objMOrder->printIncr($orderId);
  580. if ($result->isSuccess()) {
  581. parent::sendOutput($result->getData());
  582. }
  583. parent::sendOutput($result->getData(), $result->getErrorCode());
  584. }
  585. /**
  586. * (订单在待出库的状态下->确认收款->订单支付状态已付款->订单状态待出库(出库应该判断,订单是否已支付))
  587. * 修改订单的支付状态
  588. * @throws \Exception
  589. */
  590. public function updateOrderPayData()
  591. {
  592. $orderId = $this->request->param('orderId');
  593. if (!$orderId) {
  594. $this->sendOutput('参数错误', ErrorCode::$paramError);
  595. }
  596. $result = $this->objMOrder->checkOutOrderStatus($orderId);
  597. if (!$result->isSuccess()) {
  598. parent::sendOutput($result->getData(),$result->getErrorCode());
  599. }
  600. $result = $this->objMOrder->updateOrderPayData([
  601. 'payStatus' => StatusCode::$standard,
  602. 'payTime' => time(),
  603. // 'orderStatus' => StatusCode::$orderStatus['waitDelivery']
  604. ], ['id' => [$orderId]]);
  605. if ($result->isSuccess()) {
  606. parent::sendOutput($result->getData());
  607. }
  608. parent::sendOutput($result->getData(), $result->getErrorCode());
  609. }
  610. /**
  611. * todo(保存修改数据(废弃))
  612. * @throws \Exception
  613. */
  614. public function saveEdit()
  615. {
  616. $params = $this->request->getRawJson();
  617. if (empty($params)) {
  618. $this->sendOutput('参数为空', ErrorCode::$paramError);
  619. }
  620. $result = $this->objMOrder->saveEdit($params);
  621. if ($result->isSuccess()) {
  622. parent::sendOutput($result->getData());
  623. }
  624. parent::sendOutput($result->getData(), $result->getErrorCode());
  625. }
  626. /**
  627. * 订单编辑(现在只能编辑订单支付金额)
  628. * @throws \Exception
  629. * @Deprecated
  630. */
  631. public function orderEdit()
  632. {
  633. $params = $this->request->getRawJson();
  634. if (empty($params)) {
  635. $this->sendOutput('参数为空', ErrorCode::$paramError);
  636. }
  637. $data = [
  638. 'orderId' => isset($params['orderId']) ? $params['orderId'] : '',
  639. 'editAmount' => isset($params['editAmount']) ? $params['editAmount'] : '',//编辑后实付款金额
  640. ];
  641. foreach ($params as $key => $value) {
  642. if (empty($value)) {
  643. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  644. }
  645. }
  646. $result = $this->objMOrder->orderEdit($data);
  647. if ($result->isSuccess()) {
  648. parent::sendOutput($result->getData());
  649. }
  650. parent::sendOutput($result->getData(), $result->getErrorCode());
  651. }
  652. /**
  653. * Doc: (des="")
  654. * User: XMing
  655. * Date: 2020/12/21
  656. * Time: 11:06 上午
  657. * @throws \Exception
  658. */
  659. public function addSalesOrder()
  660. {
  661. $params = $this->request->getRawJson();
  662. if (empty($params)) {
  663. parent::sendOutput('参数为空', ErrorCode::$paramError);
  664. }
  665. $data = [
  666. 'totalMoney' => isset($params['totalMoney']) ? $params['totalMoney'] : 0,//商品总金额
  667. 'totalReduceMoney' => isset($params['totalReduceMoney']) ? $params['totalReduceMoney'] : 0,
  668. 'payMoney' => isset($params['payAmount']) ? $params['payAmount'] : 0,//实付金额
  669. 'customerId' => isset($params['customerId']) ? $params['customerId'] : 0,//客户id
  670. 'userCenterId' => $this->onlineUserId,//客户当前用户id
  671. 'customerName' => isset($params['customerName']) ? $params['customerName'] : '',//客户名称
  672. 'customerType' => isset($params['customerType']) ? $params['customerType'] : 0,//客户类型
  673. 'receiveAddressId' => isset($params['receiveAddressId']) ? $params['receiveAddressId'] : 0,//客户类型
  674. 'source' => isset($params['source']) ? $params['source'] : StatusCode::$source['manage'],//订单来源
  675. 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : StatusCode::$deliveryType['selfMention'],
  676. 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : [],//商品数据,
  677. 'isEnablePrint' => isset($params['isEnablePrint']) ? $params['isEnablePrint'] : StatusCode::$delete,
  678. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  679. 'operatorId' => $this->loginUserCenterId,
  680. ];
  681. foreach ($data as $key => $value) {
  682. if (empty($value) && $value !='' && $value != 0) {
  683. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  684. }
  685. }
  686. $data['accountList'] = isset($params['accountList']) ? $params['accountList'] : [];
  687. $data['currentAccountName'] = isset($params['currentAccountName']) ? $params['currentAccountName'] : '';
  688. $data['receivedMoney'] = isset($params['receivedMoney']) ? $params['receivedMoney'] : 0;
  689. $data['lists'] = $data['goodsData'];
  690. unset($data['goodsData']);
  691. //验证商品
  692. $dbResult = $this->objMCart->checkCart($data['lists']);
  693. if (!$dbResult->isSuccess()) {
  694. parent::sendOutput($dbResult->getData(), $dbResult->getErrorCode());
  695. }
  696. $data['remark'] = isset($params['remark']) ? $params['remark'] : '';//销售单备注
  697. $data['orderType'] = StatusCode::$orderType['salesSlip'];
  698. $result = $this->objMOrder->add($data);
  699. if ($result->isSuccess()) {
  700. parent::sendOutput($result->getData());
  701. }
  702. parent::sendOutput($result->getData(), $result->getErrorCode());
  703. }
  704. /**
  705. * Doc: (des="分配业务员")
  706. * User: XMing
  707. * Date: 2020/8/26
  708. * Time: 3:35 下午
  709. * @throws \Exception
  710. */
  711. public function setSalesMan()
  712. {
  713. $params = $this->request->getRawJson();
  714. $data = [
  715. 'orderId' => isset($params['orderId']) ? $params['orderId'] : '',
  716. ];
  717. foreach($data as $key => $value){
  718. if(empty($value)){
  719. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  720. }
  721. }
  722. $data['ifSalesMan'] = isset($params['ifSalesMan']) ? $params['ifSalesMan'] : StatusCode::$delete;
  723. isset($params['salesManId']) && $data['salesManId'] = $params['salesManId'];
  724. isset($params['salesManName']) && $data['salesManName'] = $params['salesManName'];
  725. $result = $this->objMOrder->setSalesMan($data);
  726. if ($result->isSuccess()) {
  727. parent::sendOutput($result->getData());
  728. }
  729. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  730. }
  731. /**
  732. * 销售毛利汇总
  733. * @throws \Exception
  734. */
  735. public function getOrderProfit()
  736. {
  737. $params = $this->request->getRawJson();
  738. $data = [
  739. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  740. 'goodsId' => isset($params['goodsId']) ? $params['goodsId'] : '',
  741. 'start' => isset($params['start']) ? $params['start'] : '',
  742. 'end' => isset($params['end']) ? $params['end'] : '',
  743. ];
  744. foreach($data as $key => $value){
  745. if(empty($value)){
  746. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  747. }
  748. }
  749. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  750. $data['limit'] = $pageParams['limit'];
  751. $data['offset'] = $pageParams['offset'];
  752. if(isset($params['customerId']) && !empty($params['customerId'])){
  753. $data['customerId'] = $params['customerId'];
  754. }
  755. $export = isset($params['export']) ? $params['export'] : 0;
  756. $result = $this->objMOrder->getOrderProfit($data,$export);
  757. if ($result->isSuccess()) {
  758. $returnData = $result->getData();
  759. $pageData = [
  760. 'pageIndex' => $params['page'],
  761. 'pageSize' => $params['pageSize'],
  762. 'pageTotal' => $returnData['total'],
  763. ];
  764. parent::sendOutput($returnData['data'], 0, $pageData);
  765. } else {
  766. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  767. }
  768. }
  769. /**
  770. * Doc: (des="收银台创建订单 会直接创建收款单")
  771. * User: XMing
  772. * Date: 2020/9/1
  773. * Time: 5:24 下午
  774. * @throws \Exception
  775. */
  776. public function cashierOrder()
  777. {
  778. $userCenterId = $this->request->param('userCenterId');
  779. if (empty($userCenterId)){
  780. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  781. }
  782. $objMOrder = new MOrder($userCenterId,$this->onlineEnterpriseId,$this->onlineUserId,false,true);
  783. $params = $this->request->getRawJson();
  784. if (empty($params)){
  785. parent::sendOutput('参数为空',ErrorCode::$paramError);
  786. }
  787. $orderData = [
  788. 'payType' => isset($params['payType']) ? $params['payType'] : null,
  789. 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : null,
  790. 'userCenterId' => $userCenterId,
  791. 'customerId' => isset($params['customerId']) ? $params['customerId'] : 0,
  792. 'customerName' => isset($params['customerName']) ? $params['customerName'] : '',
  793. 'source' => isset($params['source']) ? $params['source'] : null,//订单来源
  794. 'cashierUid' => $this->onlineUserId,//当前收银员id
  795. 'isEnablePrint' => isset($params['isEnablePrint']) ? $params['isEnablePrint'] : StatusCode::$delete,
  796. 'guideUids' => isset($params['guideUids']) ? $params['guideUids'] : 0,//导购员ids
  797. 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : [],//商品数据json(包含信息有以下字段)
  798. 'remark' => isset($params['orderRemark']) ? $params['orderRemark'] : '',
  799. 'accountList' => isset($params['accountList']) ? $params['accountList'] : null,//收款账户
  800. 'currentAccountName' => isset($params['currentAccountName']) ? $params['currentAccountName'] : '',
  801. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  802. 'operatorId' => $this->loginUserCenterId,
  803. ];
  804. foreach ($orderData as $key => $value) {
  805. if (empty($value) && $value !== 0 && $value != '') {
  806. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  807. }
  808. }
  809. $result = $objMOrder->cashierOrder($orderData);
  810. if (!$result->isSuccess()){
  811. parent::sendOutput($result->getData(),$result->getErrorCode());
  812. }
  813. parent::sendOutput($result->getData());
  814. }
  815. /**
  816. * Doc: (des="第一步--创建订单")
  817. * User: XMing
  818. * Date: 2020/10/12
  819. * Time: 4:01 下午
  820. * @throws \Exception
  821. */
  822. public function create()
  823. {
  824. $userCenterId = $this->request->param('userCenterId');
  825. if (empty($userCenterId)){
  826. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  827. }
  828. $objMOrder = new MOrder($userCenterId,$this->onlineEnterpriseId,$this->onlineUserId,false,true);
  829. $params = $this->request->getRawJson();
  830. if (empty($params)){
  831. parent::sendOutput('参数为空',ErrorCode::$paramError);
  832. }
  833. $orderData = [
  834. 'payType' => '',
  835. 'deliveryType' => isset($params['deliveryType']) ? $params['deliveryType'] : null,
  836. 'userCenterId' => $userCenterId,
  837. 'customerId' => isset($params['customerId']) ? $params['customerId'] : 0,
  838. 'customerName' => isset($params['customerName']) ? $params['customerName'] : '',
  839. 'source' => isset($params['source']) ? $params['source'] : null,//订单来源
  840. 'cashierUid' => $this->onlineUserId,//当前收银员id
  841. 'isEnablePrint' => isset($params['isEnablePrint']) ? $params['isEnablePrint'] : StatusCode::$delete,
  842. 'goodsData' => isset($params['goodsData']) ? $params['goodsData'] : [],//商品数据json(包含信息有以下字段)
  843. 'remark' => isset($params['orderRemark']) ? $params['orderRemark'] : '',
  844. 'operatorName' => isset($params['operatorName']) ? $params['operatorName'] : '',
  845. 'operatorId' => $this->loginUserCenterId,
  846. ];
  847. foreach ($orderData as $key => $value) {
  848. if (empty($value) && $value !== 0 && $value != '') {
  849. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  850. }
  851. }
  852. $result = $objMOrder->create($orderData);
  853. if (!$result->isSuccess()){
  854. parent::sendOutput($result->getData(),$result->getErrorCode());
  855. }
  856. parent::sendOutput($result->getData());
  857. }
  858. /**
  859. * Doc: (des="第二步--确认订单收款")
  860. * User: XMing
  861. * Date: 2020/10/12
  862. * Time: 3:48 下午
  863. * @throws \Exception
  864. */
  865. public function confirm()
  866. {
  867. $userCenterId = $this->request->param('userCenterId');
  868. if (empty($userCenterId)){
  869. $userCenterId = StatusCode::$noneUserCenter;//TODO(匿名用户,客户表中存一个匿名客户)
  870. }
  871. $objMOrder = new MOrder($userCenterId,$this->onlineEnterpriseId,$this->onlineUserId,false,true);
  872. $params = $this->request->getRawJson();
  873. if (empty($params)){
  874. parent::sendOutput('参数为空',ErrorCode::$paramError);
  875. }
  876. $data = [
  877. 'payType' => isset($params['payType']) ? $params['payType'] : null,//支付方式
  878. 'orderId' => isset($params['orderId']) ? $params['orderId'] : null,//订单id
  879. 'cashierUid' => $this->onlineUserId,//当前收银员id
  880. 'guideUids' => isset($params['guideUids']) ? $params['guideUids'] : 0,//导购员ids
  881. 'accountList' => isset($params['accountList']) ? $params['accountList'] : null,//收款账户
  882. 'currentAccountName' => isset($params['currentAccountName']) ? $params['currentAccountName'] : '',//收款账户名称
  883. ];
  884. foreach ($data as $key => $value) {
  885. if (empty($value) && $value !== 0 && $value != '') {
  886. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  887. }
  888. }
  889. $result = $objMOrder->confirm($data);
  890. if (!$result->isSuccess()){
  891. parent::sendOutput($result->getData(),$result->getErrorCode());
  892. }
  893. parent::sendOutput($result->getData());
  894. }
  895. /**
  896. * Doc: (des="通过核销码获取订单")
  897. * User: XMing
  898. * Date: 2020/9/4
  899. * Time: 2:06 下午
  900. * @throws \Exception
  901. */
  902. public function getOrderByVerifyCode()
  903. {
  904. $params = $this->request->getRawJson();
  905. if (!isset($params['verifyCode']) || empty($params['verifyCode'])){
  906. parent::sendOutput('verifyCode参数错误',ErrorCode::$paramError);
  907. }
  908. $result = $this->objMOrder->getOrderByVerifyCode($params['verifyCode']);
  909. if (!$result->isSuccess()){
  910. parent::sendOutput($result->getData(),$result->getErrorCode());
  911. }
  912. parent::sendOutput($result->getData());
  913. }
  914. /**
  915. * Doc: (des="订单核销")
  916. * User: XMing
  917. * Date: 2020/9/4
  918. * Time: 2:25 下午
  919. * @throws \Exception
  920. */
  921. public function verification()
  922. {
  923. $orderId = $this->request->param('request_id');
  924. if (empty($orderId)){
  925. parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
  926. }
  927. $result = $this->objMOrder->verification($orderId,[
  928. 'Token' => $this->token,
  929. 'Authorization' => $this->authorization
  930. ]);
  931. if (!$result->isSuccess()){
  932. parent::sendOutput($result->getData(),$result->getErrorCode());
  933. }
  934. parent::sendOutput($result->getData());
  935. }
  936. /**
  937. * Doc: (des="修改订单的发货信息")
  938. * User: XMing
  939. * Date: 2020/9/9
  940. * Time: 11:43 上午
  941. * @throws \Exception
  942. */
  943. public function editOrderExpress()
  944. {
  945. $orderId = $this->request->param('request_id');
  946. if (empty($orderId)){
  947. parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
  948. }
  949. $params = $this->request->getRawJson();
  950. $result = $this->objMOrder->editOrderExpress('',$params,$orderId);
  951. if (!$result->isSuccess()){
  952. parent::sendOutput($result->getData(),$result->getErrorCode());
  953. }
  954. parent::sendOutput($result->getData());
  955. }
  956. public function fix_es()
  957. {
  958. $this->objMOrder->fix_ex();
  959. }
  960. /**
  961. * Doc: (des="")
  962. * User: XMing
  963. * Date: 2021/1/20
  964. * Time: 7:51 下午
  965. */
  966. public function statistics()
  967. {
  968. $page = $this->request->param('page') ?: 1;
  969. $pageSize = $this->request->param('pageSize') ?: 10;
  970. $params['start'] = $this->request->param('start');
  971. $params['end'] = $this->request->param('end');
  972. $offset = ($page - 1) * $pageSize;
  973. $params['limit'] = $pageSize;
  974. $params['offset'] = $offset;
  975. $orderData = $this->objMOrder->getStatistics($params);
  976. if ($orderData->isSuccess()) {
  977. $returnData = $orderData->getData();
  978. $pageData = [
  979. 'pageIndex' => $page,
  980. 'pageSize' => $pageSize,
  981. 'pageTotal' => $returnData['total'],
  982. ];
  983. parent::sendOutput($returnData['data'], 0, $pageData);
  984. }
  985. parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
  986. }
  987. /**
  988. * Doc: (des="已经审核未出库的订单,审核驳回")
  989. * User: XMing
  990. * Date: 2021/2/25
  991. * Time: 9:39 上午
  992. * @throws \Exception
  993. */
  994. public function revokeAudit()
  995. {
  996. $orderId = $this->request->param('request_id');
  997. if (empty($orderId)){
  998. parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
  999. }
  1000. $result = $this->objMOrder->revokeAudit($orderId);
  1001. if (!$result->isSuccess()){
  1002. parent::sendOutput($result->getData(),$result->getErrorCode());
  1003. }
  1004. parent::sendOutput($result->getData());
  1005. }
  1006. /**
  1007. * Doc: (des="再次出库")
  1008. * User: XMing
  1009. * Date: 2021/3/9
  1010. * Time: 5:06 下午
  1011. * @throws \Exception
  1012. */
  1013. public function reStockOut()
  1014. {
  1015. $orderId = $this->request->param('request_id');
  1016. if (empty($orderId)){
  1017. parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
  1018. }
  1019. $result = $this->objMOrder->reStockOut($orderId);
  1020. if (!$result->isSuccess()){
  1021. parent::sendOutput($result->getData(),$result->getErrorCode());
  1022. }
  1023. parent::sendOutput($result->getData());
  1024. }
  1025. /**
  1026. * Doc: (des="缺货订单列表")
  1027. * User: XMing
  1028. * Date: 2021/3/11
  1029. * Time: 6:42 下午
  1030. * @throws \Exception
  1031. */
  1032. public function getDistributionAll()
  1033. {
  1034. $params = $this->request->getRawJson();
  1035. $page = isset($params['page']) ? $params['page'] : 1;
  1036. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  1037. $offset = ($page - 1) * $pageSize;
  1038. $params['limit'] = $pageSize;
  1039. $params['offset'] = $offset;
  1040. $orderData = $this->objMOrder->getDistributionAll($params);
  1041. if ($orderData->isSuccess()) {
  1042. $returnData = $orderData->getData();
  1043. $pageData = [
  1044. 'pageIndex' => $page,
  1045. 'pageSize' => $pageSize,
  1046. 'pageTotal' => $returnData['total'],
  1047. ];
  1048. parent::sendOutput($returnData['data'], 0, $pageData);
  1049. }
  1050. parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
  1051. }
  1052. /**
  1053. * 一键退款
  1054. * @throws \Exception
  1055. */
  1056. public function retAmount()
  1057. {
  1058. $params = $this->request->getRawJson();
  1059. if (empty($params)){
  1060. parent::sendOutput('参数错误',ErrorCode::$paramError);
  1061. }
  1062. if (!isset($params['orderId']) || empty($params['orderId'])){
  1063. parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
  1064. }
  1065. $result = $this->objMOrder->retAmount($params['orderId']);
  1066. if (!$result->isSuccess()){
  1067. parent::sendOutput($result->getData(),$result->getErrorCode());
  1068. }
  1069. parent::sendOutput($result->getData());
  1070. }
  1071. /**
  1072. * 设置物流信息
  1073. *
  1074. */
  1075. public function addLogistics()
  1076. {
  1077. $params = $this->request->getRawJson();
  1078. if (empty($params)){
  1079. parent::sendOutput('参数错误',ErrorCode::$paramError);
  1080. }
  1081. if (!isset($params['orderId']) || empty($params['orderId'])){
  1082. parent::sendOutput('orderId参数错误',ErrorCode::$paramError);
  1083. }
  1084. $result = $this->objMOrder->addLogistics($params);
  1085. if (!$result->isSuccess()){
  1086. parent::sendOutput($result->getData(),$result->getErrorCode());
  1087. }
  1088. parent::sendOutput($result->getData());
  1089. }
  1090. }