FengsuService.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. $status = 1;
  22. //判断是否存在店铺
  23. $shops = $shopList::getSpecsIdByShopId($item['shopId']);
  24. if(!$shops->isEmpty()){
  25. //判断是否存在规格-获取重量
  26. $specs = $fengsuSku::getSpecsIdByShopId($shops->shop_id, $item['tradeOrderPrintVos'][0]['skuId']);
  27. if(!$specs->isEmpty()) {
  28. //根据规格重量获取,加收价格
  29. $weight = $productConfig::getWeight($specs->spec_id);
  30. $status = 3;
  31. if($weight){
  32. $other_price = self::getRemoteAreaFee($item['tradeOrderPrintVos'][0]['companyName'], $weight, $item['receiverProvince'], $item['receiverCity']);
  33. //获取包装箱
  34. $box = $customerSpec::getBoxId($shops->customer_id, $specs->variety_id, $specs->spec_id);
  35. $shopDelivery::create([
  36. 'customer_id' => $shops->customer_id,
  37. 'shop_id' => $shops->id,
  38. 'plat_id' => $shops->platform,
  39. 'variety_id' => $specs->variety_id,
  40. 'spec_id' => $specs->spec_id,
  41. 'spec_name' => $specs->spec_name,
  42. 'box_id' => $box->id??0,
  43. 'box_name' => $box->box_name??'',
  44. 'variety_name' => $box->variety_name,
  45. 'num' => $item['tradeOrderPrintVos'][0]['total'],
  46. 'weigh' => $weight,
  47. 'price' => $box->price??0,
  48. 'total_price' => bcmul($box->price, (string)$item['tradeOrderPrintVos'][0]['total'], 2),
  49. 'company_name' => $item['tradeOrderPrintVos'][0]['companyName'],
  50. 'waybill_no' => $item['waybillNo'],
  51. 'region' => $item['receiverProvince'].' '.$item['receiverCity'],
  52. 'other_price' => $other_price,
  53. 'ship_date' => substr($item['consignTime'], 0, 10),
  54. ]);
  55. }
  56. }else{
  57. $status = 2;
  58. }
  59. }
  60. return $status;
  61. }
  62. /** 编辑规格-加收价格
  63. * @param array $item
  64. * @return int
  65. */
  66. 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
  67. {
  68. //判断是否存在店铺
  69. $shops = $shopList::getSpecsIdByShopId($shop_id);
  70. //根据规格重量获取,加收价格
  71. $weight = $productConfig::getWeight((int)$spec_id);
  72. $other_price = self::getRemoteAreaFee($item['company_name'], $weight??0, $item['province'], $item['city']);
  73. //获取包装箱
  74. $box = $customerSpec::getBoxId($shops->customer_id, (int)$variety_id, (int)$spec_id);
  75. $shopDelivery::create([
  76. 'customer_id' => $shops->customer_id,
  77. 'shop_id' => $shops->id,
  78. 'plat_id' => $shops->platform,
  79. 'variety_id' => $variety_id,
  80. 'spec_id' => $spec_id,
  81. 'spec_name' => $spec_name,
  82. 'box_id' => $box->id??0,
  83. 'box_name' => $box->box_name??'',
  84. 'variety_name' => $box->variety_name,
  85. 'num' => $item['num'],
  86. 'weigh' => $weight??0,
  87. 'price' => $box->price??0,
  88. 'total_price' => bcmul((string)$box->price, (string)$item['num'], 2),
  89. 'company_name' => $item['company_name'],
  90. 'waybill_no' => $item['waybill_no'],
  91. 'region' => $item['province'].' '.$item['city'],
  92. 'other_price' => $other_price,
  93. 'ship_date' => substr($item['consign_time'], 0, 10),
  94. ]);
  95. return true;
  96. }
  97. /**
  98. * 获取偏远地区加收费用
  99. * @param string $express 快递公司名称
  100. * @param string $area 省份
  101. * @param float $weight 重量
  102. * @param string $city 城市
  103. * @return float
  104. */
  105. protected static function getRemoteAreaFee(string $express, string $weight, string $area, string $city = ''){
  106. $remote_area = config('app.remote_area');
  107. $fee = 0;
  108. if($express == '顺丰快递'){
  109. if(in_array($area, $remote_area[1])) {
  110. if($weight >= 3.5) $fee = 5;
  111. if($weight >= 4.5) $fee = 6;
  112. };
  113. }else{
  114. //普通(广东省-深圳) -浙江-舟山
  115. if(in_array($area, $remote_area[0])) $fee = 1.5;
  116. if($area == '广东省' && $city == '深圳市') $fee = 1.5;
  117. if($area == '浙江省' && $city == '舟山市') $fee = 1.5;
  118. }
  119. return $fee;
  120. }
  121. }