|
|
@ -1,10 +1,12 @@ |
|
|
|
<?php |
|
|
|
namespace backend\modules\shop\logic; |
|
|
|
|
|
|
|
use Yii; |
|
|
|
use yii\base\Exception; |
|
|
|
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 CommonManager |
|
|
|
class ShopManager |
|
|
|
{ |
|
|
|
//单位类型
|
|
|
|
const UNIT_TYPE_WEIGHT = 1; //重量
|
|
|
@ -17,20 +19,82 @@ class CommonManager |
|
|
|
* @return int |
|
|
|
* 比例转换 |
|
|
|
*/ |
|
|
|
public static function proportionalConversion($type, $value) |
|
|
|
public static function proportionalConversion($type) |
|
|
|
{ |
|
|
|
switch ($type) { |
|
|
|
case self::UNIT_TYPE_WEIGHT: |
|
|
|
return 1000; |
|
|
|
return 1000; //后台显示为kg,数据库保存为g
|
|
|
|
break; |
|
|
|
case self::UNIT_TYPE_MONEY: |
|
|
|
return 100; |
|
|
|
return 100; //后台显示为元,数据库保存为分
|
|
|
|
break; |
|
|
|
case self::UNIT_TYPE_ITEM: |
|
|
|
return 1; |
|
|
|
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; |
|
|
|
} |
|
|
|
} |