OrderpageController.php 14.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
<?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();
        if(!empty($indet_id['address_id'])){
            $address = Db::name('address') -> where('id',$indet_id['address_id']) -> find();
            $this -> assign('address',$address);
            $this -> assign('address_id',$indet_id['address_id']);
        }else{
            $address = Db::name('address') -> where("uid=".$uid." and default_address=1 and delete_time = 0") -> find();
            if(empty($address)){
                $this -> assign('address',4);
                $this -> assign('address_id','');
            }else{
                $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);
                $this -> assign('address_id',$address['id']);
            }
        }

        $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']);
        $this -> assign('type',5);
        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);
        //判断这个用户所属哪个业务员
        $uid = cmf_get_current_user_id();
        $user = Db::name('my_user') -> where('uid',$uid) -> find();
        //当当前用户为老师时
        if($user['status'] == 3){
            $salesman = Db::name('my_user') -> where('id',$user['pid']) -> find();
        }
        //当前用户为学生时
        if($user['status'] == 4){
            $teacher = Db::name('my_user') -> where('id',$user['pid']) -> find();
            $salesman = Db::name('my_user') -> where('id',$teacher['pid']) -> find();
        }
        // 查询业务员是否设置过邮费
        $user_postage = Db::name('user_postage')->where('user_id',$salesman['uid'])->find();
        if($user_postage) {
            $courier = $user_postage['money'];
        } else {
            $courier = Db::name('money_ratio') -> where('id',1) -> value('courier');
        }

        $this -> assign('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);
        //判断这个用户所属哪个业务员
        $user = Db::name('my_user') -> where('uid',$uid) -> find();
        //当当前用户为老师时
        if($user['status'] == 3){
            $salesman = Db::name('my_user') -> where('id',$user['pid']) -> find();
        }
        //当前用户为学生时
        if($user['status'] == 4){
            $teacher = Db::name('my_user') -> where('id',$user['pid']) -> find();
            $salesman = Db::name('my_user') -> where('id',$teacher['pid']) -> find();
        }
        // 查询业务员是否设置过邮费
        $user_postage = Db::name('user_postage')->where('user_id',$salesman['uid'])->find();
        if($user_postage) {
            $courier = $user_postage['money'];
        } else {
            $courier = Db::name('money_ratio') -> where('id',1) -> value('courier');
        }
        $this -> assign('courier',$courier);
        $money['money'] = $money['money']+$courier;
        $this -> assign('money',$money['money']);
        if(empty($indent_id['address_id'])){
            $address = Db::name('address') -> where("uid=".$uid." and default_address=1 and delete_time = 0") -> find();
        }else{
            $address = Db::name('address') -> where('id',$indent_id['address_id']) -> find();
        }

        if(empty($address)){
            $this -> assign('address',4);
        }else{
            $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'];
                $indet_data_update['region'] = $address['region'];
                $indet_data_update['region_detail'] = $address['detailed'];
                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);
       return true;

    }

    /**
     * 取消支付时
     */
    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(){
        $param = $this->request->param();
        $param['is_courier'] = 2;
        $address = Db::name('address')->where('id',$param['indent_address'])->find();
        if(!$address) {
            return false;
        }
        $param['name'] = $address['name'];
        $param['phone'] = $address['phone'];
        $data = Db::name('indent') -> update($param);
        return true;

    }

    /**
     * 点击学校时获取年级班级
     */
    public function get_grade_class(){

        $school_id = $_POST['id'];
        $grade_class = Db::name('grade_class') -> where("school_id",$school_id) -> select() -> toArray();
        if(!empty($grade_class)){
            foreach ($grade_class as $key => $val){
                $class = explode('-',$val['class']);
                for($i=$class[0];$i<=$class[1];$i++){
                    $grade_class_show[] = $val['grade'].' - '.$i."班";
                }
            }
            return json_encode($grade_class_show);
        }else{
            return false;
        }

    }

    /**
     * 业务员统一配送页去支付
     */
    public function salesman_ty_go_pay(){

        $_POST['is_courier'] = 1;
        $class = explode('-',$_POST['grade']);
        $_POST['grade'] = trim($class[0]);
        $_POST['class'] = trim($class[1]);
        $indent_data['id'] = $_POST['id'];
        $indent_data['region'] = $_POST['region'];
        $indent_data['name'] = $_POST['name'];
        $indent_data['phone'] = $_POST['phone'];
        $indent_data['is_courier'] = $_POST['is_courier'];
        $indent_data['school'] = $_POST['school'];
        $indent_data['grade'] = $_POST['grade'];
        $indent_data['class'] = $_POST['class'];
        $indent_data['leave_word'] = $_POST['leave_word'];
        $indent_data['beiyong_address'] = $_POST['beiyong_address'];
        $data = Db::name('indent') -> update($indent_data);
        if($data){
           return true;
        }else{
            return false;
        }

    }

    /**
     * 显示收货地址
     */
    public function go_add_address(){

        $indent_id = $this -> request -> param();
        $uid = cmf_get_current_user_id();
        $data = Db::name('address') -> where("delete_time = 0 and uid =".$uid) ->  select() -> toArray();
        $this -> assign('indent_id',$indent_id['indet_id']);
        $this -> assign('data',$data);
        if(!empty($indent_id['type'])){
            $this -> assign('type',5);
        }else{
            $this -> assign('type',6);
        }
        return $this -> fetch();

    }

    /**
     * 获取学校
     */
    public function get_school(){
        $user_id = $this->request->param('user_id');
        if(empty($user_id)){
            $user_id = cmf_get_current_user_id();
        }
        $my_user = Db::name('my_user')->where('uid',$user_id)->find();
        if($my_user['status'] == 3){
            $my_user2 = Db::name('my_user')->where('id',$my_user['pid'])->find();
        }else{
            $my_user3 = Db::name('my_user')->where('id',$my_user['pid'])->find();
            $my_user2 = Db::name('my_user') -> where('id',$my_user3['pid']) -> find();
        }

        $area = $this->request->param('area',0);
        if(empty($area)){
            $this->error('缺少必要参数');
        }
        //查询这个用户下添加的学校
        $school_uids = [];
        $school_uids[] = !empty($my_user2['uid']) ? $my_user2['uid'] : 0;
        if($my_user['status'] == 3){
            $school_uids[] = $user_id;
        }
        if($my_user['status'] == 4){
            $school_uids[] = $my_user3['uid'];
        }
        $where['region'] = ['like',"%$area%"];
        $where['uid'] = ['in',$school_uids];
        $data = Db::name('school')->where($where)->select()->toArray();
        //循环组建新数据
        foreach ($data as $key=>$val){
            $datas[$key]['value'] = $val['id'];
            $datas[$key]['text'] = $val['school'];
        }
        if(!empty($datas)){
            return json_encode($datas);
        }else{
            return false;
        }

//        $this->success('SUCCESS','',$datas);
    }

    /**
     * 新增地址页
     */
    public function add_shop_address(){

        if($this -> request -> isPost()){
            $uid = cmf_get_current_user_id();
            $_POST['uid'] = $uid;
            $add = Db::name('address') -> insert($_POST);
            if($add){
                return true;
            }else{
                return false;
            }
        }else{
            $indent_id = $this -> request -> param();
            $this -> assign('indent_id',$indent_id['indet_id']);
            if($indent_id['type']==5){
                $this -> assign('type',5);
            }else{
                $this -> assign('type',6);
            }
            return $this -> fetch();
        }

    }

    /**
     * 编辑地址
     */
    public function address_edit(){

        if($this -> request -> isPost()){
            $data_update = Db::name('address') -> update($_POST);
            if($data_update){
                return true;
            }else{
                return false;
            }
        }else{
            $id = $this -> request -> param();
            $data = Db::name('address') -> where('id',$id['id']) -> find();
            $this -> assign('data',$data);
            $this -> assign('indent_id',$id['indet_id']);
            if($id['type']==5){
                $this -> assign('type',5);
            }else{
                $this -> assign('type',6);
            }
            return $this -> fetch();
        }

    }















}