Account.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\Log;
  4. use DB;
  5. /**
  6. *
  7. */
  8. class Account extends BaseModel
  9. {
  10. protected $table = 'account';
  11. public $timestamps = false;
  12. function account($list, $page, $where = '', $field = 'account.id', $ads = 'desc', $rflag, $tflag)
  13. {
  14. // DB::connection()->enableQueryLog();
  15. $rechargestatus = ' WHERE a.status=1 AND a.trade_type IN (6,12,11,14) ';
  16. $takestatus = ' WHERE b.status=1 AND b.trade_type=5';
  17. $rnum = ($rflag == -1) ? '' : ',mc.recharge_num';
  18. $tnum = ($tflag == -1) ? '' : ',tc.take_num';
  19. $rjoin = ($rflag == -1) ? '' : ' LEFT JOIN (SELECT account_identity,count("id") AS recharge_num FROM money_details a ' . $rechargestatus . ' GROUP BY a.account_identity) AS mc ON mc.account_identity=account.identity ';
  20. $tjoin = ($tflag == -1) ? '' : ' LEFT JOIN (SELECT account_identity,count(id) AS take_num FROM money_details d ' . $takestatus . ' GROUP BY d.account_identity) AS tc ON tc.account_identity=account.identity ';
  21. $agent_join = " LEFT JOIN nagent_detailed c ON b.parent_id=c.agent_identity";
  22. $sql = "SELECT account.id, account.identity,account, b.grade,c.agent_identity,c.agent_user as agent_name, b.cash, b.name, b.register_time, b.qq,b.wechat,b.register_ip, b.last_ip, b.phone, b.email, b.statuss,open_invitation,b.register_url,b.last_url,c.invite,to_char(last_time,'yyyy-mm-dd hh24:mi:ss') as last_time,account.status,b.statuss,b.parent_id" . $rnum . $tnum . " FROM account LEFT JOIN account_detailed b ON account.identity=b.account_identity" . $rjoin . $tjoin . $agent_join . " WHERE account.status<>4 " . $where . " ORDER BY " . $field . ' ' . $ads;
  23. if (!empty($list)) {
  24. $offset = $list * ($page - 1);
  25. $sql .= ' LIMIT ' . $list . ' OFFSET ' . $offset;
  26. }
  27. $countsql = "SELECT count(account.identity) FROM account INNER JOIN account_detailed b ON account.identity=b.account_identity " . $rjoin . $tjoin . $agent_join . " WHERE status<>4 " . $where;
  28. Log::info ($sql);
  29. $data = DB::select ($sql);
  30. $total = DB::select ($countsql);
  31. // $queries = DB::getQueryLog();
  32. // print_r($queries);
  33. if (!$data < 0) {
  34. return -2020052003; //没有用户会员
  35. }
  36. $data = json_encode ($data);
  37. $data = json_decode ($data, 1);
  38. $res = array('data' => $data, 'total' => $total[0]->count);
  39. return $res;
  40. }
  41. /*
  42. $offset = $list*($page-1);
  43. $rechargestatus = ' WHERE a.status=1 AND a.trade_type IN (6,12,11,14) ';
  44. $takestatus = ' WHERE b.status=1 AND b.trade_type=5';
  45. $sql = "SELECT account.id, account.identity, account, grade, cash, name, register_time, register_ip, last_ip, phone, email, statuss,to_char(last_time,'yyyy-mm-dd hh24:mi:ss') as last_time,status,mc.recharge_num,tc.take_num,ta.token_time,ta.effective_time FROM account".' INNER JOIN account_detailed ON account.identity=account_detailed.account_identity LEFT JOIN (SELECT account_identity,count("id") AS recharge_num FROM money_details a '.$rechargestatus.' GROUP BY a.account_identity) AS mc ON mc.account_identity=account.identity LEFT JOIN (SELECT account_identity,count(id) AS take_num FROM money_details b '.$takestatus.' GROUP BY b.account_identity) AS tc ON tc.account_identity=account.identity LEFT JOIN (SELECT last_time AS token_time,effective_time,account_identity FROM account_token) AS ta ON ta.account_identity=account.identity WHERE status<>4 '.$where.' ORDER BY '.$field.' ' .$ads.' LIMIT '.$list.' OFFSET '.$offset;
  46. $countsql = 'SELECT count(account.identity) FROM account INNER JOIN account_detailed ON account.identity=account_detailed.account_identity LEFT JOIN (SELECT account_identity,count("id") AS recharge_num FROM money_details a '.$rechargestatus.' GROUP BY a.account_identity) AS mc ON mc.account_identity=account.identity LEFT JOIN (SELECT account_identity,count(id) AS take_num FROM money_details b '.$takestatus.' GROUP BY b.account_identity) AS tc ON tc.account_identity=account.identity LEFT JOIN (SELECT last_time AS token_time,effective_time,account_identity FROM account_token) AS ta ON ta.account_identity=account.identity WHERE status<>4 '.$where;
  47. $data = DB::select($sql);
  48. $total = DB::select($countsql);
  49. if (!$data < 0) {
  50. return -2020052003; //没有用户会员
  51. }
  52. $data = json_encode($data);
  53. $data = json_decode($data,1);
  54. $res = array('data'=>$data,'total'=>$total[0]->count);
  55. return $res;
  56. */
  57. /*function account($list, $page, $where = '',$field='account.id',$ads='desc',$rechargenum='',$takenum='') {
  58. //$data = $this->join('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')
  59. // ->select('account.id', 'account.identity', 'account', 'grade', 'cash', 'name', 'register_time', 'register_ip', 'last_ip', 'phone', 'email', 'statuss','last_time','status');
  60. $wherestr = '';
  61. if(!empty($where)&&is_array($where)){
  62. foreach($where as $v){
  63. $wherestr .= ' and ' . implode(' ',$v);
  64. }
  65. }
  66. $offset = $list*($page-1);
  67. $rechargestatus = ' where a.status=1 and a.trade_type in (6,12,11,14) ';
  68. $takestatus = ' where b.status=1 and b.trade_type=5';
  69. //$rechargestatus = empty($rechargenum)?'':' where a.status=1 and trade_type in (6,12,11,14) ';
  70. //$takestatus = empty($takenum)?'':' where b.status=1 and trade_type=5';
  71. $sql = 'select account.id, account.identity, account, grade, cash, name, register_time, register_ip, last_ip, phone, email, statuss,last_time,status,mc.recharge_num,tc.take_num from account inner join account_detailed on account.identity=account_detailed.account_identity left join (select account_identity,count("id") as recharge_num from money_recharge a '.$rechargestatus.' GROUP BY a.account_identity) as mc on mc.account_identity=account.identity left join (select account_identity,count(id) as take_num from money_take b '.$takestatus.' GROUP BY b.account_identity) as tc on tc.account_identity=account.identity where status<>4 '.$wherestr.$rechargenum.$takenum.' order by '.$field.' ' .$ads.' limit '.$list.' offset '.$offset;
  72. //print_r($sql);
  73. $countsql = 'select count(account.identity) from account inner join account_detailed on account.identity=account_detailed.account_identity left join (select account_identity,count("id") as recharge_num from money_recharge a '.$rechargestatus.' GROUP BY a.account_identity) as mc on mc.account_identity=account.identity left join (select account_identity,count(id) as take_num from money_take b '.$takestatus.' GROUP BY b.account_identity) as tc on tc.account_identity=account.identity where status<>4 '.$wherestr.$rechargenum.$takenum;
  74. $data = DB::select($sql);
  75. $total = DB::select($countsql);
  76. //if (is_array($where)) {
  77. // $where[] = array('status','<>',4);
  78. // $data = $data->where($where);
  79. //}else{
  80. // $data = $data->where('status', 1);
  81. //}
  82. //$data = $data->orderBy($field, $ads)->paginate($list);
  83. //$data = $data->paginate($list);
  84. //$account = $data->limit($list)->offset($page)->count();
  85. //$data = $data->limit($list)->offset($page)->get();
  86. //$queries = DB::getQueryLog();
  87. //print_r($queries);
  88. if (!$data < 0) {
  89. return -2020052003; //没有用户会员
  90. }
  91. $data = json_encode($data);
  92. $data = json_decode($data,1);
  93. $res = array('data'=>$data,'total'=>$total[0]->count);
  94. //print_r($res);
  95. return $res;
  96. }*/
  97. //查找代理id
  98. /**
  99. * 试玩账号
  100. * [FunctionName description]
  101. * @param string $value [description]
  102. */
  103. function demo_account($list = 10, $page, $where = '')
  104. {
  105. if (is_array ($where) && count ($where) > 0) {
  106. $where[] = array('status', '=', 4);
  107. $data = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')
  108. ->select ('account.id', 'account.identity', 'account', 'grade', 'cash', 'name', 'register_time', 'register_ip', 'last_ip', 'phone', 'email', 'statuss')
  109. ->where ($where)
  110. ->paginate ($list);
  111. } else {
  112. $data = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')
  113. ->select ('account.id', 'account', 'register_time', 'cash', 'last_ip', 'register_ip', 'statuss')
  114. ->where ('status', 4)
  115. ->paginate ($list);
  116. }
  117. if (!$data < 0) {
  118. return -2021052003; //没有用户会员
  119. }
  120. return $data->toArray ();
  121. }
  122. //获取用户详情
  123. function getUserDetails($value, $type = 1, $jointable = '', $columnn = '', $columnw = '', $page = 1, $limit = 10, $sort = 'id', $ads = 'asc')
  124. {
  125. $key = $this->getFeild ($type);
  126. $sort = 'account.' . $sort;
  127. if (empty($jointable)) {
  128. if (is_array ($value)) {
  129. $data = $this->where ($value);
  130. } else {
  131. $data = $this->where ($this->table . '.' . $key, $value);
  132. }
  133. } elseif ($jointable == 'account_detailed') {
  134. if (is_array ($value)) {
  135. $data = $this->select ('account.id', 'account as account_name', 'account.identity', 'cash')->where ($value)->join ($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw);
  136. } else {
  137. $data = $this->select ('account.id', 'account as account_name', 'account.identity', 'cash')->where ($this->table . '.' . $key, $value)->join ($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw);
  138. }
  139. } else {
  140. $data = $this->where ($this->table . '.' . $key, $value)->join ($jointable, $this->table . '.' . $columnn, $jointable . '.' . $columnw);
  141. }
  142. $data = $data->orderby ($sort, $ads)->paginate ($limit);
  143. if (!$data) {
  144. return -30203000202; //没有用户详情
  145. }
  146. return $data->toArray ();
  147. }
  148. //会员汇总统计
  149. function userCount($where = '')
  150. {
  151. $data = array();
  152. $data['allcash'] = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')->where ('status', '<>', 4)->sum ('cash');
  153. $data['normalcash'] = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')->where ('status', 1)->sum ('cash');
  154. $data['stopcash'] = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')->where ('status', -1)->sum ('cash');
  155. $data['speccash'] = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')->where ('status', -2)->sum ('cash');
  156. if (!empty($where) && is_array ($where)) {
  157. $data['allcash'] = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')->where ($where)->where ('status', '<>', 4)->sum ('cash');
  158. $data['normalcash'] = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')->where ($where)->where ('status', 1)->sum ('cash');
  159. $data['stopcash'] = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')->where ($where)->where ('status', -1)->sum ('cash');
  160. $data['speccash'] = $this->join ('account_detailed', 'account.identity', '=', 'account_detailed.account_identity')->where ($where)->where ('status', -2)->sum ('cash');
  161. }
  162. return $data;
  163. }
  164. //字段对应值
  165. private function getFeild($num)
  166. {
  167. $data = array(
  168. '1' => 'id',
  169. '2' => 'identity',
  170. '3' => 'account',
  171. '4' => 'status',
  172. );
  173. return $data[$num];
  174. }
  175. function getinfo($value, $type = 1)
  176. {
  177. $key = $this->getFeild ($type);
  178. $data = $this->where ($key, $value)->first ();
  179. if (!$data) {
  180. return -30203000202; //没有用户详情
  181. }
  182. return $data->toArray ();
  183. }
  184. protected function getinfoCopy($value, $type = 1)
  185. {
  186. return $this->getinfo ($value, $type);
  187. }
  188. //更新
  189. function updateInfo($data, $id)
  190. {
  191. $res = $this->where ('id', $id)->update ($data);
  192. if (!$res) {
  193. return -7010101202; //更新失败
  194. }
  195. return 1;
  196. }
  197. //更新
  198. function upUserInfo($data, $id)
  199. {
  200. $res = $this->where ('identity', $id)->update ($data);
  201. if (!$res) {
  202. return -7010101202; //更新失败
  203. }
  204. return 1;
  205. }
  206. //获取用户数组
  207. function getUserData($data)
  208. {
  209. $datas = $this->select ('account', 'identity')->whereIn ('account', $data)->get ();
  210. if (!$datas) {
  211. return -502030154202; //没有
  212. }
  213. return $data->toArray ();
  214. }
  215. function Accounta($where)
  216. {
  217. if (empty($where)) {
  218. return '-502030154202';
  219. }
  220. $data = $this->where ('account', $where['account'])->where ('status', $where['status'])->first ();
  221. if (!$data) {
  222. return -502030154202;
  223. }
  224. return $data->toArray ();
  225. }
  226. function Accountas()
  227. {
  228. $data = $this->select ('account', 'id')->orderBy ('id', 'desc')->get ();
  229. if (!$data) {
  230. return -502030154202;
  231. }
  232. return $data->toArray ();
  233. }
  234. function Accountad($id)
  235. {
  236. $data = $this->select ('account', 'id')->where ('id', "<", $id)->orderBy ('id', 'desc')->limit (50)->get ();
  237. if (!$data) {
  238. return -502030154202;
  239. }
  240. return $data->toArray ();
  241. }
  242. //获取会员等级
  243. function getUserGrade()
  244. {
  245. $data = db::table ('dc_user_grade')->select ('name', 'id', 'grade')->orderBy ('grade', 'desc')->get ();
  246. if (!$data) {
  247. return -502030154202;
  248. }
  249. $data = $data->toArray ();
  250. $arr = array();
  251. foreach ($data as $key => $value) {
  252. $arr[$value->grade] = $value->name;
  253. }
  254. return $arr;
  255. }
  256. /**
  257. * 首充检查
  258. * @param string $account_identity
  259. * @param string $type
  260. * @return mixed
  261. */
  262. public static function isFirstRecharge(string $account_identity, string $type = '')
  263. {
  264. $m = new Money_recharge();
  265. $where = [
  266. 'account_identity' => $account_identity
  267. ];
  268. switch ($type) {
  269. case 'month':
  270. $where[] = ['complete_time', '>=', (date ('Y-m-1'))];
  271. break;
  272. case 'week':
  273. $time = date ('Y-m-d');
  274. $t = strtotime ($time . ' Sunday');
  275. $where[] = ['complete_time', '>=', date ('Y-m-d H:i:s', $t - 86400 * 6)];
  276. default:
  277. }
  278. return $num = $m->where ($where)->count ('money');
  279. }
  280. public static function checkWithdraw($account_identity)
  281. {
  282. //$withdrawRule=new Withdraw_rule();
  283. return Withdraw_rule::check ($account_identity);
  284. }
  285. //根据用户名获取用户信息 2019-019-23 anton
  286. public function checkUserByName($username){
  287. $uinfo = $this->leftjoin('account_detailed', 'account_detailed.account_identity', '=', 'account.identity')
  288. ->select('account_detailed.cash')
  289. ->where('account.account', '=', $username)
  290. ->first();
  291. if(!$uinfo){
  292. return -502030154202;
  293. }
  294. return $uinfo->toArray();
  295. }
  296. //获取用户名信息 2019-019-26 anton
  297. public function getUserInfo($rp_name){
  298. $uinfo = $this->leftjoin('oggame_user', 'oggame_user.lo_name', '=', 'account.account')
  299. ->select('account.identity','account.account')
  300. ->where('oggame_user.rp_name', '=', $rp_name)
  301. ->first();
  302. if(!$uinfo){
  303. return -502030154202;
  304. }
  305. return $uinfo->toArray();
  306. }
  307. }