JuShuiTanService.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. ];
  88. }
  89. }else{
  90. $status = 2;
  91. }
  92. }
  93. $data=[
  94. 'shopDelivery'=>$shopDelivery,
  95. 'status'=>$status
  96. ];
  97. return $data;
  98. // return $status;
  99. }
  100. /** 编辑规格-加收价格
  101. * @param array $item
  102. * @return int
  103. */
  104. 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)
  105. {
  106. //判断是否存在规格-获取重量
  107. $specs = $sku::getSpecsIdByShopId($shop_id, $sku_id);
  108. //判断是否存在店铺
  109. $shops = $shopList::getSpecsIdByShopId($shop_id);
  110. //根据规格重量获取,加收价格
  111. $weight = $productConfig::getWeight((int)$spec_id);
  112. $other_price =self::getRemoteAreaFee($item['company_name'], $weight??0, $item['province'], $item['city']);
  113. // 保温加收价格
  114. $getPackSpecsFee=self::getPackSpecsFee($sku,$shop_id, $sku_id,$item['province']);
  115. $pack_specs=strval($getPackSpecsFee['surcharge_money']);
  116. // $other_price=(string)$other_price;
  117. // $other_price=strval($other_price);
  118. // $other_price=bcadd($other_price,$pack_specs, 2);
  119. //获取包装箱
  120. $box = $customerSpec::getBoxId($shops->customer_id, (int)$variety_id, (int)$spec_id);
  121. // $shopDelivery::create([
  122. // 'customer_id' => $shops->customer_id,
  123. // 'shop_id' => $shops->id,
  124. // 'plat_id' => $shops->platform,
  125. // 'variety_id' => $variety_id,
  126. // 'spec_id' => $spec_id,
  127. // 'spec_name' => $specs->spec_name,
  128. // 'box_id' => $box->id??0,
  129. // 'box_name' => $box->box_name??'',
  130. // 'variety_name' => $box->variety_name,
  131. // 'num' => $item['num'],
  132. // 'weigh' => $weight??0,
  133. // 'price' => $box->price??0,
  134. // 'total_price' => bcmul((string)$box->price, (string)$item['num'], 2),
  135. // 'company_name' => $item['company_name'],
  136. // 'waybill_no' => $item['waybill_no'],
  137. // 'region' => $item['province'].' '.$item['city'],
  138. // 'other_price' => $other_price,
  139. // 'ship_date' => substr($item['consign_time'], 0, 10),
  140. // 'incubator' => $getPackSpecsFee['pack_specs_type']
  141. // ]);
  142. $shopDelivery=[
  143. 'customer_id' => $shops->customer_id,
  144. 'shop_id' => $shops->id,
  145. 'plat_id' => $shops->platform,
  146. 'variety_id' => $variety_id,
  147. 'spec_id' => $spec_id,
  148. 'spec_name' => $specs->spec_name,
  149. 'box_id' => $box->id??0,
  150. 'box_name' => $box->box_name??'',
  151. 'variety_name' => $box->variety_name,
  152. 'num' => $item['num'],
  153. 'weigh' => $weight??0,
  154. 'price' => $box->price??0,
  155. 'total_price' => bcmul((string)$box->price, (string)$item['num'], 2),
  156. 'company_name' => $item['company_name'],
  157. 'waybill_no' => $item['waybill_no'],
  158. 'region' => $item['province'].' '.$item['city'],
  159. 'other_price' => $other_price,
  160. 'ship_date' => $item['consign_time'],
  161. 'incubator' => $getPackSpecsFee['pack_specs_type'],
  162. 'insulation_money' => $getPackSpecsFee['surcharge_money'],
  163. 'labor_cost_money' => $getPackSpecsFee['data']['labor_cost_money']
  164. ];
  165. $data=[
  166. 'shopDelivery'=>$shopDelivery,
  167. 'getPackSpecsFee'=>$getPackSpecsFee
  168. ];
  169. return $data;
  170. }
  171. /**
  172. * 获取偏远地区加收费用
  173. * @param string $express 快递公司名称
  174. * @param string $area 省份
  175. * @param float $weight 重量
  176. * @param string $city 城市
  177. * @return float
  178. */
  179. public static function getRemoteAreaFee(string $express, string $weight, string $area, string $city = ''){
  180. // $remote_area = config('app.remote_area');
  181. $remote_area=[];
  182. $remote_area[0]=site_config("addonsd.remote_area_0");
  183. $remote_area[1]=site_config("addonsd.remote_area_1");
  184. $fee = 0;
  185. if($express == '顺丰快递'||$express=='顺丰速运'){
  186. if(in_array($area, $remote_area[1])) {
  187. if($weight >= 3.5) $fee = 5;
  188. if($weight >= 4.5) $fee = 6;
  189. };
  190. }else{
  191. //普通(广东省-深圳) -浙江-舟山
  192. if(in_array($area, $remote_area[0])) $fee = 1.5;
  193. if($area == '广东省' && $city == '深圳市') $fee = 1.5;
  194. if($area == '浙江省' && $city == '舟山市') $fee = 1.5;
  195. }
  196. return $fee;
  197. }
  198. //防止重复记录,订单号+快递单号
  199. public static function prevent_duplicate_additions($sku_id,$waybill_no){
  200. $importList=new ImportList();
  201. $where = [
  202. 'sku_id' => ['=', $sku_id],
  203. 'waybill_no' => ['=', $waybill_no]
  204. ];
  205. $result = $importList->where($where)->count();
  206. return $result=$result>0?true:false;
  207. }
  208. // 保温加收区域设置,加收金额
  209. public static function getPackSpecsFee($sku,$shop_id,$sku_id,$province){
  210. $res=[
  211. 'data'=>[
  212. 'id'=>0,
  213. 'labor_cost_money'=>0,
  214. ],
  215. 'one_surcharge_money'=>0,
  216. 'two_surcharge_money'=>0,
  217. 'pack_specs_type'=>0,
  218. 'surcharge_money'=>0
  219. ];
  220. $pack_specs_one_region=site_config("addonsd.pack_specs_one_region");
  221. $pack_specs_two_region=site_config("addonsd.pack_specs_two_region");
  222. $pack_specs_one_type=in_array($province,$pack_specs_one_region);
  223. $pack_specs_two_type=in_array($province,$pack_specs_two_region);
  224. $pack_specs_type=0;
  225. if($pack_specs_one_type){
  226. $pack_specs_type=1;
  227. }else if($pack_specs_two_type){
  228. $pack_specs_type=2;
  229. }
  230. // if(empty($pack_specs_type))return $res;
  231. $result=$sku::getPackSpecs($shop_id, $sku_id);
  232. if(empty($result)) return $res;
  233. $surcharge_money=0;
  234. $one_surcharge_money=0;
  235. $two_surcharge_money=0;
  236. switch ($pack_specs_type) {
  237. case 1:
  238. $surcharge_money=$result->one_surcharge_money;
  239. $one_surcharge_money=$surcharge_money;
  240. break;
  241. case 2:
  242. $surcharge_money=$result->two_surcharge_money;
  243. $two_surcharge_money=$surcharge_money;
  244. break;
  245. default:
  246. $surcharge_money=0;
  247. break;
  248. }
  249. $res=[
  250. 'data'=>$result,
  251. 'pack_specs_type'=>$pack_specs_type,
  252. 'one_surcharge_money'=>$one_surcharge_money,
  253. 'two_surcharge_money'=>$two_surcharge_money,
  254. 'surcharge_money'=>$surcharge_money
  255. ];
  256. return $res;
  257. }
  258. // 根据快递订单号获取发货记录中的订单id
  259. public static function get_shopDelivery_id($waybill_no){
  260. $shopDeliveryModel=new ShopDelivery();
  261. $order_data=$shopDeliveryModel->where('waybill_no',$waybill_no)->find();
  262. if(empty($order_data)){
  263. return 0;
  264. }else{
  265. return $order_data['id'];
  266. }
  267. }
  268. }