where('uid',$loginUserInfo['id'])->find(); // print_r($vipinfo); if(!empty($loginUserInfo) && !empty($vipinfo)) { $whereToday = [['uid','=',$loginUserInfo['id']],['type','=',$type],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid'],['is_time','=',1]] ]; $whereTotal = [['uid','=',$loginUserInfo['id']],['type','=',$type],['create_time','>',$vipinfo['update_time']],['uniacid','=',$_GPC['uniacid'],['is_time','=',1]] ]; } $numberAlias = !empty($conf['number_alias'])?$conf['number_alias']:'点数'; if(!empty($conf['time_member']) && $conf['time_member'] ==1 && !empty($loginUserInfo['vip_time']) && ($loginUserInfo['vip_time'] >= time() || $loginUserInfo['vip_time'] ==9999) && !empty($vipinfo)){ if($vipinfo[$type.'_times'] == 0){ if($loginUserInfo['coin'] <$coin){ return ['status'=>false,'msg'=>'会员套餐内使用量已用完,且'.$numberAlias.'不足']; } }else{ // 开了会员,并此用户是有效会员 // 会员内有数量限制 if($vipinfo[$type.'_times'] > 0 ){ if($vipinfo[$type.'_type'] == 'time'){ $used = \app\model\Bill::where($whereToday)->count(); }else{ $used = \app\model\Bill::where($whereTotal)->count(); } // print_r($used); if($used > $vipinfo[$type.'_times']){ if($loginUserInfo['coin'] <$coin){ return ['status'=>false,'msg'=>'套餐内使用次数不足']; } } } } }else{ if($loginUserInfo['coin'] <$coin){ return ['status'=>false,'msg'=>'套餐内使用次数不足']; } } } /** * 消费 * @param $token * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function cash($loginUserInfo,$type,$coin,$conf){ global $_GPC; $modelVipinfo =new \app\model\Vipinfo(); $vipinfo = $modelVipinfo->where('uid',$loginUserInfo['id'])->find(); $numberAlias = !empty($conf['number_alias'])?$conf['number_alias']:'点数'; if(!empty($loginUserInfo) && !empty($vipinfo)){ $whereToday = [['uid','=',$loginUserInfo['id']],['type','=',$type],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid']] ]; $whereTotal = [['uid','=',$loginUserInfo['id']],['type','=',$type],['create_time','>',$vipinfo['update_time']],['uniacid','=',$_GPC['uniacid']] ]; } $title=''; switch($type){ case 'gpt35': $title = !empty($conf['gpt35_alias']?$conf['gpt35_alias']:'GPT-3.5'); break; case 'gpt4': $title = !empty($conf['gpt4_alias']?$conf['gpt4_alias']:'GPT-4'); break; case 'sd': $title = !empty($conf['aipainting_alias']?$conf['aipainting_alias']:'StableDiffusion绘画'); break; case 'mj': $title = !empty($conf['aipainting_alias']?$conf['aipainting_alias']:'Midjourney绘画'); break; } if(!empty($conf['time_member']) && $conf['time_member'] ==1 && !empty($loginUserInfo['vip_time']) && ($loginUserInfo['vip_time'] >= time() || $loginUserInfo['vip_time'] ==9999) && !empty($vipinfo) ){ if($vipinfo[$type.'_times'] == 0){ if($loginUserInfo['coin'] <$coin){ return ['status'=>false,'msg'=>'会员套餐内使用量已用完,且'.$numberAlias.'不足']; }else{ \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update(); BillServiceFacade::record(0,$coin,$type,$title.'消耗'.$numberAlias,$loginUserInfo['id'],$_GPC['uniacid']); } }else{ if($vipinfo[$type.'_times']>0){ if($vipinfo[$type.'_type'] == 'time'){ $used = \app\model\Bill::where($whereToday)->count(); }else{ $used = \app\model\Bill::where($whereTotal)->count(); } if($used > $vipinfo[$type.'_times']){ if($loginUserInfo['coin'] <$coin){ return ['status'=>false,'msg'=>$numberAlias.'不足1']; }else{ \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update(); BillServiceFacade::record(0,$coin,$type,$title.'消耗'.$numberAlias,$loginUserInfo['id'],$_GPC['uniacid']); } }else{ $res = BillServiceFacade::record(0,1,$type,'消耗会员套餐内'.$type.'一次',$loginUserInfo['id'],$_GPC['uniacid'],true,$loginUserInfo['coin'],1); // if(isset($member['status']) && !$member['status']){ // return return ['status'=>false,'msg'=>$member['msg']]; // } } } } }else{ if($loginUserInfo['coin'] <$coin){ return ['status'=>false,'msg'=>$numberAlias.'不足']; }else{ \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update(); BillServiceFacade::record(0,$coin,$type,$title.'消耗'.$numberAlias,$loginUserInfo['id'],$_GPC['uniacid']); } } return ['status'=>true,'msg'=>'']; } /** * 积分 * @param $token * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function coin(){ \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update(); BillServiceFacade::record(0,$coin,$type,$title.'消耗'.$numberAlias,$loginUserInfo['id'],$_GPC['uniacid']); } /** * 会员 * @param $token * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function vip($loginUserInfo,$type,$coin,$conf) { global $_GPC; $modelVipinfo =new \app\model\Vipinfo(); $vipinfo = $modelVipinfo->where('uid',$loginUserInfo['id'])->find(); $where = [['uid','=',$loginUserInfo['id']],['type','=',$type],['is_time','=','1'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid'],['is_time','=',1]] ]; $numberAlias = !empty($conf['number_alias'])?$conf['number_alias']:'点数'; if(!empty($vipinfo)){ if($vipinfo[$type.'_type'] == 'time'){ $used = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=',$type],['is_time','=','1'],['create_time','>',date('Y-m-d 0:0:0')],['uniacid','=',$_GPC['uniacid'],['is_time','=',1]] ])->count(); if($used < $vipinfo[$type.'_times']){ $res = BillServiceFacade::record(0,$coin,$type,'问答消耗会员套餐内'.$type,$loginUserInfo['id'],$_GPC['uniacid'],true,$loginUserInfo['coin'],1); }else{ if($loginUserInfo['coin'] <$coin){ return ['status'=>false,'msg'=>$numberAlias.'不足']; }else{ \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update(); $res = BillServiceFacade::record(0,$coin,$type,'问答消耗'.$numberAlias,$loginUserInfo['id'],$_GPC['uniacid']); } } }else{ $used = \app\model\Bill::where([['uid','=',$loginUserInfo['id']],['type','=',$type],['is_time','=','1'],['create_time','>',$vipinfo['update_time'] ],['uniacid','=',$_GPC['uniacid']] ])->count(); if($used < $vipinfo[$type.'_times']){ \app\model\User::where(['id'=>$loginUserInfo['id']])->dec('coin',$coin)->update(); $res = BillServiceFacade::record(0,$coin,$type,'问答消耗'.$numberAlias,$loginUserInfo['id'],$_GPC['uniacid']); }else{ return ['status'=>false,'msg'=>'会员套餐内'.$type.'剩余次数不足']; } } } } }