FengsuService.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * ----------------------------------------------------------------------------
  4. * 行到水穷处,坐看云起时
  5. * 开发软件,找贵阳云起信息科技,官网地址:https://www.56q7.com/
  6. * ----------------------------------------------------------------------------
  7. * Author: 老成
  8. * email:85556713@qq.com
  9. */
  10. declare(strict_types=1);
  11. namespace app\admin\service;
  12. class FengsuService {
  13. /** 加收价格
  14. * 1.先判断店铺
  15. * 2.在判断店铺下面的规格
  16. * @param array $item
  17. * @return int
  18. */
  19. public static function getAdditionalPrice(object $shopList, object $fengsuSku, object $productConfig, object $shopDelivery, object $customerSpec, array $item):int
  20. {
  21. dump('店铺0');
  22. $status = 1;
  23. //判断是否存在店铺
  24. $shops = $shopList::getSpecsIdByShopId($item['shopId']);
  25. dump('店铺00');
  26. if(!$shops->isEmpty()){
  27. dump('店铺1');
  28. //判断是否存在规格-获取重量
  29. $specs = $fengsuSku::getSpecsIdByShopId($shops->shop_id, $item['tradeOrderPrintVos'][0]['skuId']);
  30. if(!$specs->isEmpty()) {
  31. dump('店铺2');
  32. //根据规格重量获取,加收价格
  33. $weight = $productConfig::getWeight($specs->spec_id);
  34. $status = 3;
  35. if($weight){
  36. dump('店铺3');
  37. $other_price = self::getRemoteAreaFee($item['tradeOrderPrintVos'][0]['companyName'], $weight, $item['receiverProvince'], $item['receiverCity']);
  38. //获取包装箱
  39. $box = $customerSpec::getBoxId($shops->customer_id, $specs->variety_id, $specs->spec_id);
  40. $shopDelivery::create([
  41. 'customer_id' => $shops->customer_id,
  42. 'shop_id' => $shops->id,
  43. 'plat_id' => $shops->platform,
  44. 'variety_id' => $specs->variety_id,
  45. 'spec_id' => $specs->spec_id,
  46. 'spec_name' => $specs->spec_name,
  47. 'box_id' => $box->id??0,
  48. 'box_name' => $box->box_name??'',
  49. 'variety_name' => $box->variety_name,
  50. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  51. 'weigh' => $weight,
  52. 'price' => $box->price??0,
  53. 'total_price' => bcmul($box->price, (string)$item['tradeOrderPrintVos'][0]['total'], 2),
  54. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  55. 'waybill_no' => $item['waybillNo'],
  56. 'region' => $item['receiverProvince'].' '.$item['receiverCity'],
  57. 'other_price' => $other_price,
  58. 'ship_date' => substr($item['consignTime'], 0, 10),
  59. ]);
  60. }
  61. }else{
  62. $status = 2;
  63. }
  64. }
  65. return $status;
  66. }
  67. /** 编辑规格-加收价格
  68. * @param array $item
  69. * @return int
  70. */
  71. public static function setAdditionalPrice(object $shopList, object $productConfig, object $shopDelivery, object $customerSpec, string $shop_id, $variety_id, $spec_id, string $spec_name, object $item):bool
  72. {
  73. //判断是否存在店铺
  74. $shops = $shopList::getSpecsIdByShopId($shop_id);
  75. //根据规格重量获取,加收价格
  76. $weight = $productConfig::getWeight((int)$spec_id);
  77. $other_price = self::getRemoteAreaFee($item['company_name'], $weight??0, $item['province'], $item['city']);
  78. //获取包装箱
  79. $box = $customerSpec::getBoxId($shops->customer_id, (int)$variety_id, (int)$spec_id);
  80. $shopDelivery::create([
  81. 'customer_id' => $shops->customer_id,
  82. 'shop_id' => $shops->id,
  83. 'plat_id' => $shops->platform,
  84. 'variety_id' => $variety_id,
  85. 'spec_id' => $spec_id,
  86. 'spec_name' => $spec_name,
  87. 'box_id' => $box->id??0,
  88. 'box_name' => $box->box_name??'',
  89. 'variety_name' => $box->variety_name,
  90. 'num' => $item['num'],
  91. 'weigh' => $weight??0,
  92. 'price' => $box->price??0,
  93. 'total_price' => bcmul((string)$box->price, (string)$item['num'], 2),
  94. 'company_name' => $item['company_name'],
  95. 'waybill_no' => $item['waybill_no'],
  96. 'region' => $item['province'].' '.$item['city'],
  97. 'other_price' => $other_price,
  98. 'ship_date' => substr($item['consign_time'], 0, 10),
  99. ]);
  100. return true;
  101. }
  102. /**
  103. * 获取偏远地区加收费用
  104. * @param string $express 快递公司名称
  105. * @param string $area 省份
  106. * @param float $weight 重量
  107. * @param string $city 城市
  108. * @return float
  109. */
  110. protected static function getRemoteAreaFee(string $express, string $weight, string $area, string $city = ''){
  111. $remote_area = config('app.remote_area');
  112. $fee = 0;
  113. if($express == '顺丰快递'){
  114. if(in_array($area, $remote_area[1])) {
  115. if($weight >= 3.5) $fee = 5;
  116. if($weight >= 4.5) $fee = 6;
  117. };
  118. }else{
  119. //普通(广东省-深圳) -浙江-舟山
  120. if(in_array($area, $remote_area[0])) $fee = 1.5;
  121. if($area == '广东省' && $city == '深圳市') $fee = 1.5;
  122. if($area == '浙江省' && $city == '舟山市') $fee = 1.5;
  123. }
  124. return $fee;
  125. }
  126. }