| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 | <?phpnamespace app\api\controller;use app\common\controller\Api;use think\Db;/** * 解锁微信号和私密视频 */class Unlockorder extends Api{    protected $noNeedLogin = [];    protected $noNeedRight = ['*'];    //解锁微信订单    public function wechataccount(){        //检查用户        $to_user_id = input('to_user_id','');        if(empty($to_user_id)){            $this->error();        }        $to_user_info = Db::name('user')->find($to_user_id);        if(empty($to_user_info)){            $this->error('不存在的用户');        }        //检查防重复解锁        $check_map = [            'user_id' => $this->auth->id,            'to_user_id' => $to_user_id,            'endtime' => ['gt',time()],        ];        $check_repeat = Db::name('order_wechataccount')->where($check_map)->find();        if(!empty($check_repeat)){            $this->error('尚未过期无需再次解锁');        }        //订单        $price = config('site.unlock_wechataccount');        $price = bcadd(intval($price),0,0);        $data = [            'user_id' => $this->auth->id,            'to_user_id' => $to_user_id,            'createtime' => time(),            'endtime' => time() + 604800,            'price' => $price,        ];        Db::startTrans();        $order_id = Db::name('order_wechataccount')->insertGetId($data);        if(!$order_id){            Db::rollback();            $this->error('解锁失败');        }        if($price > 0){            $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',$price,71,'解锁:'.$to_user_info['username'],'order_wechataccount',$order_id);            if($wallet_rs['status'] === false){                Db::rollback();                $this->error($wallet_rs['msg']);            }        }        Db::commit();        $this->success('解锁成功');    }    //解锁私密视频订单    public function secretvideo(){        //检查用户        $to_user_id = input('to_user_id','');        if(empty($to_user_id)){            $this->error();        }        $to_user_info = Db::name('user')->find($to_user_id);        if(empty($to_user_info)){            $this->error('不存在的用户');        }        //检查防重复解锁        $check_map = [            'user_id' => $this->auth->id,            'to_user_id' => $to_user_id,            'endtime' => ['gt',time()],        ];        $check_repeat = Db::name('order_secretvideo')->where($check_map)->find();        if(!empty($check_repeat)){            $this->error('尚未过期无需再次解锁');        }        //订单        $price = config('site.unlock_secretvideo');        $price = bcadd(intval($price),0,0);        $data = [            'user_id' => $this->auth->id,            'to_user_id' => $to_user_id,            'createtime' => time(),            'endtime' => time() + 604800,            'price' => $price,            'type' => 1,        ];        //年费vip干预        $wallet = model('wallet')->getwallet($this->auth->id);        if($wallet['vip_endtime'] > time() && $wallet['vip_level'] == 30){            $data['price'] = 0;            $data['type'] = 2;            $data['endtime'] = time(); //立即过期,就看一下            $price = 0;        }        //log        Db::startTrans();        $order_id = Db::name('order_secretvideo')->insertGetId($data);        if(!$order_id){            Db::rollback();            $this->error('解锁失败');        }        if($price > 0){            $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',$price,72,'解锁:'.$to_user_info['username'],'order_secretvideo',$order_id);            if($wallet_rs['status'] === false){                Db::rollback();                $this->error($wallet_rs['msg']);            }        }        Db::commit();        $this->success('解锁成功');    }}
 |