JuShuiTanService.php 13 KB

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