| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace common\services;
- use common\components\util;
- use Yii;
- use common\components\stringUtil;
- use common\components\dict;
- use common\models\xhGoodsSetting;
- class xhGoodsSettingService {
- public static function getBySjId($sjId)
- {
- $user = xhGoodsSetting::find()->where(['sjId'=>$sjId])->asArray()->one();
- return $user;
- }
- public static function add($data,$sjId)
- {
- $return = xhGoodsSetting::add($data);
- return $return;
- }
- public static function updateBySjId($sjId,$data)
- {
- xhGoodsSetting::updateByCondition(['sjId'=>$sjId], $data);
- }
- /**
- * 将商品涨价
- */
- public static function unitySet($goods)
- {
- $sjId = $goods['sjId'];
- $set = self::getBySjId($sjId);
- $riseAmount = !empty($goods['riseAmount']) ? $goods['riseAmount'] : $set['riseAmount'];//单个商品有设置涨价金额则从商品里取
- $noRise = dict::getDict('riseType','noRise');
- $byPercent = dict::getDict('riseType','percent');
- $byAmount = dict::getDict('riseType','amount');
- if(!empty($set)){
- $goods['goodsIntroduce'] = $set['goodsIntroduce'];
- $goods['riseType'] = $noRise;
- $goods['riseAmount'] = $riseAmount;
- // if($set['riseType'] != $noRise){
- // $now = time();
- // if($now > $set['startRiseTime'] && $now < $set['endRiseTime']){
- // if($set['riseType'] == $byPercent){//百分比
- // $percent = $riseAmount / 100;
- // $goods['price'] = floor($goods['price']*(1+$percent));
- // }else{//金额
- // $goods['price'] = stringUtil::calcAdd($goods['price'], $riseAmount);
- // }
- // }
- // }
- }
- return $goods;
- }
- /**
- * 改写unitySet(将商品涨价)方法,传入价格参数,返回涨价
- */
- public static function changePrice($goods, $price)
- {
- $sjId = $goods['sjId'];
- $set = self::getBySjId($sjId);
- $riseAmount = !empty($goods['riseAmount']) ? $goods['riseAmount'] : $set['riseAmount'];//单个商品有设置涨价金额则从商品里取
- $noRise = dict::getDict('riseType','noRise');
- $byPercent = dict::getDict('riseType','percent');
- $byAmount = dict::getDict('riseType','amount');
- if(!empty($set)){
- $goods['goodsIntroduce'] = $set['goodsIntroduce'];
- $goods['riseType'] = $noRise;
- $goods['riseAmount'] = $riseAmount;
- if($set['riseType'] != $noRise){
- $now = time();
- if($now > $set['startRiseTime'] && $now < $set['endRiseTime']){
- if($set['riseType'] == $byPercent){//百分比
- $percent = $riseAmount / 100;
- $price = floor($price*(1+$percent));
- }else{//金额
- $price = stringUtil::calcAdd($price, $riseAmount);
- }
- }
- }
- }
- return $price;
- }
- }
|