JuShuiTanService.php 12 KB

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