StoreOrderComputedServices.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\order;
  12. use app\services\BaseServices;
  13. use app\dao\order\StoreOrderDao;
  14. use app\services\pay\PayServices;
  15. use app\services\product\product\StoreCategoryServices;
  16. use app\services\user\member\MemberCardServices;
  17. use app\services\user\UserBillServices;
  18. use app\services\user\UserServices;
  19. use think\exception\ValidateException;
  20. use app\services\user\UserAddressServices;
  21. use app\services\activity\coupon\StoreCouponUserServices;
  22. use app\services\shipping\ShippingTemplatesFreeServices;
  23. use app\services\shipping\ShippingTemplatesRegionServices;
  24. use app\services\shipping\ShippingTemplatesServices;
  25. /**
  26. * 订单计算金额
  27. * Class StoreOrderComputedServices
  28. * @package app\services\order
  29. */
  30. class StoreOrderComputedServices extends BaseServices
  31. {
  32. /**
  33. * 支付类型
  34. * @var string[]
  35. */
  36. public $payType = ['weixin' => '微信支付', 'yue' => '余额支付', 'offline' => '线下支付', 'pc' => 'pc'];
  37. /**
  38. * 额外参数
  39. * @var array
  40. */
  41. protected $paramData = [];
  42. /**
  43. * StoreOrderComputedServices constructor.
  44. * @param StoreOrderDao $dao
  45. */
  46. public function __construct(StoreOrderDao $dao)
  47. {
  48. $this->dao = $dao;
  49. }
  50. /**
  51. * 设置额外参数
  52. * @param array $paramData
  53. * @return $this
  54. */
  55. public function setParamData(array $paramData)
  56. {
  57. $this->paramData = $paramData;
  58. return $this;
  59. }
  60. /**
  61. * 计算订单金额
  62. * @param int $uid
  63. * @param string $key
  64. * @param array $cartGroup
  65. * @param int $addressId
  66. * @param string $payType
  67. * @param bool $useIntegral
  68. * @param int $couponId
  69. * @param bool $is_create
  70. * @param int $shipping_type
  71. * @return array
  72. */
  73. public function computedOrder(int $uid, array $userInfo = [], array $cartGroup, int $addressId, string $payType, bool $useIntegral = false, int $couponId = 0, bool $isCreate = false, int $shippingType = 1)
  74. {
  75. $offlinePayStatus = (int)sys_config('offline_pay_status') ?? (int)2;
  76. $systemPayType = PayServices::PAY_TYPE;
  77. if ($offlinePayStatus == 2) unset($systemPayType['offline']);
  78. if (strtolower($payType) != 'pc' && strtolower($payType) != 'friend') {
  79. if (!array_key_exists($payType, $systemPayType)) {
  80. throw new ValidateException('选择支付方式有误');
  81. }
  82. }
  83. if (!$userInfo) {
  84. /** @var UserServices $userServices */
  85. $userServices = app()->make(UserServices::class);
  86. $userInfo = $userServices->getUserInfo($uid);
  87. if (!$userInfo) {
  88. throw new ValidateException('用户不存在!');
  89. }
  90. }
  91. $cartInfo = $cartGroup['cartInfo'];
  92. $priceGroup = $cartGroup['priceGroup'];
  93. $other = $cartGroup['other'];
  94. $payPrice = (float)$priceGroup['totalPrice'];
  95. $addr = $cartGroup['addr'] ?? [];
  96. $postage = $priceGroup;
  97. if (!$addr || $addr['id'] != $addressId) {
  98. /** @var UserAddressServices $addressServices */
  99. $addressServices = app()->make(UserAddressServices::class);
  100. $addr = $addressServices->getAddress($addressId) ?? [];
  101. if ($addr) {
  102. $addr = $addr->toArray();
  103. }
  104. //改变地址重新计算邮费
  105. $postage = [];
  106. }
  107. $combinationId = $this->paramData['combinationId'] ?? 0;
  108. $seckillId = $this->paramData['seckill_id'] ?? 0;
  109. $bargainId = $this->paramData['bargainId'] ?? 0;
  110. $isActivity = $combinationId || $seckillId || $bargainId;
  111. if (!$isActivity) {
  112. //使用优惠劵
  113. [$payPrice, $couponPrice] = $this->useCouponId($couponId, $uid, $cartInfo, $payPrice, $isCreate);
  114. //使用积分
  115. [$payPrice, $deductionPrice, $usedIntegral, $SurplusIntegral] = $this->useIntegral($useIntegral, $userInfo, $payPrice, $other);
  116. }
  117. //计算邮费
  118. [$payPrice, $payPostage, $storePostageDiscount, $storeFreePostage, $isStoreFreePostage] = $this->computedPayPostage($shippingType, $payType, $cartInfo, $addr, $payPrice, $postage, $other, $userInfo);
  119. $result = [
  120. 'total_price' => $priceGroup['totalPrice'],
  121. 'pay_price' => $payPrice > 0 ? $payPrice : 0,
  122. 'pay_postage' => $payPostage,
  123. 'coupon_price' => $couponPrice ?? 0,
  124. 'deduction_price' => $deductionPrice ?? 0,
  125. 'usedIntegral' => $usedIntegral ?? 0,
  126. 'SurplusIntegral' => $SurplusIntegral ?? 0,
  127. 'storePostageDiscount' => $storePostageDiscount ?? 0,
  128. 'isStoreFreePostage' => $isStoreFreePostage ?? false,
  129. 'storeFreePostage' => $storeFreePostage ?? 0
  130. ];
  131. $this->paramData = [];
  132. return $result;
  133. }
  134. /**
  135. * 使用优惠卷
  136. * @param int $couponId
  137. * @param int $uid
  138. * @param $cartInfo
  139. * @param $payPrice
  140. * @param bool $is_create
  141. */
  142. public function useCouponId(int $couponId, int $uid, $cartInfo, $payPrice, bool $isCreate)
  143. {
  144. //使用优惠劵
  145. $res1 = true;
  146. if ($couponId) {
  147. /** @var StoreCouponUserServices $couponServices */
  148. $couponServices = app()->make(StoreCouponUserServices::class);
  149. $couponInfo = $couponServices->getOne([['id', '=', $couponId], ['uid', '=', $uid], ['is_fail', '=', 0], ['status', '=', 0], ['start_time', '<', time()], ['end_time', '>', time()]], '*', ['issue']);
  150. if (!$couponInfo) {
  151. throw new ValidateException('选择的优惠劵无效!');
  152. }
  153. $type = $couponInfo['applicable_type'] ?? 0;
  154. $flag = false;
  155. $price = 0;
  156. $count = 0;
  157. switch ($type) {
  158. case 0:
  159. case 3:
  160. foreach ($cartInfo as $cart) {
  161. $price = bcadd($price, bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
  162. $count++;
  163. }
  164. break;
  165. case 1://品类券
  166. /** @var StoreCategoryServices $storeCategoryServices */
  167. $storeCategoryServices = app()->make(StoreCategoryServices::class);
  168. $cateGorys = $storeCategoryServices->getAllById((int)$couponInfo['category_id']);
  169. if ($cateGorys) {
  170. $cateIds = array_column($cateGorys, 'id');
  171. foreach ($cartInfo as $cart) {
  172. if (isset($cart['productInfo']['cate_id']) && array_intersect(explode(',', $cart['productInfo']['cate_id']), $cateIds)) {
  173. $price = bcadd($price, bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
  174. $count++;
  175. }
  176. }
  177. }
  178. break;
  179. case 2:
  180. foreach ($cartInfo as $cart) {
  181. if (isset($cart['product_id']) && in_array($cart['product_id'], explode(',', $couponInfo['product_id']))) {
  182. $price = bcadd($price, bcmul((string)$cart['truePrice'], (string)$cart['cart_num'], 2), 2);
  183. $count++;
  184. }
  185. }
  186. break;
  187. }
  188. if ($count && $couponInfo['use_min_price'] <= $price) {
  189. $flag = true;
  190. }
  191. if (!$flag) {
  192. throw new ValidateException('不满足优惠劵的使用条件!');
  193. }
  194. $payPrice = (float)bcsub((string)$payPrice, (string)$couponInfo['coupon_price'], 2);
  195. if ($isCreate) {
  196. $res1 = $couponServices->useCoupon($couponId);
  197. }
  198. $couponPrice = $couponInfo['coupon_price'];
  199. } else {
  200. $couponPrice = 0;
  201. }
  202. if (!$res1) {
  203. throw new ValidateException('使用优惠劵失败!');
  204. }
  205. return [$payPrice, $couponPrice];
  206. }
  207. /**
  208. * 使用积分
  209. * @param $useIntegral
  210. * @param $userInfo
  211. * @param $payPrice
  212. * @param $other
  213. * @return array
  214. */
  215. public function useIntegral(bool $useIntegral, $userInfo, string $payPrice, array $other)
  216. {
  217. /** @var UserBillServices $userBillServices */
  218. $userBillServices = app()->make(UserBillServices::class);
  219. // 可用积分
  220. $usable = bcsub((string)$userInfo['integral'], (string)$userBillServices->getBillSum(['uid' => $userInfo['uid'], 'is_frozen' => 1]), 0);
  221. $SurplusIntegral = 0;
  222. if ($useIntegral && $userInfo['integral'] > 0) {
  223. //积分抵扣上限
  224. $integralMaxNum = sys_config('integral_max_num', 200);
  225. if ($integralMaxNum > 0 && $usable > $integralMaxNum) {
  226. $integral = $integralMaxNum;
  227. } else {
  228. $integral = $usable;
  229. }
  230. $deductionPrice = (float)bcmul((string)$integral, (string)$other['integralRatio'], 2);
  231. if ($deductionPrice < $payPrice) {
  232. $payPrice = bcsub((string)$payPrice, (string)$deductionPrice, 2);
  233. $usedIntegral = $integral;
  234. } else {
  235. $deductionPrice = $payPrice;
  236. $usedIntegral = (int)ceil(bcdiv((string)$payPrice, (string)$other['integralRatio'], 2));
  237. $payPrice = 0;
  238. }
  239. $deductionPrice = $deductionPrice > 0 ? $deductionPrice : 0;
  240. $usedIntegral = $usedIntegral > 0 ? $usedIntegral : 0;
  241. $SurplusIntegral = (int)bcsub((string)$usable, $usedIntegral, 0);
  242. } else {
  243. $deductionPrice = 0;
  244. $usedIntegral = 0;
  245. }
  246. if ($payPrice <= 0) $payPrice = 0;
  247. return [$payPrice, $deductionPrice, $usedIntegral, $SurplusIntegral];
  248. }
  249. /**
  250. * 计算邮费
  251. * @param int $shipping_type
  252. * @param string $payType
  253. * @param array $cartInfo
  254. * @param array $addr
  255. * @param string $payPrice
  256. * @param array $other
  257. * @return array
  258. */
  259. public function computedPayPostage(int $shipping_type, string $payType, array $cartInfo, array $addr, string $payPrice, array $postage = [], array $other, $userInfo = [])
  260. {
  261. $storePostageDiscount = 0;
  262. $storeFreePostage = $postage['storeFreePostage'] ?? 0;
  263. $isStoreFreePostage = false;
  264. if (!$storeFreePostage) {
  265. $storeFreePostage = floatval(sys_config('store_free_postage')) ?: 0;//满额包邮金额
  266. }
  267. if (!$addr && !isset($addr['id']) || !$cartInfo) {
  268. $payPostage = 0;
  269. } else {
  270. //$shipping_type = 1 快递发货 $shipping_type = 2 门店自提
  271. if ($shipping_type == 2) {
  272. $store_self_mention = sys_config('store_self_mention') ?? 0;
  273. if (!$store_self_mention) $shipping_type = 1;
  274. }
  275. //门店自提 || (线下支付 && 线下支付包邮) 没有邮费支付
  276. if ($shipping_type === 2 || ($payType == 'offline' && ((isset($other['offlinePostage']) && $other['offlinePostage']) || sys_config('offline_postage')) == 1)) {
  277. $payPostage = 0;
  278. } else {
  279. if (!$postage || !isset($postage['storePostage']) || !isset($postage['storePostageDiscount'])) {
  280. $postage = $this->getOrderPriceGroup($storeFreePostage, $cartInfo, $addr, $userInfo);
  281. }
  282. $payPostage = $postage['storePostage'];
  283. $storePostageDiscount = $postage['storePostageDiscount'];
  284. $isStoreFreePostage = $postage['isStoreFreePostage'] ?? false;
  285. $payPrice = (float)bcadd((string)$payPrice, (string)$payPostage, 2);
  286. }
  287. }
  288. return [$payPrice, $payPostage, $storePostageDiscount, $storeFreePostage, $isStoreFreePostage];
  289. }
  290. /**
  291. * 运费计算,总金额计算
  292. * @param $cartInfo
  293. * @param $addr
  294. * @param array $userInfo
  295. * @return array
  296. */
  297. public function getOrderPriceGroup($storeFreePostage, $cartInfo, $addr, $userInfo = [])
  298. {
  299. $sumPrice = $totalPrice = $costPrice = $vipPrice = 0;
  300. $storePostage = 0;
  301. $storePostageDiscount = 0;
  302. $isStoreFreePostage = false;//是否满额包邮
  303. $sumPrice = $this->getOrderSumPrice($cartInfo, 'sum_price');//获取订单原总金额
  304. $totalPrice = $this->getOrderSumPrice($cartInfo, 'truePrice');//获取订单svip、用户等级优惠之后总金额
  305. $costPrice = $this->getOrderSumPrice($cartInfo, 'costPrice');//获取订单成本价
  306. $vipPrice = $this->getOrderSumPrice($cartInfo, 'vip_truePrice');//获取订单会员优惠金额
  307. // 判断商品包邮和固定运费
  308. foreach ($cartInfo as $key => &$item) {
  309. $item['postage_price'] = 0;
  310. if ($item['productInfo']['freight'] == 1) {
  311. $item['postage_price'] = 0;
  312. } elseif ($item['productInfo']['freight'] == 2) {
  313. $item['postage_price'] = bcmul((string)$item['productInfo']['postage'], (string)$item['cart_num'], 2);
  314. $storePostage = bcadd((string)$storePostage, (string)$item['postage_price'], 2);
  315. }
  316. }
  317. $postageArr = [];
  318. if (isset($cartInfo[0]['productInfo']['is_virtual']) && $cartInfo[0]['productInfo']['is_virtual'] == 1) {
  319. $storePostage = 0;
  320. } elseif ($storeFreePostage && $cartInfo && $addr) {
  321. if ($sumPrice >= $storeFreePostage) {//如果总价大于等于满额包邮 邮费等于0
  322. $isStoreFreePostage = true;
  323. $storePostage = 0;
  324. } else {
  325. //按照运费模板计算每个运费模板下商品的件数/重量/体积以及总金额 按照首重倒序排列
  326. $cityId = $addr['city_id'] ?? 0;
  327. $tempIds[] = 1;
  328. foreach ($cartInfo as $key_c => $item_c) {
  329. if (isset($item_c['productInfo']['freight']) && $item_c['productInfo']['freight'] == 3) {
  330. $tempIds[] = $item_c['productInfo']['temp_id'];
  331. }
  332. }
  333. $tempIds = array_unique($tempIds);
  334. /** @var ShippingTemplatesServices $shippServices */
  335. $shippServices = app()->make(ShippingTemplatesServices::class);
  336. $temp = $shippServices->getShippingColumn(['id' => $tempIds], 'type,appoint', 'id');
  337. /** @var ShippingTemplatesRegionServices $regionServices */
  338. $regionServices = app()->make(ShippingTemplatesRegionServices::class);
  339. $regions = $regionServices->getTempRegionList($tempIds, [$cityId, 0], 'temp_id,first,first_price,continue,continue_price', 'temp_id');
  340. $temp_num = [];
  341. foreach ($cartInfo as $cart) {
  342. if (isset($cart['productInfo']['freight']) && in_array($cart['productInfo']['freight'], [1, 2])) {
  343. continue;
  344. }
  345. $tempId = $cart['productInfo']['temp_id'] ?? 1;
  346. $type = $temp[$tempId]['type'] ?? $temp[1]['type'];
  347. if ($type == 1) {
  348. $num = $cart['cart_num'];
  349. } elseif ($type == 2) {
  350. $num = $cart['cart_num'] * $cart['productInfo']['attrInfo']['weight'];
  351. } else {
  352. $num = $cart['cart_num'] * $cart['productInfo']['attrInfo']['volume'];
  353. }
  354. $region = $regions[$tempId] ?? $regions[1];
  355. if (!isset($temp_num[$tempId])) {
  356. $temp_num[$tempId] = [
  357. 'number' => $num,
  358. 'type' => $type,
  359. 'price' => bcmul($cart['cart_num'], $cart['truePrice'], 2),
  360. 'first' => $region['first'],
  361. 'first_price' => $region['first_price'],
  362. 'continue' => $region['continue'],
  363. 'continue_price' => $region['continue_price'],
  364. 'temp_id' => $tempId
  365. ];
  366. } else {
  367. $temp_num[$tempId]['number'] += $num;
  368. $temp_num[$tempId]['price'] += bcmul($cart['cart_num'], $cart['truePrice'], 2);
  369. }
  370. }
  371. /** @var ShippingTemplatesFreeServices $freeServices */
  372. $freeServices = app()->make(ShippingTemplatesFreeServices::class);
  373. $freeList = $freeServices->isFreeList($tempIds, $addr['city_id'], 0, 'temp_id,number,price', 'temp_id');
  374. if ($freeList) {
  375. foreach ($temp_num as $k => $v) {
  376. if (isset($temp[$v['temp_id']]['appoint']) && $temp[$v['temp_id']]['appoint'] && isset($freeList[$v['temp_id']])) {
  377. $free = $freeList[$v['temp_id']];
  378. $condition = $v['type'] == 1 ? $free['number'] <= $v['number'] : $free['number'] >= $v['number'];
  379. if ($free['price'] <= $v['price'] && $condition) {
  380. unset($temp_num[$k]);
  381. }
  382. }
  383. }
  384. }
  385. //首件运费最大值
  386. $maxFirstPrice = $temp_num ? max(array_column($temp_num, 'first_price')) : 0;
  387. //初始运费为0
  388. $storePostage_arr = [];
  389. $i = 0;
  390. //循环运费数组
  391. foreach ($temp_num as $fk => $fv) {
  392. //找到首件运费等于最大值
  393. if ($fv['first_price'] == $maxFirstPrice) {
  394. //每次循环设置初始值
  395. $tempArr = $temp_num;
  396. $Postage = 0;
  397. //计算首件运费
  398. if ($fv['number'] <= $fv['first']) {
  399. $Postage = bcadd($Postage, $fv['first_price'], 2);
  400. } else {
  401. if ($fv['continue'] <= 0) {
  402. $Postage = $Postage;
  403. } else {
  404. $Postage = bcadd(bcadd($Postage, $fv['first_price'], 2), bcmul(ceil(bcdiv(bcsub($fv['number'], $fv['first'], 2), $fv['continue'] ?? 0, 2)), $fv['continue_price'], 4), 2);
  405. }
  406. }
  407. $postageArr[$i]['data'][$fk] = $Postage;
  408. //删除计算过的首件数据
  409. unset($tempArr[$fk]);
  410. //循环计算剩余运费
  411. foreach ($tempArr as $ck => $cv) {
  412. if ($cv['continue'] <= 0) {
  413. $Postage = $Postage;
  414. } else {
  415. $one_postage = bcmul(ceil(bcdiv($cv['number'], $cv['continue'] ?? 0, 2)), $cv['continue_price'], 2);
  416. $Postage = bcadd($Postage, $one_postage, 2);
  417. $postageArr[$i]['data'][$ck] = $one_postage;
  418. }
  419. }
  420. $postageArr[$i]['sum'] = $Postage;
  421. $storePostage_arr[] = $Postage;
  422. }
  423. }
  424. if (count($storePostage_arr)) {
  425. //获取运费计算中的最大值
  426. $storePostage = bcadd((string)$storePostage, (string)(max($storePostage_arr)), 2);
  427. }
  428. }
  429. }
  430. //会员邮费享受折扣
  431. if ($storePostage) {
  432. $express_rule_number = 0;
  433. if (!$userInfo) {
  434. /** @var UserServices $userService */
  435. $userService = app()->make(UserServices::class);
  436. $userInfo = $userService->getUserInfo($addr['uid']);
  437. }
  438. if ($userInfo && isset($userInfo['is_money_level']) && $userInfo['is_money_level'] > 0) {
  439. //看是否开启会员折扣奖励
  440. /** @var MemberCardServices $memberCardService */
  441. $memberCardService = app()->make(MemberCardServices::class);
  442. $express_rule_number = $memberCardService->isOpenMemberCard('express');
  443. $express_rule_number = $express_rule_number <= 0 ? 0 : $express_rule_number;
  444. }
  445. $truePostageArr = [];
  446. foreach ($postageArr as $postitem) {
  447. if ($postitem['sum'] == $storePostage) {
  448. $truePostageArr = $postitem['data'];
  449. break;
  450. }
  451. }
  452. $cartAlready = [];
  453. foreach ($cartInfo as &$item) {
  454. if (isset($item['productInfo']['freight']) && in_array($item['productInfo']['freight'], [1, 2])) {
  455. continue;
  456. }
  457. $tempId = $item['productInfo']['temp_id'] ?? 0;
  458. $tempPostage = $truePostageArr[$tempId] ?? 0;
  459. $type = $temp_num[$tempId]['type'];
  460. $tempNumber = $temp_num[$tempId]['number'] ?? 0;
  461. if (!$tempId || !$tempPostage || !$tempNumber) continue;
  462. $cartNumber = $item['cart_num'];
  463. if ((($cartAlready[$tempId]['number'] ?? 0) + $cartNumber) >= $tempNumber) {
  464. $price = isset($cartAlready[$tempId]['price']) ? bcsub((string)$tempPostage, (string)$cartAlready[$tempId]['price'], 6) : $tempPostage;
  465. } else {
  466. $price = bcmul((string)$tempPostage, bcdiv((string)$cartNumber, (string)$tempNumber, 6), 6);
  467. }
  468. $cartAlready[$tempId]['number'] = bcadd((string)($cartNumber[$tempId]['number'] ?? 0), (string)$cartNumber, 4);
  469. $cartAlready[$tempId]['price'] = bcadd((string)($cartNumber[$tempId]['price'] ?? 0.00), (string)$price, 4);
  470. if ($express_rule_number && $express_rule_number < 100) {
  471. $price = bcmul($price, bcdiv($express_rule_number, 100, 4), 4);
  472. }
  473. if ($type == 2) {
  474. $price = bcmul($price, $item['productInfo']['attrInfo']['weight'], 6);
  475. } elseif ($type == 3) {
  476. $price = bcmul($price, $item['productInfo']['attrInfo']['volume'], 6);
  477. }
  478. $price = sprintf("%.2f", $price);
  479. $item['postage_price'] = $price;
  480. }
  481. if ($express_rule_number && $express_rule_number < 100) {
  482. $storePostageDiscount = $storePostage;
  483. $storePostage = bcmul($storePostage, bcdiv($express_rule_number, 100, 4), 2);
  484. $storePostageDiscount = bcsub($storePostageDiscount, $storePostage, 2);
  485. } else {
  486. $storePostageDiscount = 0;
  487. $storePostage = $storePostage;
  488. }
  489. }
  490. return compact('storePostage', 'storeFreePostage', 'isStoreFreePostage', 'sumPrice', 'totalPrice', 'costPrice', 'vipPrice', 'storePostageDiscount', 'cartInfo');
  491. }
  492. /**
  493. * 获取某个字段总金额
  494. * @param $cartInfo
  495. * @param string $key
  496. * @param bool $is_unit
  497. * @return int|string
  498. */
  499. public function getOrderSumPrice($cartInfo, $key = 'truePrice', $is_unit = true)
  500. {
  501. $SumPrice = 0;
  502. foreach ($cartInfo as $cart) {
  503. if (isset($cart['cart_info'])) $cart = $cart['cart_info'];
  504. if ($is_unit) {
  505. $SumPrice = bcadd($SumPrice, bcmul($cart['cart_num'], $cart[$key], 2), 2);
  506. } else {
  507. $SumPrice = bcadd($SumPrice, $cart[$key], 2);
  508. }
  509. }
  510. return $SumPrice;
  511. }
  512. }