JuShuiTanService.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 $sku, object $productConfig, object $shopDelivery, object $customerSpec, array $item)
  21. {
  22. $status = 1;
  23. $shopDelivery=[];
  24. //判断是否存在店铺
  25. $shops = $shopList::getSpecsIdByShopId($item['shopId']);
  26. if(!$shops->isEmpty()){
  27. //判断是否存在规格-获取重量
  28. $specs = $sku::getSpecsIdByShopId($shops->shop_id, $item['disInnerOrderGoodsViewList'][0]['shopSkuId']);
  29. if(!$specs->isEmpty()) {
  30. //根据规格重量获取,加收价格
  31. $weight = $productConfig::getWeight($specs->spec_id);
  32. $status = 3;
  33. if($weight){
  34. $other_price = self::getRemoteAreaFee($item['expressCompany'], $weight, $item['receiverState'], $item['receiverCity']);
  35. // 保温加收价格
  36. $getPackSpecsFee=self::getPackSpecsFee($sku,$item['shopId'], $item['disInnerOrderGoodsViewList'][0]['shopSkuId'],$item['receiverState']);
  37. $pack_specs=strval($getPackSpecsFee['surcharge_money']);
  38. $other_price=(string)$other_price;
  39. $other_price=strval($other_price);
  40. $other_price=bcadd($other_price,$pack_specs, 2);
  41. //获取包装箱
  42. $box = $customerSpec::getBoxId($shops->customer_id, $specs->variety_id, $specs->spec_id);
  43. // $shopDelivery::create([
  44. // 'customer_id' => $shops->customer_id,
  45. // 'shop_id' => $shops->id,
  46. // 'plat_id' => $shops->platform,
  47. // 'variety_id' => $specs->variety_id,
  48. // 'spec_id' => $specs->spec_id,
  49. // 'spec_name' => $specs->spec_name,
  50. // 'box_id' => $specs->box_id??0,
  51. // 'box_name' => $box->box_name??'',
  52. // 'variety_name' => $box->variety_name,
  53. // 'num' => $item['disInnerOrderGoodsViewList'][0]['itemCount'],
  54. // 'weigh' => $weight,
  55. // 'price' => $box->price??0,
  56. // 'total_price' => bcmul($box->price, (string)$item['disInnerOrderGoodsViewList'][0]['itemCount'], 2),
  57. // 'company_name' => $item['expressCompany'],
  58. // 'waybill_no' => ltrim($item['trackNo'], '@'),
  59. // 'region' => $item['receiverState'].' '.$item['receiverCity'],
  60. // 'other_price' => $other_price,
  61. // 'ship_date' => substr($item['deliveryDate'], 0, 10),
  62. // 'incubator' => $getPackSpecsFee['pack_specs_type']
  63. // ]);
  64. $shopDelivery=[
  65. 'customer_id' => $shops->customer_id,
  66. 'shop_id' => $shops->id,
  67. 'plat_id' => $shops->platform,
  68. 'variety_id' => $specs->variety_id,
  69. 'spec_id' => $specs->spec_id,
  70. 'spec_name' => $specs->spec_name,
  71. 'box_id' => $specs->box_id??0,
  72. 'box_name' => $box->box_name??'',
  73. 'variety_name' => $box->variety_name,
  74. 'num' => $item['disInnerOrderGoodsViewList'][0]['itemCount'],
  75. 'weigh' => $weight,
  76. 'price' => $box->price??0,
  77. 'total_price' => bcmul((string)$box->price, (string)$item['disInnerOrderGoodsViewList'][0]['itemCount'], 2),
  78. 'company_name' => $item['expressCompany'],
  79. 'waybill_no' => ltrim($item['trackNo'], '@'),
  80. 'region' => $item['receiverState'].' '.$item['receiverCity'],
  81. 'other_price' => $other_price,
  82. 'ship_date' => substr($item['deliveryDate'], 0, 10),
  83. 'incubator' => $getPackSpecsFee['pack_specs_type']
  84. ];
  85. }
  86. }else{
  87. $status = 2;
  88. }
  89. }
  90. $data=[
  91. 'shopDelivery'=>$shopDelivery,
  92. 'status'=>$status
  93. ];
  94. return $data;
  95. // return $status;
  96. }
  97. /** 编辑规格-加收价格
  98. * @param array $item
  99. * @return int
  100. */
  101. public static function setAdditionalPrice(object $sku,object $shopList, object $productConfig, object $shopDelivery, object $customerSpec, string $shop_id,$sku_id, $variety_id, $spec_id, string $spec_name, object $item)
  102. {
  103. //判断是否存在规格-获取重量
  104. $specs = $sku::getSpecsIdByShopId($shop_id, $sku_id);
  105. //判断是否存在店铺
  106. $shops = $shopList::getSpecsIdByShopId($shop_id);
  107. //根据规格重量获取,加收价格
  108. $weight = $productConfig::getWeight((int)$spec_id);
  109. $other_price =self::getRemoteAreaFee($item['company_name'], $weight??0, $item['province'], $item['city']);
  110. // 保温加收价格
  111. $getPackSpecsFee=self::getPackSpecsFee($sku,$shop_id, $sku_id,$item['province']);
  112. $pack_specs=strval($getPackSpecsFee['surcharge_money']);
  113. $other_price=(string)$other_price;
  114. $other_price=strval($other_price);
  115. $other_price=bcadd($other_price,$pack_specs, 2);
  116. //获取包装箱
  117. $box = $customerSpec::getBoxId($shops->customer_id, (int)$variety_id, (int)$spec_id);
  118. // $shopDelivery::create([
  119. // 'customer_id' => $shops->customer_id,
  120. // 'shop_id' => $shops->id,
  121. // 'plat_id' => $shops->platform,
  122. // 'variety_id' => $variety_id,
  123. // 'spec_id' => $spec_id,
  124. // 'spec_name' => $specs->spec_name,
  125. // 'box_id' => $box->id??0,
  126. // 'box_name' => $box->box_name??'',
  127. // 'variety_name' => $box->variety_name,
  128. // 'num' => $item['num'],
  129. // 'weigh' => $weight??0,
  130. // 'price' => $box->price??0,
  131. // 'total_price' => bcmul((string)$box->price, (string)$item['num'], 2),
  132. // 'company_name' => $item['company_name'],
  133. // 'waybill_no' => $item['waybill_no'],
  134. // 'region' => $item['province'].' '.$item['city'],
  135. // 'other_price' => $other_price,
  136. // 'ship_date' => substr($item['consign_time'], 0, 10),
  137. // 'incubator' => $getPackSpecsFee['pack_specs_type']
  138. // ]);
  139. $shopDelivery=[
  140. 'customer_id' => $shops->customer_id,
  141. 'shop_id' => $shops->id,
  142. 'plat_id' => $shops->platform,
  143. 'variety_id' => $variety_id,
  144. 'spec_id' => $spec_id,
  145. 'spec_name' => $specs->spec_name,
  146. 'box_id' => $box->id??0,
  147. 'box_name' => $box->box_name??'',
  148. 'variety_name' => $box->variety_name,
  149. 'num' => $item['num'],
  150. 'weigh' => $weight??0,
  151. 'price' => $box->price??0,
  152. 'total_price' => bcmul((string)$box->price, (string)$item['num'], 2),
  153. 'company_name' => $item['company_name'],
  154. 'waybill_no' => $item['waybill_no'],
  155. 'region' => $item['province'].' '.$item['city'],
  156. 'other_price' => $other_price,
  157. 'ship_date' => substr($item['consign_time'], 0, 10),
  158. 'incubator' => $getPackSpecsFee['pack_specs_type']
  159. ];
  160. $data=[
  161. 'shopDelivery'=>$shopDelivery,
  162. 'getPackSpecsFee'=>$getPackSpecsFee
  163. ];
  164. return $data;
  165. }
  166. /**
  167. * 获取偏远地区加收费用
  168. * @param string $express 快递公司名称
  169. * @param string $area 省份
  170. * @param float $weight 重量
  171. * @param string $city 城市
  172. * @return float
  173. */
  174. public static function getRemoteAreaFee(string $express, string $weight, string $area, string $city = ''){
  175. // $remote_area = config('app.remote_area');
  176. $remote_area=[];
  177. $remote_area[0]=site_config("addonsd.remote_area_0");
  178. $remote_area[1]=site_config("addonsd.remote_area_1");
  179. $fee = 0;
  180. if($express == '顺丰快递'||$express=='顺丰速运'){
  181. if(in_array($area, $remote_area[1])) {
  182. if($weight >= 3.5) $fee = 5;
  183. if($weight >= 4.5) $fee = 6;
  184. };
  185. }else{
  186. //普通(广东省-深圳) -浙江-舟山
  187. if(in_array($area, $remote_area[0])) $fee = 1.5;
  188. if($area == '广东省' && $city == '深圳市') $fee = 1.5;
  189. if($area == '浙江省' && $city == '舟山市') $fee = 1.5;
  190. }
  191. return $fee;
  192. }
  193. //防止重复记录,订单号+快递单号
  194. public static function prevent_duplicate_additions($sku_id,$waybill_no){
  195. $importList=new ImportList();
  196. $where = [
  197. 'sku_id' => ['=', $sku_id],
  198. 'waybill_no' => ['=', $waybill_no]
  199. ];
  200. $result = $importList->where($where)->count();
  201. return $result=$result>0?true:false;
  202. }
  203. // 保温加收区域设置,加收金额
  204. public static function getPackSpecsFee($sku,$shop_id,$sku_id,$province){
  205. $res=[
  206. 'data'=>[
  207. 'id'=>0,
  208. 'labor_cost_money'=>0,
  209. ],
  210. 'one_surcharge_money'=>0,
  211. 'two_surcharge_money'=>0,
  212. 'pack_specs_type'=>0,
  213. 'surcharge_money'=>0
  214. ];
  215. $pack_specs_one_region=site_config("addonsd.pack_specs_one_region");
  216. $pack_specs_two_region=site_config("addonsd.pack_specs_two_region");
  217. $pack_specs_one_type=in_array($province,$pack_specs_one_region);
  218. $pack_specs_two_type=in_array($province,$pack_specs_two_region);
  219. $pack_specs_type=0;
  220. if($pack_specs_one_type){
  221. $pack_specs_type=1;
  222. }else if($pack_specs_two_type){
  223. $pack_specs_type=2;
  224. }
  225. // if(empty($pack_specs_type))return $res;
  226. $result=$sku::getPackSpecs($shop_id, $sku_id);
  227. if(empty($result)) return $res;
  228. $surcharge_money=0;
  229. $one_surcharge_money=0;
  230. $two_surcharge_money=0;
  231. switch ($pack_specs_type) {
  232. case 1:
  233. $surcharge_money=$result->one_surcharge_money;
  234. $one_surcharge_money=$surcharge_money;
  235. break;
  236. case 2:
  237. $surcharge_money=$result->two_surcharge_money;
  238. $two_surcharge_money=$surcharge_money;
  239. break;
  240. default:
  241. $surcharge_money=0;
  242. break;
  243. }
  244. $res=[
  245. 'data'=>$result,
  246. 'pack_specs_type'=>$pack_specs_type,
  247. 'one_surcharge_money'=>$one_surcharge_money,
  248. 'two_surcharge_money'=>$two_surcharge_money,
  249. 'surcharge_money'=>$surcharge_money
  250. ];
  251. return $res;
  252. }
  253. }