FengsuService.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * 获取偏远地区加收费用
  64. * @param string $express 快递公司名称
  65. * @param string $area 省份
  66. * @param float $weight 重量
  67. * @param string $city 城市
  68. * @return float
  69. */
  70. protected static function getRemoteAreaFee(string $express, string $weight, string $area, string $city = ''){
  71. $remote_area = config('app.remote_area');
  72. $fee = 0;
  73. if($express == '顺丰快递'){
  74. if(in_array($area, $remote_area[1])) {
  75. if($weight >= 3.5) $fee = 5;
  76. if($weight >= 4.5) $fee = 6;
  77. };
  78. }else{
  79. //普通(广东省-深圳) -浙江-舟山
  80. if(in_array($area, $remote_area[0])) $fee = 1.5;
  81. if($area == '广东省' && $city == '深圳市') $fee = 1.5;
  82. if($area == '浙江省' && $city == '舟山市') $fee = 1.5;
  83. }
  84. return $fee;
  85. }
  86. }