JuShuiTanService.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. use app\common\model\ImportList;
  13. class JuShuiTanService {
  14. /** 加收价格
  15. * 1.先判断店铺
  16. * 2.在判断店铺下面的规格
  17. * @param array $item
  18. * @return int
  19. */
  20. public static function getAdditionalPrice(object $shopList, object $fengsuSku, object $productConfig, object $shopDelivery, object $customerSpec, array $item):int
  21. {
  22. $status = 1;
  23. //判断是否存在店铺
  24. $shops = $shopList::getSpecsIdByShopId($item['shopId']);
  25. if(!$shops->isEmpty()){
  26. //判断是否存在规格-获取重量
  27. $specs = $fengsuSku::getSpecsIdByShopId($shops->shop_id, $item['disInnerOrderGoodsViewList'][0]['shopSkuId']);
  28. if(!$specs->isEmpty()) {
  29. //根据规格重量获取,加收价格
  30. $weight = $productConfig::getWeight($specs->spec_id);
  31. $status = 3;
  32. if($weight){
  33. $other_price = self::getRemoteAreaFee($item['expressCompany'], $weight, $item['receiverState'], $item['receiverCity']);
  34. //获取包装箱
  35. $box = $customerSpec::getBoxId($shops->customer_id, $specs->variety_id, $specs->spec_id);
  36. $shopDelivery::create([
  37. 'customer_id' => $shops->customer_id,
  38. 'shop_id' => $shops->id,
  39. 'plat_id' => $shops->platform,
  40. 'variety_id' => $specs->variety_id,
  41. 'spec_id' => $specs->spec_id,
  42. 'spec_name' => $specs->spec_name,
  43. 'box_id' => $specs->box_id??0,
  44. 'box_name' => $box->box_name??'',
  45. 'variety_name' => $box->variety_name,
  46. 'num' => $item['disInnerOrderGoodsViewList'][0]['itemCount'],
  47. 'weigh' => $weight,
  48. 'price' => $box->price??0,
  49. 'total_price' => bcmul($box->price, (string)$item['disInnerOrderGoodsViewList'][0]['itemCount'], 2),
  50. 'company_name' => $item['expressCompany'],
  51. 'waybill_no' => ltrim($item['trackNo'], '@'),
  52. 'region' => $item['receiverState'].' '.$item['receiverCity'],
  53. 'other_price' => $other_price,
  54. 'ship_date' => substr($item['deliveryDate'], 0, 10),
  55. ]);
  56. }
  57. }else{
  58. $status = 2;
  59. }
  60. }
  61. return $status;
  62. }
  63. /** 编辑规格-加收价格
  64. * @param array $item
  65. * @return int
  66. */
  67. public static function setAdditionalPrice(object $fengsuSku,object $shopList, object $productConfig, object $shopDelivery, object $customerSpec, string $shop_id,$sku_id, $variety_id, $spec_id, string $spec_name, object $item):bool
  68. {
  69. //判断是否存在规格-获取重量
  70. $specs = $fengsuSku::getSpecsIdByShopId($shop_id, $sku_id);
  71. //判断是否存在店铺
  72. $shops = $shopList::getSpecsIdByShopId($shop_id);
  73. //根据规格重量获取,加收价格
  74. $weight = $productConfig::getWeight((int)$spec_id);
  75. $other_price = self::getRemoteAreaFee($item['company_name'], $weight??0, $item['province'], $item['city']);
  76. //获取包装箱
  77. $box = $customerSpec::getBoxId($shops->customer_id, (int)$variety_id, (int)$spec_id);
  78. $shopDelivery::create([
  79. 'customer_id' => $shops->customer_id,
  80. 'shop_id' => $shops->id,
  81. 'plat_id' => $shops->platform,
  82. 'variety_id' => $variety_id,
  83. 'spec_id' => $spec_id,
  84. 'spec_name' => $specs->spec_name,
  85. 'box_id' => $box->id??0,
  86. 'box_name' => $box->box_name??'',
  87. 'variety_name' => $box->variety_name,
  88. 'num' => $item['num'],
  89. 'weigh' => $weight??0,
  90. 'price' => $box->price??0,
  91. 'total_price' => bcmul((string)$box->price, (string)$item['num'], 2),
  92. 'company_name' => $item['company_name'],
  93. 'waybill_no' => $item['waybill_no'],
  94. 'region' => $item['province'].' '.$item['city'],
  95. 'other_price' => $other_price,
  96. 'ship_date' => substr($item['consign_time'], 0, 10),
  97. ]);
  98. return true;
  99. }
  100. /**
  101. * 获取偏远地区加收费用
  102. * @param string $express 快递公司名称
  103. * @param string $area 省份
  104. * @param float $weight 重量
  105. * @param string $city 城市
  106. * @return float
  107. */
  108. protected static function getRemoteAreaFee(string $express, string $weight, string $area, string $city = ''){
  109. $remote_area = config('app.remote_area');
  110. $fee = 0;
  111. if($express == '顺丰速运'){
  112. if(in_array($area, $remote_area[1])) {
  113. if($weight >= 3.5) $fee = 5;
  114. if($weight >= 4.5) $fee = 6;
  115. };
  116. }else{
  117. //普通(广东省-深圳) -浙江-舟山
  118. if(in_array($area, $remote_area[0])) $fee = 1.5;
  119. if($area == '广东省' && $city == '深圳市') $fee = 1.5;
  120. if($area == '浙江省' && $city == '舟山市') $fee = 1.5;
  121. }
  122. return $fee;
  123. }
  124. //防止重复记录,订单号+快递单号
  125. public static function prevent_duplicate_additions($oid,$waybill_no){
  126. $importList=new ImportList();
  127. $where = [
  128. 'order_id' => ['=', $oid],
  129. 'waybill_no' => ['=', $waybill_no]
  130. ];
  131. $result = $importList->where($where)->count();
  132. return $result=$result>0?true:false;
  133. }
  134. }