CartServices.php 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. declare (strict_types=1);
  12. namespace app\services\pc;
  13. use app\services\BaseServices;
  14. use app\services\order\StoreCartServices;
  15. use app\services\product\product\StoreProductServices;
  16. use app\services\user\level\SystemUserLevelServices;
  17. use app\services\user\member\MemberCardServices;
  18. use app\services\user\UserServices;
  19. class CartServices extends BaseServices
  20. {
  21. /**
  22. * PC端购物车列表
  23. * @param int $uid
  24. * @return array[]
  25. */
  26. public function getCartList(int $uid)
  27. {
  28. /** @var StoreCartServices $storeCartServices */
  29. $storeCartServices = app()->make(StoreCartServices::class);
  30. /** @var StoreProductServices $productServices */
  31. $productServices = app()->make(StoreProductServices::class);
  32. $list = $storeCartServices->getCartList(['uid' => $uid, 'is_pay' => 0, 'is_new' => 0, 'is_del' => 0, 'type' => 0, 'store_id' => 0], 0, 0, ['productInfo', 'attrInfo']);
  33. /** @var MemberCardServices $memberCardService */
  34. $memberCardService = app()->make(MemberCardServices::class);
  35. $vipStatus = $memberCardService->isOpenMemberCardCache('vip_price', false);
  36. /** @var UserServices $user */
  37. $user = app()->make(UserServices::class);
  38. $userInfo = $user->getUserInfo($uid);
  39. //用户等级是否开启
  40. $discount = 100;
  41. if (sys_config('member_func_status', 1)) {
  42. /** @var SystemUserLevelServices $systemLevel */
  43. $systemLevel = app()->make(SystemUserLevelServices::class);
  44. $discount = $systemLevel->getDiscount($uid, (int)$userInfo['level']);
  45. }
  46. $valid = $invalid = [];
  47. foreach ($list as &$item) {
  48. $is_valid = $item['attrInfo']['suk'] ?? 0;
  49. $item['productInfo']['attrInfo'] = $item['attrInfo'] ?? [];
  50. $item['productInfo']['attrInfo']['image'] = $item['attrInfo']['image'] ?? $item['productInfo']['image'];
  51. if (isset($item['productInfo']['attrInfo'])) {
  52. $item['productInfo']['attrInfo'] = get_thumb_water($item['productInfo']['attrInfo']);
  53. }
  54. $item['productInfo'] = get_thumb_water($item['productInfo']);
  55. $productInfo = $item['productInfo'];
  56. $item['vip_truePrice'] = 0;
  57. //门店独立商品
  58. $isBranchProduct = isset($productInfo['type']) && isset($productInfo['pid']) && $productInfo['type'] == 1 && !$productInfo['pid'];
  59. if (isset($productInfo['attrInfo']['product_id']) && $item['product_attr_unique']) {
  60. $item['costPrice'] = $productInfo['attrInfo']['cost'] ?? 0;
  61. $item['trueStock'] = $productInfo['attrInfo']['stock'] ?? 0;
  62. $item['truePrice'] = $productInfo['attrInfo']['price'] ?? 0;
  63. $item['sum_price'] = $productInfo['attrInfo']['price'] ?? 0;
  64. if (!$isBranchProduct) {
  65. [$truePrice, $vip_truePrice, $type] = $productServices->setLevelPrice($productInfo['attrInfo']['price'] ?? 0, $uid, $userInfo, $vipStatus, $discount, $productInfo['attrInfo']['vip_price'] ?? 0, $productInfo['is_vip'] ?? 0, true);
  66. }
  67. } else {
  68. $item['costPrice'] = $item['productInfo']['cost'] ?? 0;
  69. $item['trueStock'] = $item['productInfo']['stock'] ?? 0;
  70. $item['truePrice'] = $item['productInfo']['price'] ?? 0;
  71. $item['sum_price'] = $item['productInfo']['price'] ?? 0;
  72. if (!$isBranchProduct) {
  73. [$truePrice, $vip_truePrice, $type] = $productServices->setLevelPrice($item['productInfo']['price'] ?? 0, $uid, $userInfo, $vipStatus, $discount, $item['productInfo']['vip_price'] ?? 0, $item['productInfo']['is_vip'] ?? 0);
  74. }
  75. }
  76. $item['truePrice'] = $truePrice;
  77. $item['vip_truePrice'] = $vip_truePrice;
  78. $item['price_type'] = $type;
  79. unset($item['attrInfo']);
  80. if ($item['status'] == 1 && $is_valid && $item['trueStock'] > 0) {
  81. $valid[] = $item;
  82. } else {
  83. $invalid[] = $item;
  84. }
  85. }
  86. return ['valid' => $valid, 'invalid' => $invalid];
  87. }
  88. }