zoukankan      html  css  js  c++  java
  • 封装json输出

    /**
     * 输出json
     * @param $msg
     * @param int $errno
     */
    protected function printOutError($msg,$errno = 10099) {
        $this->json->setErr($errno, $msg);
        $this->json->Send();
    }
    
    /**
     * 输出json
     * @param array $out_data
     * @param string $msg
     */
    protected function printOutSuccess($out_data = [],$msg='操作成功') {
        $this->json->setErr(0, $msg);
        if ($out_data) {
            $this->json->setAttr('data', $out_data);
        }
        $this->json->Send();
    }
    

    具体使用

    /**
     * 删除订单,已完成的可以删除
     */
    public function delOrder() {
        if (!$uid = $_POST['uid']) {
            $this->printOutError('缺少用户id',10001);
        }
    
        if (!$order_id = $_POST['order_id']) {
            $this->printOutError('缺少订单id',10001);
        }
    
        $order = M('order');
        $order_info = $order->where(['id'=>$order_id,'is_user_del'=>0,'status'=>['gt',0]])->find();
        if (!$order_info) {
            $this->printOutError('订单不存在,或已删除/取消',10002);
        }
    
        if ((int)$order_info['status'] !== 4) {
            $this->printOutError('订单状态不可删除',10003);
        }
    
        $edit_data = [
            'is_user_del'=> 1
        ];
        $edit_flag = $order->where(['id'=>$order_id])->save($edit_data);
        if (!$edit_flag) {
            $this->printOutError('操作失败,请重试');
        } else {
            $this->printOutSuccess();
        }
    }
    

    清晰明了。

  • 相关阅读:
    CAP分布式
    专职DBA-MySQL数据库开篇
    os.sep
    DocStrings
    Python如何获取脚本的参数
    LVM基础命令
    VoAndEntityTrans
    短信倒计时
    springboot在eclipse上搭建项目一(无页面)
    springboot问题
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/10767273.html
Copyright © 2011-2022 走看看