• 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;
        }
  • 相关阅读:
    Python 写Windows Service服务程序
    关于Python 获取windows信息收集
    Pyqt 获取windows系统中已安装软件列表
    Python 打开目录与指定文件
    【转载】Pyqt 编写的俄罗斯方块
    Python win32api提取exe图标icon
    Pyqt QListWidget之缩略图列表
    Pyqt 时时CPU使用情况
    Python 的三目运算
    Chrome Crx 插件下载
  • 原文地址:https://www.cnblogs.com/sgm4231/p/10490067.html
Copyright © 2020-2023  润新知