TStdOrder.Class.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. <?php
  2. namespace JinDouYun\Model\Order;
  3. use JinDouYun\Cache\Stock;
  4. use JinDouYun\Controller\Common\Logger;
  5. use JinDouYun\Dao\Order\DSupplierOrderDetails;
  6. use JinDouYun\Dao\Order\DSupplierOrderIndex;
  7. use JinDouYun\Model\Cart\MCart;
  8. use JinDouYun\Model\Customer\MCustomer;
  9. use JinDouYun\Model\Customer\MShippingAddress;
  10. use JinDouYun\Model\Finance\MCustomerBalance;
  11. use JinDouYun\Model\Goods\MGoods;
  12. use JinDouYun\Model\Market\MComBinPackage;
  13. use JinDouYun\Model\Market\MUserCoupon;
  14. use JinDouYun\Model\Purchase\MPurchase;
  15. use JinDouYun\Model\Purchase\MSupplier;
  16. use JinDouYun\Model\Stock\MInventory;
  17. use JinDouYun\Model\Stock\MInventoryOut;
  18. use JinDouYun\Model\Stock\MReservoirArea;
  19. use JinDouYun\Model\System\MBasicSetup;
  20. use JinDouYun\Model\System\MDeliverySetting;
  21. use Mall\Framework\Core\ErrorCode;
  22. use Mall\Framework\Core\ResultWrapper;
  23. use Mall\Framework\Core\StatusCode;
  24. use phpDocumentor\Reflection\Types\Self_;
  25. trait TStdOrder
  26. {
  27. private $supplierIds = [];
  28. /**
  29. * @var bool 是否开启供应商
  30. */
  31. private $isEnableSupplier = false;
  32. /**
  33. * Doc: (des="将商品数据按照指定的字段分组")
  34. * User: XMing
  35. * Date: 2020/12/15
  36. * Time: 4:52 下午
  37. * @param array $lists 商品数据
  38. * @param array $common 公共参数
  39. * @param array $shopMap 店铺对应仓库数据
  40. * @return ResultWrapper
  41. * @throws \Exception
  42. */
  43. public function groupSupplierOrderData(array $lists, array $common, array $shopMap): ResultWrapper
  44. {
  45. if (empty($lists)) {
  46. return ResultWrapper::success([]);
  47. }
  48. $this->isEnableSupplier = self::getIsEnableSupplier();
  49. //店铺商品数据
  50. $buildResult = self::buildOrderShopData($lists, $common, $shopMap);
  51. if (!$buildResult->isSuccess()) {
  52. return ResultWrapper::fail($buildResult->getData(), $buildResult->getErrorCode());
  53. }
  54. $build = $buildResult->getData();
  55. return ResultWrapper::success($build);
  56. }
  57. /**
  58. * Doc: (des="")
  59. * User: XMing
  60. * Date: 2020/12/18
  61. * Time: 12:17 下午
  62. * @param array $shopData 店铺商品数据
  63. * @param array $params 公共数据
  64. * @param array $shopMap
  65. * @return ResultWrapper
  66. * @throws \Exception
  67. */
  68. public function buildOrderShopData(array $shopData, array $params, array $shopMap): ResultWrapper
  69. {
  70. $params['createTime'] = time();
  71. $params['updateTime'] = time();
  72. $objStockCache = new Stock($this->onlineEnterpriseId);
  73. $orderIndex = [];
  74. $order = [];
  75. $orderReceive = [];
  76. $orderGoods = [];
  77. $lockInventoryData = [];
  78. $activityData = [];
  79. $goodsSaleData = [];
  80. $cartIds = [];
  81. $orderSn = [];
  82. $supplierIndex = [];
  83. $supplierDetails = [];
  84. $useCoupon = getArrayItem($params, 'useCoupon', []);
  85. $useCouponId = getArrayItem($useCoupon, 'id', 0);
  86. $proporties = getArrayItem($params,'proporties',[]);
  87. $version = getArrayItem($params,'version',0);
  88. foreach ($shopData as $key => &$val) {
  89. $serialNum = $objStockCache->createSerialSn(0, 'Order');
  90. $sn = $serialNum;
  91. $verifyCode = self::createVerifyCode(substr($serialNum, -3));
  92. $orderSn[] = $sn;
  93. //将数据写入索引表
  94. if ($params['orderType'] == StatusCode::$orderType['saleOrder']){
  95. $preferential = floatval(array_sum(array_column($val['shopGoodsData'],'preferential')));//优惠券优惠
  96. if ($params['source'] == StatusCode::$source['manage']){
  97. $preferential = bcadd($preferential,isset($val['preferential']) ? $val['preferential'] : 0);
  98. }
  99. $vipDiscount = floatval(array_sum(array_column($val['shopGoodsData'],'vipDiscount')));//会员卡优惠
  100. $buyTotal = floatval(array_sum(array_column($val['shopGoodsData'],'buyNum')));
  101. $val['preferential'] = $preferential;
  102. $val['vipDiscount'] = $vipDiscount;
  103. $val['payMoney'] = bcadd($val['expressMoney'],bcsub($val['totalMoney'],bcadd($preferential,$vipDiscount),2),2);
  104. $val['buyTotal'] = $buyTotal;
  105. }
  106. if ($version == 1){
  107. //为了兼容xhjc
  108. $thisProporties = getArrayItem($proporties,$val['shopId'],[]);
  109. if (empty($thisProporties)){
  110. return ResultWrapper::fail('proporties异常',ErrorCode::$paramError);
  111. }
  112. $deliveryType = getArrayItem($thisProporties,'deliveryType',StatusCode::$deliveryType['selfMention']);
  113. $selfRuleId = getArrayItem($thisProporties,'selfRuleId',0);
  114. $selfRuleData = getArrayItem($thisProporties,'selfRuleData',null);
  115. $addressData = getArrayItem($thisProporties,'addressData',[]);
  116. }else{
  117. $deliveryType = getArrayItem($params, 'deliveryType', StatusCode::$deliveryType['selfMention']);
  118. $selfRuleId = getArrayItem($params, 'selfRuleId', 0);
  119. $selfRuleData = getArrayItem($params, 'selfRuleData', null);
  120. $addressData = getArrayItem($params, 'addressData', []);
  121. }
  122. $orderIndex[] = [
  123. 'shopId' => getArrayItem($val, 'shopId', 0),
  124. 'userCenterId' => getArrayItem($params, 'userCenterId', 0),
  125. 'salesManId' => getArrayItem($params, 'salesManId', 0),
  126. 'createTime' => getArrayItem($params, 'createTime', time()),
  127. 'updateTime' => getArrayItem($params, 'updateTime', time()),
  128. 'deleteStatus' => getArrayItem($params, 'deleteStatus', StatusCode::$standard),
  129. 'auditStatus' => getArrayItem($params, 'auditStatus', StatusCode::$auditStatus['auditing']),
  130. 'payStatus' => getArrayItem($params, 'payStatus', StatusCode::$delete),
  131. 'orderStatus' => getArrayItem($params, 'orderStatus', StatusCode::$orderStatus['waitPay']),
  132. 'outStatus' => getArrayItem($params, 'outStatus', StatusCode::$delete),
  133. 'returnStatus' => getArrayItem($params, 'returnStatus', StatusCode::$orderReturn['notReturn']),
  134. 'deliveryType' => $deliveryType,
  135. 'payType' => getArrayItem($params, 'payType',''),
  136. 'customerId' => getArrayItem($params, 'id', 0),
  137. 'no' => $sn,
  138. 'verifyCode' => $verifyCode,
  139. 'orderType' => getArrayItem($params, 'orderType', StatusCode::$orderType['saleOrder']),
  140. 'selfRuleId' => getArrayItem($params, 'selfRuleId', 0),
  141. ];
  142. //订单数据
  143. $order[$sn] = [
  144. 'customerId' => getArrayItem($params, 'id', 0),
  145. 'userCenterId' => getArrayItem($params, 'userCenterId', 0),
  146. 'shopId' => getArrayItem($val, 'shopId', 0),
  147. 'shopName' => getArrayItem($val, 'shopName', ''),
  148. 'no' => $sn,
  149. 'outerTradeNo' => getArrayItem($params, 'outerTradeNo', ''),
  150. 'totalMoney' => getArrayItem($val, 'totalMoney', 0),
  151. 'payAmount' => getArrayItem($val, 'payMoney', 0),
  152. 'customerName' => getArrayItem($params, 'name', ''),
  153. 'customerMobile' => getArrayItem($params, 'mobile', ''),
  154. 'remark' => getArrayItem($params, 'remark', ''),
  155. 'deliveryType' => $deliveryType,//配送方式
  156. 'payType' => getArrayItem($params, 'payType', ''),//支付方式
  157. 'salesManId' => getArrayItem($params, 'salesManId', 0),
  158. 'salesManName' => getArrayItem($params, 'salesManName', ''),
  159. 'customerType' => getArrayItem($params, 'customerType', 0),
  160. 'buyTotal' => getArrayItem($val, 'buyTotal', 0),
  161. 'source' => getArrayItem($params, 'source', StatusCode::$source['manage']),//来源
  162. 'orderStatus' => getArrayItem($params, 'orderStatus', StatusCode::$orderStatus['waitPay']),
  163. 'payStatus' => getArrayItem($params, 'payStatus', StatusCode::$delete),
  164. 'returnStatus' => getArrayItem($params, 'returnStatus', StatusCode::$orderReturn['notReturn']),
  165. 'outStatus' => getArrayItem($params, 'outStatus', StatusCode::$delete),
  166. 'createTime' => getArrayItem($params, 'createTime', time()),
  167. 'updateTime' => getArrayItem($params, 'updateTime', time()),
  168. 'customerOwe' => getArrayItem($params, 'customerOwe', 0),//客户当前欠款
  169. 'auditStatus' => getArrayItem($params, 'auditStatus', StatusCode::$auditStatus['auditing']),
  170. 'preferential' => getArrayItem($val, 'preferential', 0),//优惠券优惠金额
  171. 'vipDiscount' => getArrayItem($val, 'vipDiscount', 0),//会员卡优惠金额
  172. 'vipDoubleDiscount' => getArrayItem($val, 'vipDoubleDiscount', 0),
  173. 'originPayAmount' => getArrayItem($val, 'payAmount', 0),
  174. 'orderType' => getArrayItem($params, 'orderType', StatusCode::$orderType['saleOrder']),
  175. 'verifyCode' => $verifyCode,
  176. 'expressMoney' => getArrayItem($val, 'expressMoney', 0),
  177. 'selfRuleId' => $selfRuleId,
  178. 'selfRuleData' => json_encode($selfRuleData),
  179. 'serialNum' => $serialNum,
  180. 'operatorName' => getArrayItem($params, 'operatorName', $params['name']),
  181. 'operatorId' => $this->loginUserCenterId,
  182. 'accountList' => json_encode(getArrayItem($params, 'accountList', null)),
  183. 'currentAccountName' => getArrayItem($params, 'currentAccountName', ''),
  184. 'receivedMoney' => getArrayItem($params, 'receivedMoney', 0),
  185. 'reservoir' => json_encode(getArrayItem($params, 'reservoir', [])),
  186. 'comBinId' => getArrayItem($params,'comBinId',0),
  187. 'logisticsData' => json_encode(getArrayItem($params,'logisticsData',null))
  188. ];
  189. $extend = [];
  190. // 处理混合支付数据
  191. if( !empty($params['admixPayData']) ){
  192. $extend['admixPayData'] = $params['admixPayData'];
  193. }
  194. if( !empty($extend) ){
  195. $order[$sn]['extends'] = json_encode($extend);
  196. }
  197. if (!empty($addressData)) {
  198. $orderReceive[$sn] = [
  199. 'no' => $sn,
  200. 'customerId' => getArrayItem($params, 'id', 0),
  201. 'customerCode' => getArrayItem($addressData, 'customerCode', ''),//客户编码
  202. 'realName' => getArrayItem($addressData, 'name', ''),//收货人姓名
  203. 'mobile' => getArrayItem($addressData, 'mobile', ''),//收货人电话
  204. 'address' => getArrayItem($addressData, 'address', ''),//收货人详细地址
  205. 'provinceCode' => getArrayItem($addressData, 'provinceCode', ''),
  206. 'cityCode' => getArrayItem($addressData, 'cityCode', ''),
  207. 'districtCode' => getArrayItem($addressData, 'districtCode', ''),
  208. ];
  209. }
  210. foreach ($val['shopGoodsData'] as $k => &$v) {
  211. $orderGoods[$sn][] = [
  212. 'no' => $sn,
  213. 'goodsId' => getArrayItem($v, 'goodsId', 0),
  214. 'goodsName' => getArrayItem($v, 'goodsName', ''),
  215. 'shopId' => getArrayItem($val, 'shopId', 0),//商铺id
  216. 'shopName' => getArrayItem($val, 'shopName', ''),//商铺名称
  217. 'originPrice' => getArrayItem($v, 'originPrice', 0),
  218. 'price' => getArrayItem($v, 'price', 0),
  219. 'buyNum' => getArrayItem($v, 'buyNum', 0),
  220. 'otherNum' => getArrayItem($v, 'otherNum', 0),
  221. 'totalMoney' => getArrayItem($v, 'totalMoney', 0),
  222. 'skuId' => getArrayItem($v, 'skuId', 0),
  223. 'goodsBasicId' => getArrayItem($v, 'goodsBasicId', 0),
  224. 'goodsCode' => getArrayItem($v, 'goodsCode', ''),
  225. 'deliverNum' => getArrayItem($v, 'buyNum', 0),//发货数量=购买数量
  226. 'unitName' => getArrayItem($v, 'unitName', ''),//单位名称
  227. 'conversion' => getArrayItem($v, 'conversion', 0),//换算比率
  228. 'preferential' => getArrayItem($v, 'preferential', 0),//优惠券优惠金额
  229. 'vipDiscount' => getArrayItem($v, 'vipDiscount', 0),//会员卡优惠金额
  230. 'categoryPath' => getArrayItem($v, 'categoryPath', ''),//分类路径
  231. 'brandId' => getArrayItem($v, 'brandId', 0),//品牌id
  232. 'specGroup' => json_encode(getArrayItem($v, 'specGroup', null)),//
  233. 'goodsImages' => getArrayItem($v, 'goodsImages', ''),
  234. 'barCode' => getArrayItem($v, 'barCode', ''),
  235. 'storageCode' => getArrayItem($v, 'storageCode', ''),
  236. 'categoryName' => getArrayItem($v, 'categoryName', ''),
  237. 'brandName' => getArrayItem($v, 'brandName', ''),
  238. 'expressMoney' => getArrayItem($v, 'expressMoney', 0),
  239. 'outNum' => 0,//已出库数量
  240. 'outOfNum' => getArrayItem($v, 'buyNum', 0),//未出库数量
  241. 'isEq' => getArrayItem($v,'isEq',StatusCode::$delete),
  242. 'extends' => json_encode(getArrayItem($v, 'extends', null)),
  243. ];
  244. $lockInventoryData[$sn][] = [
  245. 'shopId' => getArrayItem($val, 'shopId', 0),
  246. 'merchantId' => getArrayItem($v, 'merchantId', 0),
  247. 'materielId' => getArrayItem($v, 'goodsBasicId', 0),
  248. 'materielCode' => getArrayItem($v, 'goodsCode', ''),
  249. 'lockingNum' => getArrayItem($v, 'buyNum', 0),
  250. 'originNo' => $sn,
  251. 'source' => StatusCode::$orderType['saleOrder'],
  252. 'sourceNo' => $sn,
  253. 'operatorId' => getArrayItem($val, 'id', 0),
  254. 'operatorName' => getArrayItem($val, 'name', ''),
  255. 'skuId' => getArrayItem($v, 'skuId', 0),
  256. 'goodsName' => getArrayItem($v, 'goodsName', ''),
  257. 'unitName' => getArrayItem($v, 'unitName', ''),
  258. 'specGroup' => getArrayItem($v, 'specGroup', null),
  259. ];
  260. $goodsSaleData [] = [
  261. 'goodsId' => getArrayItem($v, 'goodsId', 0),
  262. 'skuId' => getArrayItem($v, 'skuId', 0),
  263. 'buyNum' => getArrayItem($v, 'buyNum', 0),
  264. ];
  265. //活动商品数据
  266. if ($this->isFront) {
  267. if (isset($v['activityId']) && $v['activityId'] != 0) {
  268. $activityData[] = [
  269. 'goodsId' => getArrayItem($v, 'goodsId', 0),
  270. 'skuId' => getArrayItem($v, 'skuId', 0),
  271. 'activityId' => getArrayItem($v, 'activityId', 0),
  272. 'buyNum' => getArrayItem($v, 'buyNum', 0)
  273. ];
  274. }
  275. }
  276. if (isset($v['cartId']) && !empty($v['cartId'])) {
  277. $cartIds[] = getArrayItem($v, 'cartId', 0);
  278. }
  279. if ($this->isEnableSupplier) {
  280. //开启了供应商的模块
  281. if (isset($v['supplierId']) && !empty($v['supplierId'])) {
  282. $supplierIndex[$sn][] = [
  283. 'no' => $sn,
  284. 'supplierId' => getArrayItem($v, 'supplierId', 0),
  285. 'supplierName' => getArrayItem($v, 'supplierName', ''),
  286. 'customerId' => getArrayItem($params, 'id', 0),
  287. 'customerName' => getArrayItem($params, 'name', ''),
  288. 'shopId' => getArrayItem($v, 'shopId', 0),
  289. 'shopName' => getArrayItem($v, 'shopName', ''),
  290. 'reservoir' => json_encode(getArrayItem($params, 'reservoir', []))
  291. ];
  292. $supplierDetails[] = [
  293. 'no' => $sn,
  294. 'supplierId' => getArrayItem($v, 'supplierId', 0),
  295. 'supplierName' => getArrayItem($v, 'supplierName', ''),
  296. 'userCenterId' => getArrayItem($params, 'userCenterId', 0),
  297. 'customerId' => getArrayItem($params, 'id', 0),
  298. 'customerName' => getArrayItem($params, 'name', ''),
  299. 'shopId' => getArrayItem($v, 'shopId', 0),
  300. 'shopName' => getArrayItem($v, 'shopName', ''),
  301. 'materielId' => getArrayItem($v, 'goodsBasicId', 0),
  302. 'materielCode' => getArrayItem($v, 'goodsCode', ''),
  303. 'goodsId' => getArrayItem($v, 'goodsId', 0),
  304. 'goodsName' => getArrayItem($v, 'goodsName', ''),
  305. 'goodsImages' => getArrayItem($v, 'goodsImages', ''),
  306. 'skuId' => getArrayItem($v, 'skuId', 0),
  307. 'unitName' => getArrayItem($v, 'unitName', ''),
  308. 'conversion' => getArrayItem($v, 'conversion', 0),
  309. 'specGroup' => json_encode(getArrayItem($v, 'specGroup', null)),//
  310. 'categoryPath' => getArrayItem($v, 'categoryPath', ''),
  311. 'brandId' => getArrayItem($v, 'brandId', 0),
  312. 'categoryName' => getArrayItem($v, 'categoryName', ''),
  313. 'brandName' => getArrayItem($v, 'brandName', ''),
  314. 'barCode' => getArrayItem($v, 'barCode', ''),
  315. 'storageCode' => getArrayItem($v, 'storageCode', ''),
  316. 'buyNum' => getArrayItem($v, 'buyNum', 0),
  317. 'costPrice' => getArrayItem($v, 'costPrice', 0),
  318. 'price' => getArrayItem($v, 'price', 0),
  319. 'totalMoney' => getArrayItem($v, 'totalMoney', 0),
  320. 'createTime' => time(),
  321. 'reservoir' => json_encode(getArrayItem($params, 'reservoir', []))
  322. ];
  323. }
  324. }
  325. }
  326. }
  327. unset($val);
  328. return ResultWrapper::success([
  329. 'orderIndex' => $orderIndex,
  330. 'order' => $order,
  331. 'orderGoods' => $orderGoods,
  332. 'orderReceive' => $orderReceive,
  333. 'lockInventoryData' => $lockInventoryData,
  334. 'activityData' => $activityData,
  335. 'goodsSaleData' => $goodsSaleData,
  336. 'cartIds' => $cartIds,
  337. 'useCouponId' => $useCouponId,
  338. 'orderSn' => $orderSn,
  339. 'supplierIndex' => $supplierIndex,
  340. 'supplierDetails' => $supplierDetails,
  341. ]);
  342. }
  343. /**
  344. * Doc: (des="")
  345. * User: XMing
  346. * Date: 2020/12/22
  347. * Time: 4:27 下午
  348. * @param array $params
  349. * @return array
  350. */
  351. public static function noRelIdMap(array $params): array
  352. {
  353. $map = [];
  354. foreach ($params as $val) {
  355. $map[$val['no']] = $val['id'];
  356. }
  357. return $map;
  358. }
  359. /**
  360. * Doc: (des="")
  361. * User: XMing
  362. * Date: 2020/12/18
  363. * Time: 3:08 下午
  364. * @param $originArr
  365. * @param $relMap
  366. * @param string $field
  367. * @param bool $mul
  368. * @return void
  369. */
  370. public function pushValByNo(&$originArr, $relMap, $field = 'orderId', $mul = false)
  371. {
  372. $map = [];
  373. foreach ($originArr as $no => &$item) {
  374. $orderId = getArrayItem($relMap, $no, 0);
  375. if ($mul === false) {
  376. $item[$field] = $orderId;
  377. continue;
  378. }
  379. foreach ($item as &$value) {
  380. $value[$field] = $orderId;
  381. $map[] = $value;
  382. }
  383. }
  384. $mul === true && $originArr = $map;
  385. $originArr = array_values($originArr);
  386. }
  387. /**
  388. * Doc: (des="转换锁定库存的数据格式")
  389. * User: XMing
  390. * Date: 2021/3/5
  391. * Time: 10:41 上午
  392. * @param $originArr
  393. * @return array
  394. */
  395. public function buildLockingByShopId($originArr): array
  396. {
  397. $map = [];
  398. foreach ($originArr as $item){
  399. $map[$item['shopId']][] = $item;
  400. }
  401. return $map;
  402. }
  403. /**
  404. * Doc: (des="写入订单数据")
  405. * User: XMing
  406. * Date: 2020/12/19
  407. * Time: 2:44 下午
  408. * @param array $buildGroup
  409. * @param $params
  410. * @return ResultWrapper
  411. * @throws \Exception
  412. */
  413. public function insertOrder(array $buildGroup, $params): ResultWrapper
  414. {
  415. $objMCart = new MCart($this->onlineUserId, $this->onlineEnterpriseId);
  416. $objMUserCoupon = new MUserCoupon($this->onlineUserId, $this->onlineEnterpriseId);
  417. $objMInventory = new MInventory($this->onlineEnterpriseId, $this->onlineUserId);
  418. $objMGoods = new MGoods($this->onlineEnterpriseId, false, $this->onlineUserId);
  419. $objMComBinPackage = new MComBinPackage($this->onlineEnterpriseId,$this->onlineUserId);
  420. $objDSupplierOrderIndex = new DSupplierOrderIndex();
  421. $objDSupplierOrderDetails = new DSupplierOrderDetails();
  422. //1. 先写索引表
  423. $fix = ceil($this->onlineUserId / $this->cutTable);
  424. $this->objDOrderIndex->setTable('qianniao_order_index_' . $this->onlineEnterpriseId);
  425. $this->objDOrder->setTable('qianniao_order_' . $this->onlineEnterpriseId . '_' . $fix);
  426. $this->objDOrderGoods->setTable('qianniao_order_goods_' . $this->onlineEnterpriseId . '_' . $fix);
  427. $this->objDOrderReceive->setTable('qianniao_order_receive_' . $this->onlineEnterpriseId . '_' . $fix);
  428. $objDSupplierOrderIndex->setTable('qianniao_supplier_order_index_' . $this->onlineEnterpriseId);
  429. $orderIndex = getArrayItem($buildGroup, 'orderIndex', []);
  430. $order = getArrayItem($buildGroup, 'order', []);
  431. $orderGoods = getArrayItem($buildGroup, 'orderGoods', []);
  432. $orderReceive = getArrayItem($buildGroup, 'orderReceive', []);
  433. $delCartIds = getArrayItem($buildGroup, 'cartIds', []);
  434. $useCouponId = getArrayItem($buildGroup, 'useCouponId', 0);
  435. $lockInventoryData = getArrayItem($buildGroup, 'lockInventoryData', []);
  436. $goodsSaleData = getArrayItem($buildGroup, 'goodsSaleData', []);
  437. $activityData = getArrayItem($buildGroup, 'activityData', []);
  438. $orderSn = getArrayItem($buildGroup, 'orderSn', []);
  439. $supplierIndex = getArrayItem($buildGroup, 'supplierIndex', []);
  440. $supplierDetails = getArrayItem($buildGroup, 'supplierDetails', []);
  441. $comBinId = getArrayItem($params,'comBinId',0);
  442. $this->objDOrder->beginTransaction();
  443. $orderIds = $this->objDOrderIndex->insert($orderIndex, true);
  444. if ($orderIds === false) {
  445. $this->objDOrder->rollBack();
  446. return ResultWrapper::fail($this->objDOrderIndex->error(), ErrorCode::$dberror);
  447. }
  448. $noRelIdMap = $this->objDOrderIndex->select(['id' => $orderIds], 'id,no');
  449. if ($noRelIdMap === false) {
  450. $this->objDOrder->rollBack();
  451. return ResultWrapper::fail($this->objDOrderIndex->error(), ErrorCode::$dberror);
  452. }
  453. $noRelIdMap = self::noRelIdMap($noRelIdMap);
  454. self::pushValByNo($order, $noRelIdMap, 'id');
  455. self::pushValByNo($orderGoods, $noRelIdMap, 'orderId', true);
  456. self::pushValByNo($lockInventoryData, $noRelIdMap, 'originId', true);
  457. $lockInventoryData = self::buildLockingByShopId($lockInventoryData);//处理锁定数据
  458. if (!empty($orderReceive)) {
  459. self::pushValByNo($orderReceive, $noRelIdMap, 'orderId');
  460. }
  461. if (!empty($comBinId)){
  462. //组合套餐
  463. $comBinIncResult = $objMComBinPackage->incPackNum($comBinId,$params,$noRelIdMap);
  464. if (!$comBinIncResult->isSuccess()){
  465. $this->objDOrder->rollBack();
  466. return ResultWrapper::fail($comBinIncResult->getData(),$comBinIncResult->getErrorCode());
  467. }
  468. }
  469. // 订单主单据数据
  470. $orderResult = $this->objDOrder->insert($order, true);
  471. if ($orderResult === false) {
  472. $this->objDOrder->rollBack();
  473. return ResultWrapper::fail($this->objDOrder->error(), ErrorCode::$dberror);
  474. }
  475. // 订单商品
  476. $orderGoodsResult = $this->objDOrderGoods->insert($orderGoods, true);
  477. if ($orderGoodsResult === false) {
  478. $this->objDOrder->rollBack();
  479. return ResultWrapper::fail($this->objDOrderGoods->error(), ErrorCode::$dberror);
  480. }
  481. // 收货地址
  482. if (!empty($orderReceive)) {
  483. $orderReceiveResult = $this->objDOrderReceive->insert($orderReceive, true);
  484. if ($orderReceiveResult === false) {
  485. $this->objDOrder->rollBack();
  486. return ResultWrapper::fail($this->objDOrderReceive->error(), ErrorCode::$dberror);
  487. }
  488. }
  489. //删除购物车内已生成订单商品
  490. if (!empty($delCartIds)) {
  491. $result = $objMCart->delCart($delCartIds, true);
  492. if (!$result->isSuccess()) {
  493. $this->objDOrder->rollBack();
  494. return ResultWrapper::fail($result->getData(), ErrorCode::$dberror);
  495. }
  496. }
  497. //将优惠券改为已使用
  498. if (isset($useCouponId) && !empty($useCouponId)) {
  499. $useCouponOrderData = [];
  500. foreach ($noRelIdMap as $key=>$value){
  501. $useCouponOrderData[] = [
  502. 'no' => $key,
  503. 'id' => $value
  504. ];
  505. }
  506. $useCouponData = [
  507. 'isUse' => StatusCode::$delete,
  508. 'useTime' => time(),
  509. 'orderData' => json_encode($useCouponOrderData)
  510. ];
  511. $result = $objMUserCoupon->updateIsUse(['id' => $useCouponId], $useCouponData);
  512. if (!$result->isSuccess()) {
  513. $this->objDOrder->rollBack();
  514. return ResultWrapper::fail($result->getData(), ErrorCode::$dberror);
  515. }
  516. }
  517. //锁定库存商品数量
  518. foreach ($lockInventoryData as $shopId => $lockInventory){
  519. $lockInventoryResult = $objMInventory->updateLockInventory($shopId,$lockInventory);
  520. if (!$lockInventoryResult->isSuccess()) {
  521. $this->objDOrder->rollBack();
  522. return ResultWrapper::fail($lockInventoryResult->getData(), $lockInventoryResult->getErrorCode());
  523. }
  524. }
  525. if (!empty($supplierIndex)) {
  526. self::pushValByNo($supplierIndex, $noRelIdMap, 'orderId', true);
  527. $supplierIndexIds = $objDSupplierOrderIndex->insert($supplierIndex, true);
  528. if ($supplierIndexIds === false) {
  529. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $objDSupplierOrderIndex->error());
  530. $this->objDOrder->rollBack();
  531. return ResultWrapper::fail($objDSupplierOrderIndex->error(), ErrorCode::$dberror);
  532. }
  533. self::relArrMap($supplierDetails, $supplierIndexIds);
  534. $maxOrderId = max($orderIds);
  535. $fix = ceil($maxOrderId / MSupplierOrderDetails::$cutTable);
  536. $objDSupplierOrderDetails->setTable('qianniao_supplier_order_details_' . $this->onlineEnterpriseId . '_' . $fix);
  537. $result = $objDSupplierOrderDetails->insert($supplierDetails, true);
  538. if ($result === false) {
  539. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, $objDSupplierOrderIndex->error());
  540. $this->objDOrder->rollBack();
  541. return ResultWrapper::fail($objDSupplierOrderIndex->error(), ErrorCode::$dberror);
  542. }
  543. }
  544. //销售单
  545. if ($params['orderType'] === StatusCode::$orderType['salesSlip']) {
  546. $runSalesSlipResult = self::runSalesSlip($orderIds);
  547. if (!$runSalesSlipResult->isSuccess()) {
  548. $this->objDOrder->rollBack();
  549. return ResultWrapper::fail($runSalesSlipResult->getData(), $runSalesSlipResult->getErrorCode());
  550. }
  551. }
  552. //写es
  553. $address = (array)array_shift($orderReceive);
  554. foreach ($order as $item) {
  555. //self::esData($item, $address);
  556. self::buildSaleOrderData($params,$address,$item,$orderGoods);
  557. }
  558. $this->objDOrder->commit();
  559. //增加销量
  560. if (!empty($goodsSaleData)) {
  561. foreach ($goodsSaleData as $value) {
  562. $result = $objMGoods->updateSalesNum($value['goodsId'], $value['skuId'], $value['buyNum']);
  563. if ($result === false) {
  564. Logger::logs(E_USER_ERROR, 'sql error', __CLASS__, __LINE__, '商品增加销量失败');
  565. }
  566. }
  567. }
  568. //减活动商品总数量
  569. if (!empty($activityData)) {
  570. foreach ($activityData as $value) {
  571. $this->objActivityLimitCache->rPop($value['activityId'], $value['goodsId'], $value['skuId'], $value['buyNum']);
  572. }
  573. }
  574. // 后台代课下单不参与分销
  575. if ($params['source'] != StatusCode::$source['manage']){
  576. foreach ($orderIds as $orderId) {
  577. self::taskCreateCommission(getArrayItem($params, 'token', ''), getArrayItem($params, 'auth', ''), getArrayItem($params, 'id', 0), $orderId);
  578. }
  579. }
  580. //统计订单信息
  581. self::noticeStatistics([
  582. 'userCenterId' => $this->onlineUserId,
  583. 'enterpriseId' => $this->onlineEnterpriseId,
  584. 'customerId' => getArrayItem($params, 'id', 0),
  585. 'no' => $orderSn,
  586. 'noticeType' => 'create',
  587. ], 'MOrderStatistics');
  588. //写日志
  589. foreach ($orderSn as $sn) {
  590. parent::saveLog([
  591. 'no' => $sn,
  592. 'actionType' => '创建订单',//创建订单
  593. 'operationData' => '',
  594. 'userCenterId' => $this->onlineUserId,
  595. 'enterpriseId' => $this->onlineEnterpriseId,
  596. 'createTime' => time(),
  597. ]);
  598. }
  599. return ResultWrapper::success($orderIds);
  600. }
  601. /**
  602. * Doc: (des="销售单-出库-收款-完成")
  603. * User: XMing
  604. * Date: 2020/12/21
  605. * Time: 11:53 上午
  606. * @param array $orderIds
  607. * @return ResultWrapper
  608. * @throws \Exception
  609. */
  610. public function runSalesSlip(array $orderIds): ResultWrapper
  611. {
  612. //自动审核订单
  613. $objMInventoryOut = new MInventoryOut($this->onlineEnterpriseId, $this->onlineUserId);
  614. foreach ($orderIds as $id) {
  615. //自动审核订单
  616. $auditResult = self::updateAuditStatus([
  617. 'id' => $id,
  618. 'audit' => '销售单-自动审核',
  619. 'auditId' => $this->onlineUserId,
  620. 'auditStatus' => StatusCode::$auditStatus['auditPass']
  621. ]);
  622. if (!$auditResult->isSuccess()) {
  623. return ResultWrapper::fail($auditResult->getData(), $auditResult->getErrorCode());
  624. }
  625. $outId = $auditResult->getData();//出库单id
  626. //自动出库
  627. $dbResult = $objMInventoryOut->updateInventoryOutStatus([
  628. 'id' => $outId,
  629. 'auditId' => $this->onlineUserId,
  630. 'auditName' => '销售单-自动审核'
  631. ]);
  632. if (!$dbResult->isSuccess()) {
  633. return ResultWrapper::fail($dbResult->getData(), $dbResult->getErrorCode());
  634. }
  635. unset($dbResult);
  636. //确认收款
  637. $dbResult = self::updateOrderPayData(
  638. [
  639. 'payStatus' => StatusCode::$standard,
  640. 'payTime' => time()
  641. ],
  642. ['id' => $id]
  643. );
  644. if (!$dbResult->isSuccess()) {
  645. return ResultWrapper::fail($dbResult->getData(), $dbResult->getErrorCode());
  646. }
  647. unset($dbResult);
  648. $dbResult = self::updateOrderStatus($id,
  649. ['orderStatus' => StatusCode::$orderStatus['finish']],
  650. []
  651. );
  652. if (!$dbResult->isSuccess()) {
  653. return ResultWrapper::fail($dbResult->getData(), $dbResult->getErrorCode());
  654. }
  655. }
  656. return ResultWrapper::success(true);
  657. }
  658. /**
  659. * Doc: (des="")
  660. * User: XMing
  661. * Date: 2020/12/19
  662. * Time: 3:06 下午
  663. * @param array $lists
  664. * @oaram array $params
  665. * @return ResultWrapper
  666. */
  667. public function buildGoodsByShop(array $lists,array $params): ResultWrapper
  668. {
  669. if (empty($lists)) {
  670. return ResultWrapper::success([]);
  671. }
  672. $totalReduceMoney = getArrayItem($params,'totalReduceMoney',0);
  673. $map = [];
  674. foreach ($lists as $list) {
  675. if (isset($list['subMoney'])) {
  676. $list['totalMoney'] = $list['subMoney'];
  677. unset($list['subMoney']);
  678. }
  679. if (isset($list['basicGoodsId'])) {
  680. $list['goodsBasicId'] = $list['basicGoodsId'];
  681. unset($list['basicGoodsId']);
  682. }
  683. if (isset($list['code'])) {
  684. $list['goodsCode'] = $list['code'];
  685. unset($list['code']);
  686. }
  687. if ($list['salePrice']) {
  688. $list['price'] = $list['salePrice'];
  689. unset($list['salePrice']);
  690. }
  691. if (!isset($map[$list['shopId']]['totalMoney'])) {
  692. $map[$list['shopId']]['totalMoney'] = 0;
  693. }
  694. if (!isset($map[$list['shopId']]['preferential'])) {
  695. $map[$list['shopId']]['preferential'] = 0;
  696. }
  697. if (!isset($map[$list['shopId']]['payMoney'])) {
  698. $map[$list['shopId']]['payMoney'] = 0;
  699. }
  700. if (!isset($map[$list['shopId']]['buyTotal'])) {
  701. $map[$list['shopId']]['buyTotal'] = 0;
  702. }
  703. if (!isset($list['supplierId'])) {
  704. $list['supplierId'] = 0;
  705. }
  706. if (!isset($list['supplerName'])) {
  707. $list['supplerName'] = '';
  708. }
  709. $totalMoney = getArrayItem($list, 'totalMoney', 0);
  710. $preferential = getArrayItem($list, 'preferential', 0);
  711. $buyNum = getArrayItem($list, 'buyNum', 0);
  712. $map[$list['shopId']]['shopId'] = getArrayItem($list, 'shopId', 0);
  713. $map[$list['shopId']]['shopName'] = getArrayItem($list, 'shopName', 0);
  714. $map[$list['shopId']]['expressMoney'] = 0;//后台下单没有运费
  715. $map[$list['shopId']]['buyTotal'] = bcadd($map[$list['shopId']]['buyTotal'], $buyNum, 2);
  716. $map[$list['shopId']]['totalMoney'] = bcadd($map[$list['shopId']]['totalMoney'], $totalMoney, 2);
  717. $map[$list['shopId']]['payMoney'] = bcadd($map[$list['shopId']]['payMoney'], bcsub($totalMoney, $preferential + $totalReduceMoney), 2);
  718. $map[$list['shopId']]['preferential'] = bcadd($map[$list['shopId']]['preferential'], $preferential + $totalReduceMoney, 2);
  719. $map[$list['shopId']]['shopGoodsData'][] = $list;
  720. $totalReduceMoney = 0;
  721. if ($map[$list['shopId']]['payMoney'] <= 0){
  722. return ResultWrapper::fail('订单金额计算异常',ErrorCode::$paramError);
  723. }
  724. }
  725. return ResultWrapper::success(array_values($map));
  726. }
  727. /**
  728. * 格式化订单关联数据
  729. * @param $common
  730. * @return ResultWrapper
  731. * @throws \Exception
  732. */
  733. public function formatCommonParams($common): ResultWrapper
  734. {
  735. $objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  736. $objMCustomerBalance = new MCustomerBalance($this->onlineEnterpriseId, $this->onlineUserId);
  737. // 获取客户信息
  738. $customerData = $objMCustomer->getCustomerInfoByUserCenterId($common['userCenterId']);
  739. if (!$customerData->isSuccess()) {
  740. return ResultWrapper::fail($customerData->getData(), $customerData->getErrorCode());
  741. }
  742. $customerData = $customerData->getData();
  743. // 获取客户当前欠款
  744. $customerOwe = $objMCustomerBalance->getCustomerBalance($customerData['id']);
  745. $customerData['customerOwe'] = $customerOwe;
  746. unset($customerData['remark']);
  747. $common = array_merge($common, $customerData);
  748. if (isset($common['version']) && $common['version'] == 1){
  749. //多配送方式
  750. foreach ($common['proporties'] as $shopId => &$item){
  751. $deliveryResult = self::getObjectByDeliveryType($item);
  752. if (!$deliveryResult->isSuccess()){
  753. return ResultWrapper::fail($deliveryResult->getData(),$deliveryResult->getErrorCode());
  754. }
  755. $deliveryData = $deliveryResult->getData();
  756. $item['selfRuleData'] = getArrayItem($deliveryData,'selfRuleData',[]);
  757. $item['addressData'] = getArrayItem($deliveryData,'addressData',[]);
  758. }
  759. unset($item);
  760. }
  761. // 获取物流信息
  762. $deliveryResult = self::getObjectByDeliveryType($common);
  763. if (!$deliveryResult->isSuccess()){
  764. return ResultWrapper::fail($deliveryResult->getData(),$deliveryResult->getErrorCode());
  765. }
  766. $deliveryData = $deliveryResult->getData();
  767. $common['selfRuleData'] = getArrayItem($deliveryData,'selfRuleData',[]);
  768. $common['addressData'] = getArrayItem($deliveryData,'addressData',[]);
  769. return ResultWrapper::success($common);
  770. }
  771. /**
  772. * Doc: (des="通过配送方式获取配送信息")
  773. * User: XMing
  774. * Date: 2021/2/4
  775. * Time: 8:12 下午
  776. * @param array $common
  777. * @return ResultWrapper
  778. * @throws \Exception
  779. */
  780. private function getObjectByDeliveryType(array $common): ResultWrapper
  781. {
  782. $objMDeliverySetting = new MDeliverySetting($this->onlineUserId, $this->onlineEnterpriseId);
  783. $selfRuleData = [];
  784. $addressData = [];
  785. switch ($common['deliveryType']) {
  786. case StatusCode::$deliveryType['selfMention']: // 上门自提
  787. if (isset($common['selfRuleId']) && !empty($common['selfRuleId'])) {
  788. $selfRuleDataResult = $objMDeliverySetting->getSelfRuleInfo($common['selfRuleId']);
  789. if (!$selfRuleDataResult->isSuccess()) {
  790. return ResultWrapper::fail($selfRuleDataResult->getData(), $selfRuleDataResult->getErrorCode());
  791. }
  792. $selfRuleData = $selfRuleDataResult->getData();
  793. $selfRuleData = isset($selfRuleData['setData']) ? $selfRuleData['setData'] : [];
  794. }
  795. break;
  796. case in_array( $common['deliveryType'],[StatusCode::$deliveryType['goodsDelivery'],StatusCode::$deliveryType['logistics'],StatusCode::$deliveryType['logisticsLines'],StatusCode::$deliveryType['logisticsVehicle']] ):
  797. if (isset($common['addressId']) && !empty($common['addressId'])){
  798. $common['receiveAddressId'] = $common['addressId'];
  799. }
  800. if (isset($common['receiveAddressId']) && !empty($common['receiveAddressId'])) {
  801. $objMShippingAddress = new MShippingAddress($this->onlineEnterpriseId);
  802. $result = $objMShippingAddress->getShippingAddressInfo($common['receiveAddressId']);
  803. if (!$result->isSuccess()) {
  804. return ResultWrapper::fail($result->getData(), ErrorCode::$dberror);
  805. }
  806. $addressData = $result->getData();
  807. if (empty($addressData)) {
  808. return ResultWrapper::fail('收货地址信息不存在', ErrorCode::$dberror);
  809. }
  810. }
  811. break;
  812. }
  813. return ResultWrapper::success([
  814. 'selfRuleData' => $selfRuleData,
  815. 'addressData' => $addressData
  816. ]);
  817. }
  818. /**
  819. * Doc: (des="")
  820. * User: XMing
  821. * Date: 2020/12/22
  822. * Time: 4:56 下午
  823. * @param $arr
  824. * @param $ids
  825. */
  826. private function relArrMap(&$arr, $ids)
  827. {
  828. foreach ($arr as $index => &$value) {
  829. $value['id'] = getArrayItem($ids, $index, 0);
  830. }
  831. }
  832. /**
  833. * Doc: (des="查询供应商模块是否启用")
  834. * User: XMing
  835. * Date: 2020/12/22
  836. * Time: 10:01 上午
  837. * @return bool true=>开启 false=>关闭
  838. */
  839. public function getIsEnableSupplier(): bool
  840. {
  841. $objMBasicSetup = new MBasicSetup($this->onlineEnterpriseId);
  842. $setResult = $objMBasicSetup->getBasicField('supplierSet');
  843. if (!$setResult->isSuccess()) {
  844. return false;
  845. }
  846. $set = (array)$setResult->getData();
  847. $supplierSet = (array)getArrayItem($set, 'supplierSet', []);
  848. $isEnableSupplier = getArrayItem($supplierSet, 'enable_istrue', StatusCode::$delete);
  849. if ($isEnableSupplier == StatusCode::$standard) {
  850. return true;
  851. }
  852. return false;
  853. }
  854. /**
  855. * Doc: (des="")
  856. * User: XMing
  857. * Date: 2020/12/23
  858. * Time: 9:50 上午
  859. * @param array $params
  860. * @param array $lists
  861. * @return array
  862. */
  863. public function buildPurchase(array $params, array $lists): array
  864. {
  865. $goodsData = [];
  866. foreach ($lists as $list) {
  867. $skuId = getArrayItem($list, 'skuId', 0);
  868. if (!isset($goodsData[$skuId]['buyerNum'])) {
  869. $goodsData[$skuId]['buyerNum'] = 0;
  870. }
  871. $goodsData[$skuId]['basicGoodsId'] = getArrayItem($list, 'materielId', 0);
  872. $goodsData[$skuId]['goodsCode'] = getArrayItem($list, 'materielCode', '');
  873. $goodsData[$skuId]['goodsName'] = getArrayItem($list, 'goodsName', '');
  874. $goodsData[$skuId]['skuId'] = getArrayItem($list, 'skuId', 0);
  875. $goodsData[$skuId]['buyerNum'] = bcadd($goodsData[$skuId]['buyerNum'], $list['buyNum'], 2);
  876. $goodsData[$skuId]['buyerUnitPrice'] = getArrayItem($list, 'costPrice', 0);
  877. $goodsData[$skuId]['subtotalPrice'] = bcmul(getArrayItem($list, 'costPrice', 0), $goodsData[$skuId]['buyerNum'], 2);
  878. $goodsData[$skuId]['categoryId'] = getArrayItem($list, 'categoryId', 0);
  879. $goodsData[$skuId]['categoryName'] = getArrayItem($list, 'categoryName', '');
  880. $goodsData[$skuId]['unitName'] = getArrayItem($list, 'unitName', '');
  881. $goodsData[$skuId]['skuName'] = MPurchase::formatSpecGroup(json_decode(getArrayItem($list, 'specGroup', [])));
  882. }
  883. return [
  884. 'shopId' => getArrayItem($params, 'shopId', 0),
  885. 'shopName' => getArrayItem($params, 'shopName', ''),
  886. 'supplierId' => getArrayItem($params, 'supplierId', 0),
  887. 'supplierName' => getArrayItem($params, 'supplierName', ''),
  888. 'buyerId' => getArrayItem($params, 'buyerId', 0),
  889. 'departmentPath' => getArrayItem($params, 'departmentPath', ''),
  890. 'buyerName' => getArrayItem($params, 'buyerName', ''),
  891. 'operatorName' => getArrayItem($params, 'operatorName', ''),
  892. 'operatorId' => getArrayItem($params, 'operatorId', 0),
  893. 'couponAmount' => getArrayItem($params, 'couponAmount', 0),
  894. 'otherAmount' => getArrayItem($params, 'otherAmount', 0),
  895. 'remark' => getArrayItem($params, 'remark', ''),
  896. 'goodsData' => $goodsData,
  897. ];
  898. }
  899. /**
  900. * Doc: (des="订单es")
  901. * User: XMing
  902. * Date: 2020/12/30
  903. * Time: 6:30 下午
  904. * @param $order
  905. * @param $addressData
  906. */
  907. public function esData($order, $addressData)
  908. {
  909. $orderEsData = [
  910. /*订单表信息*/
  911. 'id' => getArrayItem($order, 'id', 0),//订单编号,
  912. 'no' => getArrayItem($order, 'no', ''),//订单编号,
  913. 'outerTradeNo' => getArrayItem($order, 'outerTradeNo', ''),//'外部流水号(支付宝/微信返回的流水号)'
  914. 'shopId' => getArrayItem($order, 'shopId', 0),
  915. 'shopName' => getArrayItem($order, 'shopName', ''),
  916. 'enterpriseId' => $this->onlineEnterpriseId,
  917. 'userCenterId' => getArrayItem($order, 'userCenterId', 0),
  918. 'totalMoney' => getArrayItem($order, 'totalMoney', 0),
  919. 'payAmount' => getArrayItem($order, 'payAmount', 0),
  920. 'buyTotal' => getArrayItem($order, 'buyTotal', 0),
  921. 'customerName' => getArrayItem($order, 'customerName', ''),//客户姓名
  922. 'customerId' => getArrayItem($order, 'customerId', 0),
  923. 'customerType' => getArrayItem($order, 'customerType', 0),//客户类型
  924. 'payStatus' => getArrayItem($order, 'payStatus', StatusCode::$delete),//'支付状态 默认4 未支付 5已支付'
  925. 'orderStatus' => getArrayItem($order, 'orderStatus', StatusCode::$orderStatus['waitPay']),//订单状态 默认1 创建 2待支付 3代发货 4待收货 5已完成 6已关闭
  926. 'payType' => getArrayItem($order, 'payType', StatusCode::$orderType['saleOrder']),//'支付方式 1微信 2支付宝 3货到付款 4上门自提'
  927. 'deliveryType' => getArrayItem($order, 'deliveryType', StatusCode::$deliveryType['selfMention']),
  928. 'source' => getArrayItem($order, 'source', StatusCode::$source['manage']),//订单来源 默认1 ios 2android 3小程序 4后台创建
  929. 'remark' => getArrayItem($order, 'remark', ''),//订单备注
  930. 'auditStatus' => getArrayItem($order, 'auditStatus', StatusCode::$auditStatus['auditing']),// '审核状态 默认1 待审 2审核通过 3 审核未通过 4 审核中'
  931. 'createTime' => getArrayItem($order, 'createTime', time()),
  932. 'updateTime' => getArrayItem($order, 'updateTime', time()),//'修改时间',
  933. 'salesManId' => getArrayItem($order, 'salesManId', 0),
  934. 'salesManName' => getArrayItem($order, 'salesManName', ''),
  935. 'returnStatus' => getArrayItem($order, 'notReturn', StatusCode::$orderReturn['notReturn']),
  936. 'outStatus' => getArrayItem($order, 'outStatus', StatusCode::$delete),
  937. 'verifyCode' => getArrayItem($order, 'verifyCode', $order['verifyCode']),//核销码
  938. /*收货人信息*/
  939. 'realName' => getArrayItem($addressData, 'realName', ''),//收货人姓名
  940. 'mobile' => getArrayItem($addressData, 'mobile', ''),//收货人电话
  941. 'address' => getArrayItem($addressData, 'address', ''),//收货详细地址
  942. 'provinceCode' => getArrayItem($addressData, 'provinceCode', ''),//收货人省份编码
  943. 'cityCode' => getArrayItem($addressData, 'cityCode', ''),//收货人城市编码
  944. 'districtCode' => getArrayItem($addressData, 'districtCode', ''),//收货人区编码
  945. /*优惠信息*/
  946. 'preferential' => getArrayItem($order, 'preferential', 0),//优惠券优惠金额
  947. 'vipDiscount' => getArrayItem($order, 'vipDiscount', 0),//会员卡优惠金额
  948. 'vipDoubleDiscount' => getArrayItem($order, 'vipDoubleDiscount', 0),//会员卡折上折优惠金额
  949. 'orderType' => getArrayItem($order, 'orderType', StatusCode::$orderType['salesSlip']),
  950. ];
  951. $_id = self::createEsDocumentId($orderEsData['id']);
  952. $result = $this->objDOrder->addUpSearchIndexDocument($orderEsData, $_id);
  953. if (isset($result['_shards']) && isset($result['_shards']['successful']) && $result['_shards']['successful'] == 1) {
  954. //echo "es操作成功";
  955. //return;
  956. return;
  957. }
  958. Logger::logs(E_USER_ERROR, 'es error', __CLASS__, __LINE__, $_id);
  959. //echo "es操作失败";
  960. }
  961. /**
  962. * Doc: (des="订单打印小票")
  963. * User: XMing
  964. * Date: 2020/12/31
  965. * Time: 10:59 上午
  966. * @param $params
  967. * @param $address
  968. * @param $order
  969. * @param $goodsDetails
  970. */
  971. public function buildSaleOrderData($params,$address,$order,$goodsDetails)
  972. {
  973. //销售单数据
  974. $this->isEnablePrint = false;
  975. if (isset($params['isEnablePrint']) && $params['isEnablePrint'] == StatusCode::$standard){
  976. $this->isEnablePrint = true;
  977. }
  978. if ($this->isEnablePrint === false){
  979. return;
  980. }
  981. $this->objSaleOrder->setReceiptTitle('销售订单');
  982. $this->objSaleOrder->setCodeName('订单号');
  983. $this->objSaleOrder->setCustomerName(getArrayItem($params, 'name', ''));
  984. $this->objSaleOrder->setCustomerMobile(getArrayItem($params, 'mobile', ''));
  985. $this->objSaleOrder->setPreferentialAmount(getArrayItem($params, 'preferential', 0));//目前销售订单没有优惠
  986. $this->objSaleOrder->setTotalAmount(getArrayItem($params, 'totalMoney', 0));
  987. $this->objSaleOrder->setPayAmount(getArrayItem($params, 'payAmount', 0));
  988. $this->objSaleOrder->setAddress(getArrayItem($address,'address',''));
  989. $this->objSaleOrder->setNo(getArrayItem($order,'no',''));//目前只会有一个订单
  990. $this->objSaleOrder->setShopName(getArrayItem($order,'shopName',''));
  991. $this->objSaleOrder->setCreateTime(getArrayItem($order,'createTime',time()));
  992. $this->objSaleOrder->setGoodsDetails($goodsDetails);
  993. }
  994. public function test()
  995. {
  996. }
  997. }