SalesOrderController.php 2.9 KB
<?php
/**
 * Created by PhpStorm.
 * User: 29925
 * Date: 2018/8/21
 * Time: 11:53
 */

namespace app\user\controller;

use cmf\controller\UserBaseController;
use think\Validate;

class SalesOrderController extends UserBaseController
{
    protected $table;
    function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
        $this->table = 'OrderSort';
    }

    /**
     * 添加电子订单(选择类型)
     */
    public function index() {
        $where = [
            'delete_time'=>0
        ];
        $list = $this->singleData($this->table,$where,1,['create_time'=>'DESC']);
        $this->assign('list',$list);
        return $this->fetch();
    }

    /**
     * 添加电子订单(完善内容)
     */
    public function detail() {
        $sort = $this->request->param('sort');
        $where = [
            'id' => $sort,
            'delete_time'=>0
        ];
        $orderSort = $this->singleData($this->table,$where);
        if(!$orderSort) {
            $this->error('订单类型错误');
        }
        $orderSort['options'] = json_decode($orderSort['options'],true);
        $this->assign('orderSort',$orderSort);
        return $this->fetch();
    }

    /**
     * 提交电子订单
     * @param $options 填写的订单内容
     */
    public function addOrder() {
        if($this->request->isAjax()) {
            $data = $this->request->param();
            $validate = new Validate([
//                'captcha'  => 'require',
                'username' => 'require',
                'password' => 'require',
            ]);
            $validate->message([
                'username.require' => '用户名不能为空',
                'password.require'     => '密码不能为空',
//                'captcha.require'  => '验证码不能为空',
            ]);

            $data = $this->request->post();
            if (!$validate->check($data)) {
                $this->error($validate->getError());
            }
        }
    }

    /**
     * 查看已提交订单
     */
    public function orders() {
        $user_id = cmf_get_current_user_id();
        $where = [
            'user_id' => $user_id,
            'delete_time' => 0
        ];
        $list = $this->singleData('OrderView',$where,2,['create_time'=>'DESC']);
        $this->assign('list' ,$list);
        return $this->fetch();
    }

    /**
     * 编辑电子订单
     * @param $id 电子订单ID
     */
    public function edit() {
        $id = $this->request->param('id');
        if(!$id) {
            $this->error('参数错误');
        }
        $user_id = cmf_get_current_user_id();
        $where = [
            'user_id' => $user_id,
            'delete_time' => 0
        ];
        $orderInfo = $this->singleData('OrderView',$where);
        $orderInfo['options'] = json_decode($orderInfo['options'],true);
        $this->assign('info',$orderInfo);
        return $this->fetch();
    }
}