CartServices.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\system\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], 0, 0, ['productInfo', 'attrInfo']);
  33. /** @var MemberCardServices $memberCardService */
  34. $memberCardService = app()->make(MemberCardServices::class);
  35. $vipStatus = $memberCardService->isOpenMemberCard('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->value(['id' => $userInfo['level'], 'is_del' => 0, 'is_show' => 1], 'discount') ?: 100;
  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. if (isset($productInfo['attrInfo']['product_id']) && $item['product_attr_unique']) {
  57. $item['costPrice'] = $productInfo['attrInfo']['cost'] ?? 0;
  58. $item['trueStock'] = $productInfo['attrInfo']['stock'] ?? 0;
  59. [$truePrice, $vip_truePrice, $type] = $productServices->setLevelPrice($productInfo['attrInfo']['price'] ?? 0, $uid, $userInfo, $vipStatus, $discount, $productInfo['attrInfo']['vip_price'] ?? 0, $productInfo['is_vip'] ?? 0, true);
  60. $item['truePrice'] = $truePrice;
  61. $item['vip_truePrice'] = $vip_truePrice;
  62. $item['price_type'] = $type;
  63. } else {
  64. $item['costPrice'] = $item['productInfo']['cost'] ?? 0;
  65. $item['trueStock'] = $item['productInfo']['stock'] ?? 0;
  66. [$truePrice, $vip_truePrice, $type] = $productServices->setLevelPrice($item['productInfo']['price'] ?? 0, $uid, $userInfo, $vipStatus, $discount, $item['productInfo']['vip_price'] ?? 0, $item['productInfo']['is_vip'] ?? 0);
  67. $item['truePrice'] = $truePrice;
  68. $item['vip_truePrice'] = $vip_truePrice;
  69. $item['price_type'] = $type;
  70. }
  71. unset($item['attrInfo']);
  72. if ($item['status'] == 1 && $is_valid && $item['trueStock'] > 0) {
  73. $valid[] = $item;
  74. } else {
  75. $invalid[] = $item;
  76. }
  77. }
  78. return ['valid' => $valid, 'invalid' => $invalid];
  79. }
  80. }