RecordPlatformData.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?php
  2. namespace App\Models;
  3. use App\Facade\TableName;
  4. use App\Util;
  5. use Carbon\Carbon;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Support\Facades\DB;
  8. class RecordPlatformData extends Model
  9. {
  10. public $connection = 'read';
  11. protected $table = 'QPRecordDB.dbo.RecordPlatformData';
  12. public $timestamps = false;
  13. // 按天获取注册,充值,活跃等
  14. public function dayAccountInfo($startDateID, $endDateID)
  15. {
  16. return self::query()
  17. ->where('Channel', -1)
  18. ->whereBetween('DateID', [$startDateID, $endDateID])
  19. ->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')
  20. ->first();
  21. }
  22. // 按天获取注册用户
  23. public function registerDay($startDateID, $endDateID)
  24. {
  25. return self::query()
  26. ->where('Channel', -1)
  27. ->whereBetween('DateID', [$startDateID, $endDateID])
  28. ->sum('RegPeple');
  29. }
  30. // 按天获取活跃用户
  31. public function ActiveDay($startDateID, $endDateID)
  32. {
  33. return self::query()
  34. ->where('Channel', -1)
  35. ->whereBetween('DateID', [$startDateID, $endDateID])
  36. ->sum('ActivePeple');
  37. }
  38. // 按天获取充值用户
  39. public function WithdrawDay($startDateID, $endDateID)
  40. {
  41. return self::query()
  42. ->where('Channel', -1)
  43. ->whereBetween('DateID', [$startDateID, $endDateID])
  44. ->sum('PayPeple');
  45. }
  46. /**
  47. * 增加提现成功手续费记录
  48. * @param $UserID
  49. * @param $Free
  50. */
  51. public function WithdrawFree($UserID, $Free)
  52. {
  53. $DateID = Carbon::now()->format('Ymd');
  54. $Channel = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')
  55. ->where('UserID', $UserID)
  56. ->value('Channel');
  57. if (DB::table(TableName::QPRecordDB() . 'RecordPlatformData')->where(['DateID' => $DateID, 'Channel' => -1])->value('DateID')) {
  58. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  59. ->where(['DateID' => $DateID, 'Channel' => -1])
  60. ->update(['WithdrawFree' => DB::raw("WithdrawFree+$Free")]);
  61. } else {
  62. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  63. ->insert(['DateID' => $DateID, 'Channel' => -1, 'WithdrawFree' => $Free]);
  64. }
  65. if (DB::table(TableName::QPRecordDB() . 'RecordPlatformData')->where(['DateID' => $DateID, 'Channel' => $Channel])->value('DateID')) {
  66. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  67. ->where(['DateID' => $DateID, 'Channel' => $Channel])
  68. ->update(['WithdrawFree' => DB::raw("WithdrawFree+$Free")]);
  69. } else {
  70. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  71. ->insert(['DateID' => $DateID, 'Channel' => $Channel, 'WithdrawFree' => $Free]);
  72. }
  73. }
  74. // 复购用户人数,充值金额
  75. public function OldUser($UserID, $Channel, $money, $Extra,$type = 3)
  76. {
  77. Util::WriteLog('RecordPlatformDataOld',[$UserID, $Channel, $money, $Extra,$type]);
  78. $dateID = Carbon::now()->format('Ymd');
  79. $queryUserID = DB::table(TableName::QPAccountsDB() . 'AccountsInfo')->where('UserID', $UserID)
  80. ->whereDate('RegisterDate', '<', date('Y-m-d'))
  81. ->value('UserID');
  82. if (empty($queryUserID)) { // 不是老用户直接返回
  83. return true;
  84. }
  85. // 判断以前有没有充值
  86. // if (DB::table(TableName::QPAccountsDB() . 'YN_VIPAccount')->where('UserID', $UserID)->first()) {
  87. // if ($Extra == 1) {
  88. $AllFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  89. ->where(['Channel' => -1, 'DateID' => $dateID])
  90. ->select('DateID')
  91. ->first();
  92. // 当日单用户,第一次充值增加人数
  93. $addPayPeple = 0;
  94. if ($Extra == 1) {
  95. $addPayPeple = 1;
  96. }
  97. if ($AllFormData) {
  98. if($type == 3){
  99. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  100. ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['OldUserPayCount' => DB::raw("OldUserPayCount+$addPayPeple"), 'OldUserPayBi' => DB::raw('OldUserPayBi+1'), 'OldUserPaySum' => DB::raw("OldUserPaySum+$money")]);
  101. }elseif($type == 4){
  102. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  103. ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['OldUserWithdrawCount' => DB::raw("OldUserWithdrawCount+$addPayPeple"), 'OldUserWithdrawBi' => DB::raw('OldUserWithdrawBi+1'),'OldUserWithdrawSum' => DB::raw("OldUserWithdrawSum+$money")]);
  104. }
  105. } else {
  106. if($type == 3){
  107. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  108. ->insert(['OldUserPayCount' => 1, 'OldUserPayBi' => 1, 'OldUserPaySum' => $money, 'Channel' => -1, 'DateID' => $dateID]);
  109. }elseif($type == 4){
  110. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  111. ->insert(['OldUserWithdrawCount' => 1, 'OldUserWithdrawBi' => 1, 'OldUserWithdrawSum' => $money, 'Channel' => -1, 'DateID' => $dateID]);
  112. }
  113. }
  114. $ChannelFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  115. ->where(['Channel' => $Channel, 'DateID' => $dateID])
  116. ->select('DateID')
  117. ->first();
  118. if ($ChannelFormData) {
  119. // DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  120. // ->where(['Channel' => $Channel, 'DateID' => $dateID])
  121. // ->update(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserPayCount' => DB::raw("OldUserPayCount+$addPayPeple"), 'OldUserPayBi' => DB::raw('OldUserPayBi+1'), 'OldUserPaySum' => DB::raw("OldUserPaySum+$money")]);
  122. if($type == 3){
  123. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  124. ->where(['Channel' => $Channel, 'DateID' => $dateID])
  125. ->update(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserPayCount' => DB::raw("OldUserPayCount+$addPayPeple"), 'OldUserPayBi' => DB::raw('OldUserPayBi+1'), 'OldUserPaySum' => DB::raw("OldUserPaySum+$money")]);
  126. }elseif($type == 4){
  127. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  128. ->where(['Channel' => $Channel, 'DateID' => $dateID])
  129. ->update(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserWithdrawCount' => DB::raw("OldUserWithdrawCount+$addPayPeple"), 'OldUserWithdrawBi' => DB::raw('OldUserWithdrawBi+1'), 'OldUserWithdrawSum' => DB::raw("OldUserWithdrawSum+$money")]);
  130. }
  131. } else {
  132. // DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  133. // ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserPayCount' => 1, 'OldUserPayBi' => 1, 'OldUserPaySum' => $money]);
  134. if($type == 3){
  135. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  136. ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserPayCount' => 1, 'OldUserPayBi' => 1, 'OldUserPaySum' => $money]);
  137. }elseif($type == 4){
  138. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  139. ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'OldUserWithdrawCount' => 1,'OldUserWithdrawBi' => 1, 'OldUserWithdrawSum' => $money]);
  140. }
  141. }
  142. // }
  143. // }
  144. }
  145. // 当日注册-当日充值
  146. public function Today($Channel, $money, $RegisterDate, $Extra,$type = 3)
  147. {
  148. Util::WriteLog('RecordPlatformData',[$Channel, $money, $RegisterDate, $Extra,$type]);
  149. $dateID = Carbon::now()->format('Ymd');
  150. // if ($dateID == date('Ymd', strtotime($RegisterDate)) && $Extra == 1) {
  151. if ($dateID == date('Ymd', strtotime($RegisterDate))) {
  152. $AllFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  153. ->where(['Channel' => -1, 'DateID' => $dateID])
  154. ->select('DateID')
  155. ->first();
  156. // 当日单用户,第一次充值,加充值人数
  157. $addPayPeple = 0;
  158. if ($Extra == 1) {
  159. $addPayPeple = 1;
  160. }
  161. if ($AllFormData) {
  162. if($type == 3){
  163. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  164. ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['NewPayPeple' => DB::raw("NewPayPeple+$addPayPeple"), 'NewPayPepleBi' => DB::raw('NewPayPepleBi+1'), 'NewPayTotal' => DB::raw("NewPayTotal+$money")]);
  165. }elseif($type == 4){
  166. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  167. ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['NewDrawPeple' => DB::raw("NewDrawPeple+$addPayPeple"),'NewDrawBi' => DB::raw('NewDrawBi+1'),'NewDrawTotal' => DB::raw("NewDrawTotal+$money")]);
  168. }
  169. } else {
  170. if($type == 3){
  171. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  172. ->insert(['NewPayPeple' => 1, 'NewPayTotal' => $money, 'Channel' => -1, 'DateID' => $dateID, 'NewPayPepleBi' => 1]);
  173. }elseif($type == 4){
  174. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  175. ->insert(['NewDrawPeple' => 1, 'NewDrawTotal' => $money, 'Channel' => -1, 'DateID' => $dateID, 'NewDrawBi' => 1 ]);
  176. }
  177. }
  178. $ChannelFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  179. ->where(['Channel' => $Channel, 'DateID' => $dateID])
  180. ->select('DateID')
  181. ->first();
  182. if ($ChannelFormData) {
  183. if($type == 3){
  184. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  185. ->where(['Channel' => $Channel, 'DateID' => $dateID])
  186. ->update(['Channel' => $Channel, 'DateID' => $dateID, 'NewPayPeple' => DB::raw("NewPayPeple+$addPayPeple"), 'NewPayPepleBi' => DB::raw('NewPayPepleBi+1'), 'NewPayTotal' => DB::raw("NewPayTotal+$money")]);
  187. }elseif($type == 4){
  188. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  189. ->where(['Channel' => $Channel, 'DateID' => $dateID])
  190. ->update(['Channel' => $Channel, 'DateID' => $dateID, 'NewDrawPeple' => DB::raw("NewDrawPeple+$addPayPeple") , 'NewDrawBi' => DB::raw('NewDrawBi+1'), 'NewDrawTotal' => DB::raw("NewDrawTotal+$money")]);
  191. }
  192. } else {
  193. if($type == 3){
  194. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  195. ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'NewPayPeple' => 1, 'NewPayTotal' => $money, 'NewPayPepleBi' => 1]);
  196. }elseif($type == 4){
  197. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  198. ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'NewDrawPeple' => 1, 'NewDrawTotal' => $money, 'NewDrawBi' => 1]);
  199. }
  200. }
  201. }
  202. }
  203. // 添加赠送金额
  204. public static function addGiveGold($money, $Channel, $dateID = '')
  205. {
  206. if (empty($dateID)) {
  207. $dateID = Carbon::now()->format('Ymd');
  208. }
  209. $AllFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  210. ->where(['Channel' => -1, 'DateID' => $dateID])
  211. ->select('DateID')
  212. ->first();
  213. if ($AllFormData) {
  214. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  215. ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['GiveGold' => DB::raw("GiveGold+$money")]);
  216. } else {
  217. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  218. ->insert(['GiveGold' => $money, 'Channel' => -1, 'DateID' => $dateID]);
  219. }
  220. if ($Channel != -1) {
  221. $ChannelFormData = DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  222. ->where(['Channel' => $Channel, 'DateID' => $dateID])
  223. ->select('DateID')
  224. ->first();
  225. if ($ChannelFormData) {
  226. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  227. ->where(['Channel' => $Channel, 'DateID' => $dateID])
  228. ->update(['Channel' => $Channel, 'DateID' => $dateID, 'GiveGold' => DB::raw("GiveGold+$money")]);
  229. } else {
  230. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  231. ->insert(['Channel' => $Channel, 'DateID' => $dateID, 'GiveGold' => $money]);
  232. }
  233. }
  234. }
  235. public function BindToday($Channel, $RegisterDate)
  236. {
  237. $dateID = Carbon::now()->format('Ymd');
  238. $newCont = 0;
  239. // if ($dateID == date('Ymd', strtotime($RegisterDate)) && $Extra == 1) {
  240. if ($dateID == date('Ymd', strtotime($RegisterDate))) {
  241. $newCont = 1;
  242. }
  243. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  244. ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['BindPhoneCount' => DB::raw("BindPhoneCount+1"),'NewPhoneCount' => DB::raw("NewPhoneCount+$newCont")]);
  245. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  246. ->updateOrInsert(['Channel' => $Channel, 'DateID' => $dateID], ['BindPhoneCount' => DB::raw("BindPhoneCount+1"),'NewPhoneCount' => DB::raw("NewPhoneCount+$newCont")]);
  247. }
  248. public function PayRequestToday($Channel, $RegisterDate)
  249. {
  250. $dateID = Carbon::now()->format('Ymd');
  251. if ($dateID == date('Ymd', strtotime($RegisterDate))) {
  252. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  253. ->updateOrInsert(['Channel' => -1, 'DateID' => $dateID], ['NewPayRequest' => DB::raw("NewPayRequest+1")]);
  254. DB::table(TableName::QPRecordDB() . 'RecordPlatformData')
  255. ->updateOrInsert(['Channel' => $Channel, 'DateID' => $dateID], ['NewPayRequest' => DB::raw("NewPayRequest+1")]);
  256. }
  257. }
  258. }