审查视图

app/portal/controller/OrderController.php 2.9 KB
王晓刚 authored
1 2 3 4 5 6 7 8 9 10 11
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/5
 * Time: 19:55
 */

namespace app\portal\controller;

王晓刚 authored
12
use app\portal\model\AddressModel;
13 14
use app\portal\model\IndentGoodsModel;
use app\portal\model\IndentModel;
王晓刚 authored
15 16 17 18
use cmf\controller\WeChatBaseController;

class OrderController extends WeChatBaseController
{
19 20 21 22 23 24 25
    /**
     * 全部订单
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
王晓刚 authored
26
    public function get_all(){
27 28 29 30
        $state = $this->request->param('state',0,'intval');
//        if(!empty($state)){
//            $where1['state'] = ['eq',$state];
//        }
王晓刚 authored
31
        $user_id = cmf_get_current_user_id();
32 33 34
        $indentModel = new IndentModel();
        $where1['uid'] = ['eq',$user_id];
        $data = $indentModel->selectData($where1);
王晓刚 authored
35
        if(!empty($data)){
36
            $indentGoodsModel = new IndentGoodsModel();
王晓刚 authored
37
            foreach($data as $key => $vo){
38 39 40
                $where2['indent_id'] = ['eq',$vo['id']];
                $indentGoods = $indentGoodsModel->selectData($where2);
                $data[$key]['indent_goods'] = $indentGoods;
王晓刚 authored
41 42
            }
        }
43 44 45 46 47 48 49 50 51 52 53 54 55
        $this->assign('data',$data);
        $this->assign('state',$state);
        return $this->fetch();
    }
    public function get_one(){
        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this->error('缺少必要参数','','','');
        }
        $user_id = cmf_get_current_user_id();
        $where1['uid'] = ['eq',$user_id];
        $where1['id'] = ['eq',$id];
        $indentModel = new IndentModel();
王晓刚 authored
56
        $data = $indentModel->findData($where1)->toArray();
57 58 59 60 61 62
        if(empty($data)){
            $this->error('未查询到该订单','','','');
        }
        $where2['indent_id'] = ['eq',$data['id']];
        $indentGoodsModel = new IndentGoodsModel();
        $indentGoods = $indentGoodsModel->selectData($where2);
王晓刚 authored
63 64 65
        $addressModle = new AddressModel();
        $address = $addressModle->findData(['id'=>$data['indent_address']])->toArray();
        $data['address'] = $address;
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
        $data['indent_goods'] = $indentGoods;
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function cancel_order(){
        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this->error('缺少必要参数','','','');
        }
        $where1['id'] = ['eq',$id];
        $indentModel = new IndentModel();
        $data = $indentModel->findData($where1);
        if(empty($data)){
            $this->error('缺少必要参数','','','');
        }
        if($data['state'] != 4){
            $this->error('订单不是待支付状态','','','');
        }
        $result = $indentModel->deleteData($where1);
        if(empty($result)){
            $this->error('sql执行失败','','','');
        }
王晓刚 authored
88
        $this->success('SUCCESS');
王晓刚 authored
89 90
    }
}