zoukankan      html  css  js  c++  java
  • tp3.2 事务

    public function exchangeTransfer($user_id, $type, $money, $config, $other_id = 0)
        {
            $r['code'] = ERROR1;
            $r['msg'] = L('parameter_error');
            $r['result'] = [];
            if (intval($user_id) && !empty($money)) {
                $uuc_money = M('UucMoney')->where(['user_id'=>$user_id])->find();
                if(!$uuc_money && !$this->otherMoneyInit($user_id)){
                    $r['code'] = ERROR4;
                    $r['msg'] = $this->logic_error;
                    return $r;
                }
                // 互转时给对方账户初始化
                if($other_id>0 && !$this->otherMoneyInit($other_id)){
                    $r['code'] = ERROR5;
                    $r['msg'] = $this->logic_error;
                    return $r;
                }
                $balance = $uuc_money['exchange_money']; // 账户余额
                try {
                    $model = M();
                    $model->startTrans();
                    switch($type){
                        case 1: // 后台充值
                            if(!$this->exchangeRecharge($user_id, $money, $config)){
                                throw new Exception($this->logic_error);
                            }
                            break;
                        case 2: // 后台扣除
                            if(!$this->exchangeDeduction($user_id, $money, $balance, $config)){
                                throw new Exception($this->logic_error);
                            }
                            break;
                        case 4:  // 转出其他用户
                            if(!$this->exchangeToOtherExchange($user_id, $money, $balance, $config, $other_id)){
                                throw new Exception($this->logic_error);
                            }
                            break;
                        default:
                            throw new Exception(L('type_error'));
                    }
    
                    $model->commit();
                    $r['msg'] = L('success_operation');
                    $r['code'] = SUCCESS;
                } catch (Exception $e) {
                    $model->rollback();
                    $r['msg'] = $e->getMessage();
                    $r['code'] = ERROR3;
                }
            }
            return $r;
        }
  • 相关阅读:
    mysql 每条数据增加随机数
    Linux 的VSFTP报错
    Linux 常见命令指南
    Python文件
    Python合并2个文件
    J2ME获取移动手机号码
    不同角度来理解面向对象的几个关键性概念
    打印字符串中第一个只出现一次的字符(C语言)
    ftp上传文件
    ftp上传到nas
  • 原文地址:https://www.cnblogs.com/sgm4231/p/10490067.html
Copyright © 2011-2022 走看看