You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

100 lines
3.5 KiB

<?php
namespace backend\modules\shop\logic;
use backend\modules\shop\models\ars\City;
use backend\modules\shop\models\ars\ExpressArea;
use backend\modules\shop\models\ars\Province;
use backend\modules\shop\models\ars\ExpressTemplate;
class ShopManager
{
//单位类型
const UNIT_TYPE_WEIGHT = 1; //重量
const UNIT_TYPE_MONEY = 2; //金额
const UNIT_TYPE_ITEM = 3; //件
/**
* @param $type
* @param $value
* @return int
* 比例转换
*/
public static function proportionalConversion($type)
{
switch ($type) {
case self::UNIT_TYPE_WEIGHT:
return 1000; //后台显示为kg,数据库保存为g
break;
case self::UNIT_TYPE_MONEY:
return 100; //后台显示为元,数据库保存为分
break;
case self::UNIT_TYPE_ITEM:
return 1; //后台显示和数据库都为件
break;
default:
return 1;
}
}
/**
* @param $expressAreaModel
* @param $expressTemplateModel
* 区域运费模板按比例转化数据
*/
public static function expressAreaScaleDate($expressAreaModel, $expressTemplateModel)
{
$expressAreaModel->basic_price *= self::proportionalConversion(self::UNIT_TYPE_MONEY);
$expressAreaModel->extra_price *= self::proportionalConversion(self::UNIT_TYPE_MONEY);
if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) {
$expressAreaModel->basic_count *= self::proportionalConversion(self::UNIT_TYPE_WEIGHT);
$expressAreaModel->extra_count *= self::proportionalConversion(self::UNIT_TYPE_WEIGHT);
} else {
$expressAreaModel->basic_count *= self::proportionalConversion(self::UNIT_TYPE_ITEM);
$expressAreaModel->extra_count *= self::proportionalConversion(self::UNIT_TYPE_ITEM);
}
}
/**
* @param $expressAresModel
* @return array
* 除去已被选取的城市,筛选剩下的城市数据
*/
public static function filterCity($expressAresModel)
{
$data = [];
$query = ExpressArea::find()
->select(['city'])
->where(['express_template' => $expressAresModel->express_template]);
if ($expressAresModel->id) { //修改操作时,除去自身的城市
$query = $query->andWhere(['!=', 'id', $expressAresModel->id]);
}
$expressAreas = $query->all();
//获取已选的城市id数组
$expressAresCityIdArr = [];
if ($expressAreas) {
foreach ($expressAreas as $expressAreaCity) {
$cityIdArr = explode(',', $expressAreaCity->city);
$expressAresCityIdArr = array_unique(array_merge($cityIdArr, $expressAresCityIdArr));
}
}
//筛选剩下的城市
$provinces = Province::find()->cache(0)->all();
$j = 0;
foreach ($provinces as $k => $v) {
$cities = City::find()
->where(['province_id' => $v->province_id])
->andWhere(['not in', 'city_id', $expressAresCityIdArr])
->all();
if ($cities) {
$data[$j]['province'] = $v->name;
foreach ($cities as $city) {
$data[$j]['city'][] = ['id' => $city->city_id, 'name' => $city->name];
}
$j++;
}
}
return $data;
}
}