| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 | <?phpnamespace app\common\model;use \think\Db;//use \com\Pay\Pay;/** * 订单支付模型 */class Recharge{    /**     * 支付回调     */    public function goldpaysucc($orderId,$args){        $order = Db::name('pay_order')->where(array('pay_no'=>$orderId,'status'=>2))->find();        if( $order )        {            Db::startTrans();            //更新订单状态            $rs = Db::name('pay_order')->where(['id'=>$order['id']])->update(['status'=>1]);            if(!$rs){                Db::rollback();                filePut('[wallet][paySucc] pay_order update fail'.$orderId);                abort(500,'订单更新失败');            }            //先充值            $result = model('Wallet')->lockChangeAccountRemain($args['user_id'],'gold',$args['gold'],10, '金币充值:'.$orderId,'pay_order',$order['id']);            if($result['status']===false)            {                Db::rollback();                filePut('[wallet][paySucc]网银充值入账更新余额失败 recharge money fail'.$orderId.$result['msg']);                abort(500,'网银充值入账 model wallet recharge money fail');            }            //首充            $first_map = [                'uid' => $args['user_id'],                'pg_id' => $args['pg_id'],            ];            $first_check = Db::name('user_paygold_log')->where($first_map)->find();            if(empty($first_check)){                //首充日志                $first_log_id = Db::name('user_paygold_log')->insertGetId($first_map);                if(!$first_log_id){                    Db::rollback();                    abort(500,'首充赠送失败');                }                //送金币                if(isset($args['first_gold']) && $args['first_gold'] > 0){                    $result = model('Wallet')->lockChangeAccountRemain($args['user_id'],'gold',$args['first_gold'],14, '金币充值:'.$orderId,'pay_order',$order['id']);                    if($result['status']===false)                    {                        Db::rollback();                        filePut('[wallet][paySucc]网银充值入账更新余额失败 recharge money fail'.$orderId.$result['msg']);                        abort(500,'网银充值入账 model wallet recharge money fail');                    }                }                //送vip                if(isset($args['first_vipdays']) && $args['first_vipdays'] > 0){                    $user_info = Db::name('user_wallet')->where('user_id',$args['user_id'])->lock(true)->find();                    if($user_info['vip_endtime'] < time()){                        //过期了                        $vip_endtime = time() + (intval($args['first_vipdays']) * 86400);                    }else{                        //追加vip                        $vip_endtime = $user_info['vip_endtime'] + (intval($args['first_vipdays']) * 86400);                    }                    $result = Db::name('user_wallet')->where('user_id',$args['user_id'])->update(['vip_endtime'=>$vip_endtime]);                    if($result === false)                    {                        Db::rollback();                        filePut('[wallet][paySucc]网银充值入账更新vip时间失败 recharge money fail'.$orderId);                        abort(500,'网银充值入账 model wallet recharge money fail');                    }                }            }            Db::commit();            return true;        }else{            filePut('[wallet][paySucc]在线支付订单有误 '.$orderId);            abort(500,'model wallet fail');            return false;        }    }    public function vippaysucc($orderId,$args){        $order = Db::name('pay_order')->where(array('pay_no'=>$orderId,'status'=>2))->find();        if( $order )        {            Db::startTrans();            //更新订单状态            $rs = Db::name('pay_order')->where(['id'=>$order['id']])->update(['status'=>1]);            if(!$rs){                Db::rollback();                filePut('[wallet][paySucc] pay_order update fail'.$orderId);                abort(500,'订单更新失败');            }            //先充值            $user_info = Db::name('user_wallet')->where('user_id',$args['user_id'])->lock(true)->find();            if($user_info['vip_endtime'] < time()){                //过期了                $vip_endtime = time() + (intval($args['days']) * 86400);            }else{                //追加vip                $vip_endtime = $user_info['vip_endtime'] + (intval($args['days']) * 86400);            }            $result = Db::name('user_wallet')->where('user_id',$args['user_id'])->update(['vip_endtime'=>$vip_endtime]);            if($result === false)            {                Db::rollback();                filePut('[wallet][paySucc]网银充值入账更新vip时间失败 recharge money fail'.$orderId);                abort(500,'网银充值入账 model wallet recharge money fail');            }            Db::commit();            //再扣款            /* Db::startTrans();             //需要更新某个支付表             if(isset($args['payids']) && $args['payids'])             {                 logic('Cashier')->paySuccess($args,true);                 filePut('[wallet][paySucc] end success '.$orderId);            }            Db::commit();*/            return true;        }else{            filePut('[wallet][paySucc]在线支付订单有误 '.$orderId);            abort(500,'model wallet fail');            return false;        }    }}
 |