| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- <?php
- namespace App\Models;
- use App\Facade\TableName;
- use App\Util;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- class RecordPlatformData extends Model
- {
- public $connection = 'read';
- protected $table = 'QPRecordDB.dbo.RecordPlatformData';
- public $timestamps = false;
- // 按天获取注册,充值,活跃等
- public function dayAccountInfo($startDateID, $endDateID)
- {
- return self::query()
- ->where('Channel', -1)
- ->whereBetween('DateID', [$startDateID, $endDateID])
- ->selectRaw('IsNull(sum(RegPeple),0) RegPeple,IsNull(sum(ActivePeple),0) ActivePeple,IsNull(sum(PayPeple),0) PayPeple,IsNull(sum(PayTotal),0) PayTotal,IsNull(sum(DrawTotal),0) DrawTotal')
- ->first();
- }
- // 按天获取注册用户
- public function registerDay($startDateID, $endDateID)
- {
- return self::query()
- ->where('Channel', -1)
- ->whereBetween('DateID', [$startDateID, $endDateID])
- ->sum('RegPeple');
- }
- // 按天获取活跃用户
- public function ActiveDay($startDateID, $endDateID)
- {
- return self::query()
- ->where('Channel', -1)
- ->whereBetween('DateID', [$startDateID, $endDateID])
- ->sum('ActivePeple');
- }
- // 按天获取充值用户
- public function WithdrawDay($startDateID, $endDateID)
- {
- return self::query()
- ->where('Channel', -1)
- ->whereBetween('DateID', [$startDateID, $endDateID])
- ->sum('PayPeple');
- }
- /**
- * 增加提现成功手续费记录
- * @param $UserID
- * @param $Free
- */
- public function WithdrawFree($UserID, $Free)
- {
- $DateID = Carbon::now()->format('Ymd');
- $Channel = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
- ->where('UserID', $UserID)
- ->value('Channel');
- if (DB::table(TableName::QPRecordDB() . 'RecordPlatformData')->where(['DateID' => $DateID, 'Channel' => -1])->value('DateID')) {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['DateID' => $DateID, 'Channel' => -1])
- ->update(['WithdrawFree' => DB::raw("WithdrawFree+$Free")]);
- } else {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['DateID' => $DateID, 'Channel' => -1, 'WithdrawFree' => $Free]);
- }
- if (DB::table(TableName::QPRecordDB() . 'RecordPlatformData')->where(['DateID' => $DateID, 'Channel' => $Channel])->value('DateID')) {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['DateID' => $DateID, 'Channel' => $Channel])
- ->update(['WithdrawFree' => DB::raw("WithdrawFree+$Free")]);
- } else {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['DateID' => $DateID, 'Channel' => $Channel, 'WithdrawFree' => $Free]);
- }
- }
- // 复购用户人数,充值金额
- public function OldUser($UserID, $Channel, $money, $Extra,$type = 3)
- {
- Util::WriteLog('RecordPlatformDataOld',[$UserID, $Channel, $money, $Extra,$type]);
- $dateID = Carbon::now()->format('Ymd');
- $queryUserID = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')->where('UserID', $UserID)
- ->whereDate('RegisterDate', '<', date('Y-m-d'))
- ->value('UserID');
- if (empty($queryUserID)) { // 不是老用户直接返回
- return true;
- }
- // 判断以前有没有充值
- // if (DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')->where('UserID', $UserID)->first()) {
- // if ($Extra == 1) {
- $AllFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => -1, 'DateID' => $dateID])
- ->select('DateID')
- ->first();
- // 当日单用户,第一次充值增加人数
- $addPayPeple = 0;
- if ($Extra == 1) {
- $addPayPeple = 1;
- }
- if ($AllFormData) {
- if($type == 3){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['OldUserPayCount' => DB::raw("OldUserPayCount+$addPayPeple"), 'OldUserPayBi' => DB::raw('OldUserPayBi+1'), 'OldUserPaySum' => DB::raw("OldUserPaySum+$money")]);
- }elseif($type == 4){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['OldUserWithdrawCount' => DB::raw("OldUserWithdrawCount+$addPayPeple"), 'OldUserWithdrawBi' => DB::raw('OldUserWithdrawBi+1'),'OldUserWithdrawSum' => DB::raw("OldUserWithdrawSum+$money")]);
- }
- } else {
- if($type == 3){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['OldUserPayCount' => 1, 'OldUserPayBi' => 1, 'OldUserPaySum' => $money, 'Channel' => -1, 'DateID' => $dateID]);
- }elseif($type == 4){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['OldUserWithdrawCount' => 1, 'OldUserWithdrawBi' => 1, 'OldUserWithdrawSum' => $money, 'Channel' => -1, 'DateID' => $dateID]);
- }
- }
- $ChannelFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => $Channel, 'DateID' => $dateID])
- ->select('DateID')
- ->first();
- if ($ChannelFormData) {
- // DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- // ->where(['Channel' => $Channel, 'DateID' => $dateID])
- // ->update(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserPayCount' => DB::raw("OldUserPayCount+$addPayPeple"), 'OldUserPayBi' => DB::raw('OldUserPayBi+1'), 'OldUserPaySum' => DB::raw("OldUserPaySum+$money")]);
- if($type == 3){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => $Channel, 'DateID' => $dateID])
- ->update(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserPayCount' => DB::raw("OldUserPayCount+$addPayPeple"), 'OldUserPayBi' => DB::raw('OldUserPayBi+1'), 'OldUserPaySum' => DB::raw("OldUserPaySum+$money")]);
- }elseif($type == 4){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => $Channel, 'DateID' => $dateID])
- ->update(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserWithdrawCount' => DB::raw("OldUserWithdrawCount+$addPayPeple"), 'OldUserWithdrawBi' => DB::raw('OldUserWithdrawBi+1'), 'OldUserWithdrawSum' => DB::raw("OldUserWithdrawSum+$money")]);
- }
- } else {
- // DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- // ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserPayCount' => 1, 'OldUserPayBi' => 1, 'OldUserPaySum' => $money]);
- if($type == 3){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserPayCount' => 1, 'OldUserPayBi' => 1, 'OldUserPaySum' => $money]);
- }elseif($type == 4){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserWithdrawCount' => 1,'OldUserWithdrawBi' => 1, 'OldUserWithdrawSum' => $money]);
- }
- }
- // }
- // }
- }
- // 当日注册-当日充值
- public function Today($Channel, $money, $RegisterDate, $Extra,$type = 3)
- {
- Util::WriteLog('RecordPlatformData',[$Channel, $money, $RegisterDate, $Extra,$type]);
- $dateID = Carbon::now()->format('Ymd');
- // if ($dateID == date('Ymd', strtotime($RegisterDate)) && $Extra == 1) {
- if ($dateID == date('Ymd', strtotime($RegisterDate))) {
- $AllFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => -1, 'DateID' => $dateID])
- ->select('DateID')
- ->first();
- // 当日单用户,第一次充值,加充值人数
- $addPayPeple = 0;
- if ($Extra == 1) {
- $addPayPeple = 1;
- }
- if ($AllFormData) {
- if($type == 3){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['NewPayPeple' => DB::raw("NewPayPeple+$addPayPeple"), 'NewPayPepleBi' => DB::raw('NewPayPepleBi+1'), 'NewPayTotal' => DB::raw("NewPayTotal+$money")]);
- }elseif($type == 4){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['NewDrawPeple' => DB::raw("NewDrawPeple+$addPayPeple"),'NewDrawBi' => DB::raw('NewDrawBi+1'),'NewDrawTotal' => DB::raw("NewDrawTotal+$money")]);
- }
- } else {
- if($type == 3){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['NewPayPeple' => 1, 'NewPayTotal' => $money, 'Channel' => -1, 'DateID' => $dateID, 'NewPayPepleBi' => 1]);
- }elseif($type == 4){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['NewDrawPeple' => 1, 'NewDrawTotal' => $money, 'Channel' => -1, 'DateID' => $dateID, 'NewDrawBi' => 1 ]);
- }
- }
- $ChannelFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => $Channel, 'DateID' => $dateID])
- ->select('DateID')
- ->first();
- if ($ChannelFormData) {
- if($type == 3){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => $Channel, 'DateID' => $dateID])
- ->update(['Channel' => $Channel, 'DateID' => $dateID, 'NewPayPeple' => DB::raw("NewPayPeple+$addPayPeple"), 'NewPayPepleBi' => DB::raw('NewPayPepleBi+1'), 'NewPayTotal' => DB::raw("NewPayTotal+$money")]);
- }elseif($type == 4){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => $Channel, 'DateID' => $dateID])
- ->update(['Channel' => $Channel, 'DateID' => $dateID, 'NewDrawPeple' => DB::raw("NewDrawPeple+$addPayPeple") , 'NewDrawBi' => DB::raw('NewDrawBi+1'), 'NewDrawTotal' => DB::raw("NewDrawTotal+$money")]);
- }
- } else {
- if($type == 3){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'NewPayPeple' => 1, 'NewPayTotal' => $money, 'NewPayPepleBi' => 1]);
- }elseif($type == 4){
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'NewDrawPeple' => 1, 'NewDrawTotal' => $money, 'NewDrawBi' => 1]);
- }
- }
- }
- }
- // 添加赠送金额
- public static function addGiveGold($money, $Channel, $dateID = '')
- {
- if (empty($dateID)) {
- $dateID = Carbon::now()->format('Ymd');
- }
- $AllFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => -1, 'DateID' => $dateID])
- ->select('DateID')
- ->first();
- if ($AllFormData) {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['GiveGold' => DB::raw("GiveGold+$money")]);
- } else {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['GiveGold' => $money, 'Channel' => -1, 'DateID' => $dateID]);
- }
- if ($Channel != -1) {
- $ChannelFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => $Channel, 'DateID' => $dateID])
- ->select('DateID')
- ->first();
- if ($ChannelFormData) {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->where(['Channel' => $Channel, 'DateID' => $dateID])
- ->update(['Channel' => $Channel, 'DateID' => $dateID, 'GiveGold' => DB::raw("GiveGold+$money")]);
- } else {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'GiveGold' => $money]);
- }
- }
- }
- public function BindToday($Channel, $RegisterDate)
- {
- $dateID = Carbon::now()->format('Ymd');
- $newCont = 0;
- // if ($dateID == date('Ymd', strtotime($RegisterDate)) && $Extra == 1) {
- if ($dateID == date('Ymd', strtotime($RegisterDate))) {
- $newCont = 1;
- }
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['BindPhoneCount' => DB::raw("BindPhoneCount+1"),'NewPhoneCount' => DB::raw("NewPhoneCount+$newCont")]);
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => $Channel, 'DateID' => $dateID], ['BindPhoneCount' => DB::raw("BindPhoneCount+1"),'NewPhoneCount' => DB::raw("NewPhoneCount+$newCont")]);
- }
- public function PayRequestToday($Channel, $RegisterDate)
- {
- $dateID = Carbon::now()->format('Ymd');
- if ($dateID == date('Ymd', strtotime($RegisterDate))) {
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['NewPayRequest' => DB::raw("NewPayRequest+1")]);
- DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
- ->updateOrInsert(['Channel' => $Channel, 'DateID' => $dateID], ['NewPayRequest' => DB::raw("NewPayRequest+1")]);
- }
- }
- }
|