ShopService.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace biz\shop\services;
  3. use biz\base\services\BaseService;
  4. use biz\shop\classes\ShopClass;
  5. use common\components\stringUtil;
  6. use common\components\util;
  7. use Yii;
  8. class ShopService extends BaseService
  9. {
  10. public static $baseFile = '\biz\shop\classes\ShopClass';
  11. //计算运费 ssh 2019.12.4
  12. public static function getSendCost($lat, $lng, $jsStatDistance, $shopInfo)
  13. {
  14. //门店纬度
  15. $shopLat = $shopInfo['shopLat'];
  16. //门店经度
  17. $shopLong = $shopInfo['long'];
  18. //后端计算距离再确认
  19. $phpStatDistance = util::getDistance($shopLat, $shopLong, $lat, $lng);
  20. if ($phpStatDistance > $jsStatDistance) {
  21. util::fail('前端计算距离有误!');
  22. }
  23. $sjId = $shopInfo['sjId'];
  24. $ext = MerchantExtendService::getBySjId($sjId);
  25. $freight = MerchantExtendService::getFreight($ext);
  26. $firstDistance = $freight[0];
  27. $addPrice = $freight[1];
  28. $remainDistance = $jsStatDistance > $firstDistance ? stringUtil::calcSub($jsStatDistance, $firstDistance) : 0;
  29. $sendCost = ceil($remainDistance * 1000 / 1000 / 1000) * $addPrice;
  30. return $sendCost;
  31. }
  32. //获取默认门店信息 ssh 2019.12.6
  33. public static function getDefaultShop($merchant)
  34. {
  35. $defaultShopId = $merchant['defaultShopId'];
  36. return ShopClass::getById($defaultShopId);
  37. }
  38. //验证门店
  39. public static function valid($shopInfo, $sjId)
  40. {
  41. ShopClass::valid($shopInfo, $sjId);
  42. }
  43. public static function getShopList($where)
  44. {
  45. $list = ShopClass::getShopList($where);
  46. return $list;
  47. }
  48. //获取默认门店 ssh 2020.1.19
  49. public static function getDefaultShopId($merchant)
  50. {
  51. return ShopClass::getDefaultShopId($merchant);
  52. }
  53. //更新门店 ssh 2020.2.29
  54. /*public static function updateShop($id, $data)
  55. {
  56. return ShopClass::updateShop($id, $data);
  57. }*/
  58. //删除门店 ssh 2020.3.1
  59. /*public static function deleteShop($shop)
  60. {
  61. return ShopClass::deleteShop($shop);
  62. }*/
  63. //获取收款码 ssh 2020.3.9
  64. /*public static function generateGatheringCode($sjId, $shopId)
  65. {
  66. return ShopClass::generateGatheringCode($sjId, $shopId);
  67. }*/
  68. //根据商家ID,获取所有门店 shopIds lqh 2021.3.4
  69. public static function getShopIds($sjId)
  70. {
  71. $shops = ShopClass::getAllShop($sjId);
  72. $shopIds = [];
  73. if($shops){
  74. $shopIds = array_column($shops,'id');
  75. }
  76. return $shopIds;
  77. }
  78. //获取门店资产信息 lqh 2021.4.14
  79. public static function getById($shopId, $returnObj = false)
  80. {
  81. return ShopClass::getById($shopId, $returnObj);
  82. }
  83. //总订单加1
  84. public static function totalOrderPlus($shopId)
  85. {
  86. $shop = ShopClass::getById($shopId);
  87. if($shop){
  88. $data = [
  89. 'totalOrder'=>$shop['totalOrder'] + 1
  90. ];
  91. ShopClass::updateById($shopId,$data);
  92. }
  93. }
  94. //更新总收入
  95. public static function updateTotalIncome($shopId,$amount)
  96. {
  97. $shop = ShopClass::getById($shopId);
  98. if($shop){
  99. $data = [
  100. 'totalIncome'=>bcadd($shop['totalIncome'],$amount,2)
  101. ];
  102. ShopClass::updateById($shopId,$data);
  103. }
  104. }
  105. //更新总访问数 +1
  106. public static function totalViewPlus($shopId)
  107. {
  108. $shop = ShopClass::getById($shopId);
  109. if($shop){
  110. $data = [
  111. 'totalView'=>$shop['totalView'] + 1
  112. ];
  113. ShopClass::updateById($shopId,$data);
  114. }
  115. }
  116. }