123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- namespace app\fastshop\controller;
- use app\common\controller\Manage;
- use think\facade\Config;
- class Fare extends Manage{
- public function initialize() {
- parent::initialize();
- if(!model('auth')->getAuth($this->user->id,0)){
- $this->error('无权限,你非【超级管理员】');
- }
- $this->assign('pathMaps',[['name'=>'运费设置','url'=>url("fastshop/fare/index")]]);
- }
-
- public function index(){
- $view['info'] = model('Fare')->get(['member_miniapp_id' => $this->member_miniapp_id]);
- return view('index',$view);
- }
-
- public function save(){
- if(request()->isAjax()){
- $data = [
- 'first_weight' => input('post.first_weight/d'),
- 'first_price' => input('post.first_price/d'),
- 'second_weight' => input('post.second_weight/d'),
- 'second_price' => input('post.second_price/d'),
- ];
- $validate = $this->validate($data,'fare.save');
- if(true !== $validate){
- return json(['code'=>0,'msg'=>$validate]);
- }
- $rel = model('Fare')->get(['member_miniapp_id' => $this->member_miniapp_id]);
- if(empty($rel)){
- $data['member_miniapp_id'] = $this->member_miniapp_id;
- $result = model('Fare')->insert($data);
- }else{
- $result = model('Fare')->save($data,['member_miniapp_id' => $this->member_miniapp_id]);
- }
- if($result){
- return json(['code'=>200,'data' => ['url' => url('fastshop/fare/index')],'msg'=>'操作成功']);
- }else{
- return json(['code'=>0,'msg'=>'操作失败']);
- }
- }
- }
-
-
- public static function realAmount($item,$member_miniapp_id){
- $fare = self::where(['member_miniapp_id' => $member_miniapp_id])->find();
- $real_amount = 0;
- $real_freight = 0;
- $total = 0;
- foreach($item as $value){
- $real_amount += $value['amount'];
- $weight = $value['weight'] * $value['num'];
- if($weight <= $fare['first_weight'] || 0 == $fare['second_weight']){
- $total = $fare['first_price'];
- }else{
- $weight = $weight - $fare['second_weight'];
- $total = $fare['first_price'] + ceil($weight/$fare['second_weight']) * $fare['second_price'];
- }
- $real_freight += $total;
- }
- $data['real_amount'] = money($real_amount);
- $data['real_freight'] = money($real_freight);
- $data['order_amount'] = money($real_freight+$real_amount);
- return $data;
- }
- }
|