OrderpageController.php 6.8 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;

use cmf\controller\WeChatBaseController;
use think\Db;

class OrderpageController extends WeChatBaseController{

    /**
     * 显示平台订单页
     */
    public function order_page(){

        $indet_id = $this -> request -> param();
        $uid = cmf_get_current_user_id();
        $address = Db::name('address') -> where("uid=".$uid." and default_address=1 and delete_time = 0") -> find();
        if(empty($address)){
            $this -> assign('address',4);
        }else{
            $address_arr = explode(',',$address['detailed']);
            $address['detailed'] = $address_arr[0].$address_arr[1];
            $indet_data = Db::name('indent') -> where("id",$indet_id['indet_id']) -> find();
            if($indet_data['state'] == 4){
                $indet_data_update['id'] = $indet_id['indet_id'];
                $indet_data_update['indent_address'] = $address['id'];
                $indet_data_update['name'] = $address['name'];
                $indet_data_update['phone'] = $address['phone'];
                Db::name('indent')  -> update($indet_data_update);
            }
            $this -> assign('address',$address);
        }

        $data = Db::name('indent_goods') -> where('indent_id',$indet_id['indet_id']) -> select() -> toArray();
        foreach ($data as $key => $val){
            $pricing = explode('.',$val['pricing']);
            $data[$key]['pricing0'] = $pricing[0];
            $data[$key]['pricing1'] = $pricing[1];
        }
        $money = Db::name('indent') -> where('id',$indet_id['indet_id']) -> find();
        $this -> assign('money',$money['money']);
        $this -> assign('data',$data);
        $this -> assign('indent_id',$indet_id['indet_id']);
        return $this -> fetch();

    }

    /**
     * 显示业务员统一订单页mmmmm
     */
    public function order_salesman_ty(){

        $indet_id = $this -> request -> param();
        $data = Db::name('indent_goods') -> where('indent_id',$indet_id['indet_id']) -> select() -> toArray();
        foreach ($data as $key => $val){
            $pricing = explode('.',$val['price']);
            $data[$key]['price0'] = $pricing[0];
            $data[$key]['price1'] = $pricing[1];
        }
        $money = Db::name('indent') -> where('id',$indet_id['indet_id']) -> find();
        $money['money'] = explode('.',$money['money']);
        $this -> assign('money',$money['money']);
        $this -> assign('data',$data);
        $courier = Db::name('money_ratio') -> where('id',1) -> find();
        $this -> assign('courier',$courier['courier']);
        $this -> assign('indent_id',$indet_id['indet_id']);
        return $this -> fetch();

    }

    /**
     * 商品数量加一
     */
    public function shop_cart_numadd(){

        $id = $_POST['id'];
        $data = Db::name('indent_goods') -> where('id',$id) -> find();
        if($data['number']<200){
            $res = Db::name('indent_goods') -> where('id',$id) -> setInc('number');
            $indent_id = Db::name('indent_goods') -> where('id',$id) -> find();
            Db::name('indent') -> where('id',$indent_id['indent_id']) -> setInc('money',$_POST['price']);
        }
        return true;

    }

    /**
     * 商品数量减一
     */
    public function shop_cart_numdec(){

        $id = $_POST['id'];
        $data = Db::name('indent_goods') -> where('id',$id) -> find();
        if($data['number']>1){
            Db::name('indent_goods') -> where('id',$id) -> setDec('number');
            $indent_id = Db::name('indent_goods') -> where('id',$id) -> find();
            Db::name('indent') -> where('id',$indent_id['indent_id']) -> setDec('money',$_POST['price']);
        }
        return true;

    }

    /**
     * 显示业务员快递订单页
     */
    public function order_salesman_kd(){

        $uid = cmf_get_current_user_id();
        $indent_id = $this -> request -> param();
        $money = Db::name('indent') -> where("id =".$indent_id['indet_id']) -> find();
        $indent_goods_data = Db::name('indent_goods') -> where('indent_id',$indent_id['indet_id']) -> select();
        $this -> assign('data',$indent_goods_data);
        $courier = Db::name('money_ratio') -> where('id',1) -> find();
        $this -> assign('courier',$courier['courier']);
        $money['money'] = $money['money']+$courier['courier'];
        $this -> assign('money',$money['money']);

        $address = Db::name('address') -> where("uid=".$uid." and default_address=1 and delete_time = 0") -> find();
        if(empty($address)){
            $this -> assign('address',4);
        }else{
            $address_arr = explode(',',$address['detailed']);
            $address['detailed'] = $address_arr[0].$address_arr[1];
            $indet_data = Db::name('indent') -> where("id",$indent_id['indet_id']) -> find();
            if($indet_data['state'] == 4){
                $indet_data_update['id'] = $indent_id['indet_id'];
                $indet_data_update['indent_address'] = $address['id'];
                $indet_data_update['name'] = $address['name'];
                $indet_data_update['phone'] = $address['phone'];
                Db::name('indent')  -> update($indet_data_update);
            }
            $this -> assign('address',$address);
        }
        $this -> assign('indet_id',$indent_id['indet_id']);
        return $this -> fetch();

    }

    /**
     * 业务员快递去支付
     */
    public function salesman_go_pay(){

        $_POST['is_courier'] = 2;
        $data_update = Db::name('indent') -> update($_POST);
        if($data_update){
          return true;
        }else{
            return false;
        }

    }

    /**
     * 取消支付时
     */
    public function cancel_pay(){

        $indent_id = $this -> request -> param();
        $data = Db::name('indent') -> where('id',$indent_id['id']) -> find();
        $money_ratio = Db::name('money_ratio') -> where('id',1) -> find();
        if($data['indent_type'] == 2 && $data['is_courier'] == 2){
            Db::name('indent') -> where('id',$indent_id['id']) -> setDec('money',$money_ratio['courier']);
        }
        $this -> redirect('index/index');

    }

    /**
     * 平台商品去支付时 更新买家留言
     */
    public function goods_leave_word_update(){

        $data = Db::name('indent') -> update($_POST);
        if($data){
            return true;
        }else{
            return false;
        }

    }

















}