| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- /**
- * Created by PhpStorm.
- * User: ikeke
- * Date: 2018/12/6
- * Time: 19:38
- */
- namespace App\Models;
- use DB;
- class Hjgame_betting_ogrbv extends BaseModel
- {
- protected $table = "hjgame_betting_ogrbv";
- public $timestamps = false;
-
- /**
- * 获取游戏投注记录
- * @param string $where
- * @param int $limit
- * @return mixed
- */
- public function getlist($where = '', $limit = 15, $orby = 'id', $sc = "desc"){
- $data = $this->orderBy($orby, $sc);
- if (is_array($where) && count($where)>0) {
- $data = $data->where($where);
- }
- $data = $data->paginate($limit);
-
- return $data? $data->toArray():[];
- }
-
- protected function getLastTime(){
- $data = $this->orderBy('id','desc')->first(['bet_time']);
- return $data?date('Y-m-d H:i:s',$data->toArray()['bet_time']):'';
- }
-
- /**
- * 获取指定数据
- * @param string $where
- * @return mixed
- */
- protected function getOneData($where = ''){
- return $data = $this->where('record_id', $where)->first();
- }
-
- public function getSum($where){
- $arr = [];
- $ba = 0;
- $wa = 0;
- $va = 0;
- $co = 0;
- if (is_array($where) && count($where)>0) {
- //查询总投注金额
- $ba = $this->where($where)->sum('bet_amount');
- //查询总派彩金额
- $wa = $this->where($where)->where('profit','>','0')->sum('profit');
- //查询总有效投注金额
- $va = $this->where($where)->where('state','1')->sum('bet_amount');
-
- //查询总条数
- $co = $this->where($where)->count();
- }
-
- $arr['bettingamount'] = ceil($ba) == $ba ? $ba : round($ba, 2);
- $arr['winLoseamount'] = ceil($wa) == $wa ? $wa : round($wa, 2);
- $arr['validamount'] = ceil($va) == $va ? $va : round($va, 2);
- $arr['revenue'] = 0;
- $arr['co'] = $co;
-
- return $arr;
-
- }
-
- //获取回水列表
- protected function getMoneyback($value = '', $type = 1, $limit = 10, $wheregame = '', $orwhere = '', $having = '')
- {
- DB::connection()->enableQueryLog();
-
- $data = $this->select('account_name','account_identity',"username as Accounts",DB::raw('sum("bet_amount") as betting_money'),DB::raw('sum("profit") as WinLoseAmount'),DB::raw('sum("bet_amount") as ValidAmount'),DB::raw('count("id") as bet_count'))->where('state',1)->groupBy('username','account_name','account_identity');
- if (!empty($having)) {
- foreach ($having as $v) {
- $data = $data->havingRaw($v);
- }
- }
- if (empty($value) || is_array($value)) {
- $where = $value;
- } else {
- $where[] = array( 'id', $value);
- }
- $where[] = array('type', 1);
- $data = $data->where($where);
- $data = $data->paginate($limit);
-
- if (!$data) {
- return -5030001202; //没有列表数据
- }
-
- return $data->toArray();
- }
-
-
- //反水更改狀
- public function updateBackWater($name, $timearea)
- {
-
- $res = $this->where('account_name', $name)->where($timearea);
-
- $res = $res->update(['type' => '2']);
-
- if (!$res) {
- return -3012564406; //反水失败
- }
- return 1;
- }
- //添加游戏注单信息
- protected function AddGameBet($betinfo){
- $users = $indata = [];
- $i=$j=0;
- foreach ($betinfo as $k => $v) {
- if(!empty($v['bet_time'])){
- $v['bet_time'] = strtotime($v['bet_time']);
- }
- if(!empty($v['draw_time'])){
- $v['draw_time'] = strtotime($v['draw_time']);
- }
- if (!array_key_exists($v['username'], $users)) {
- //获取本站用户名
- $loainfo = \App\Models\Oggame_user::select('lo_name')->where('rp_name', $v['username'])->first();
- //获取本站用户ID
- if (!empty($loainfo->lo_name)){
- $aid = \App\Models\Account::select('identity')->where('account', $loainfo->lo_name)->first();
- if (!empty($aid->identity)){
- $users[$v['username']] = ['identity' => $aid->identity, 'name' => $loainfo->lo_name];
- $indata = [
- 'oder_id' =>md5(json_encode($v)),
- 'account_identity' =>$users[$v['username']]['identity'],
- 'account_name' => $users[$v['username']]['name'],
- ];
-
- $indata = (array_merge($indata,$v));
-
- try{
- $res = $this->insert($indata);
- if($res)++$i;
- }catch (\Exception $e){
- if(strpos($e->getMessage(),'Unique violation')!==false){continue;}else{
- dd($e);
- }
- }
- }
- }
-
- }
- }
- return $i;
- }
-
-
- }
|