model = new \app\admin\model\app\Order; $this->view->assign("symbolList", $this->model->getSymbolList()); $this->view->assign("riseOrFallList", $this->model->getRiseOrFallList()); $this->view->assign("setLossList", $this->model->getSetLossList()); } public function import() { parent::import(); } /** * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 */ /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } // list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $offset = $this->request->get("offset", 0); $limit = $this->request->get("limit", 0); $params = json_decode(input('filter'),true); $op = json_decode(input('op'),true); if(count($params) > 0){ $new_params = $new_op = []; foreach ($params as $key => $value) { if($key == 'mobile') { $new_params['u.' . $key] = $value; $new_op['u.' . $key] = $op[$key]; }else if($key == 'user_name'){ $new_params['u.username'] = $value; $new_op['u.username'] = $op[$key]; }elseif ($key == 'daili_name') { $new_params['e.nickname'] = $value; $new_op['e.nickname'] = $op[$key]; }else { $new_params['a.' . $key] = $value; $new_op['a.' . $key] = $op[$key]; } } $w = $this->rewriteQuery($new_params, $new_op); }else{ $w['a.id'] = array('>', 0); } $admin_id = $this->auth->id; if($admin_id > 1){ $user = Db::name("user")->where("admin_id",$admin_id)->find(); if($user){ $w['u.path'] = array("like",$user['path']."%"); } } $total = Db::name('order') ->alias('a') ->field('a.*,u.username as user_name,e.nickname as daili_name') ->join('fa_user u', 'a.user_id = u.id') ->join('admin e', 'u.p_admin_id = e.id' , 'left') ->where($w) ->count(); $list = Db::name('order') ->alias('a') ->field('a.*,u.username as user_name,e.nickname as daili_name') ->join('fa_user u', 'a.user_id = u.id') ->join('admin e', 'u.p_admin_id = e.id' , 'left') ->where($w) ->order('a.id', 'desc') ->limit($offset, $limit) ->select(); $extend['risenum'] = Db::name('order') ->alias('a') ->field('a.*') ->where('rise_or_fall','rise') ->sum('trade_num'); $extend['fallnum'] = Db::name('order') ->alias('a') ->field('a.*') ->where('rise_or_fall','fall') ->sum('trade_num'); $extend['risewin'] = Db::name('order') ->alias('a') ->field('a.*') ->where('rise_or_fall','rise') ->sum('expect_income'); $extend['fallwin'] = Db::name('order') ->alias('a') ->field('a.*') ->where('rise_or_fall','fall') ->sum('expect_income'); $coindata = Db::name('app_rate') ->whereIn('symbol','btcusdt,ethusdt,eosusdt,bchusdt,ltcusdt')->select(); $extend['coin'] = array_column($coindata,'open','name'); $extend['nowtime'] = time(); $result = array("total" => $total, "rows" => $list,'extend' => $extend); return json($result); } return $this->view->fetch(); } //生成价格 public function createPrice() { $params = $this->request->post(); if(empty($params['symbols'])) { $this->error('请选择币种'); } if(empty($params['zhouqi'])) { $this->error('请选择周期'); } if(empty($params['rise_or_falls'])) { $this->error('请选择涨跌类型'); } if(empty($params['prices']) || !is_numeric($params['prices'])) { $this->error('请输入波动价格'); } if(empty($params['createstime'])) { $this->error('请选择下单时间'); } $tstime = strtotime($params['createstime']); $symbols = str_replace('usdt','',$params['symbols']); $newprice1 = Db::name('hb_1s_'.$symbols) ->where('ts',"<=",$tstime-2) ->order('ts','desc')->find(); $newprice2 = Db::name('hb_1s_'.$symbols) ->where('ts',"<=",$tstime-1) ->order('ts','desc')->find(); $newprice3 = Db::name('hb_1s_'.$symbols) ->where('ts',"<=",$tstime) ->order('ts','desc')->find(); $newprice4 = Db::name('hb_1s_'.$symbols) ->where('ts',"<=",$tstime+1) ->order('ts','desc')->find(); $newprice5 = Db::name('hb_1s_'.$symbols) ->where('ts',"<=",$tstime+2) ->order('ts','desc')->find(); if(!$newprice5) { $this->error('该时间段无效未获取到价格'); } $randprice1 = $this->randomFloat(0,$params['prices'],2); $randprice2 = $this->randomFloat(0,$params['prices'],2); $randprice3 = $this->randomFloat(0,$params['prices'],2); $randprice4 = $this->randomFloat(0,$params['prices'],2); $randprice5 = $this->randomFloat(0,$params['prices'],2); if($params['rise_or_falls'] == 'rise') { $data = [ 'newprice1' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']-2), 'price' => sprintf('%.2f',($randprice1+$newprice1['price'])) ], 'newprice2' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']-1), 'price' => sprintf('%.2f',($randprice2+$newprice2['price'])) ], 'newprice3' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']), 'price' => sprintf('%.2f',($randprice3+$newprice3['price'])) ], 'newprice4' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']+1), 'price' => sprintf('%.2f',($randprice4+$newprice4['price'])) ], 'newprice5' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']+2), 'price' => $newprice5['price'] ], ]; }else{ $data = [ 'newprice1' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']-2), 'price' => sprintf('%.2f',($newprice1['price']-$randprice1)) ], 'newprice2' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']-1), 'price' => sprintf('%.2f',($newprice2['price']-$randprice2)) ], 'newprice3' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']), 'price' => sprintf('%.2f',($newprice3['price']-$randprice3)) ], 'newprice4' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']+1), 'price' => sprintf('%.2f',($newprice4['price']-$randprice4)) ], 'newprice5' => [ 'times' => date('Y-m-d H:i:s', $tstime+$params['zhouqi']+2), 'price' => $newprice5['price'] ], ]; } $data['openprice'] = $newprice3['price']; $this->success('success','',$data); } //创建价格 public function buildPrice() { $params = $this->request->post(); if (empty($params['symbols'])) { $this->error('请选择币种'); } if (empty($params['zhouqi'])) { $this->error('请选择周期'); } if (empty($params['rise_or_falls'])) { $this->error('请选择涨跌类型'); } if (empty($params['prices']) || !is_numeric($params['prices'])) { $this->error('请输入波动价格'); } if (empty($params['createstime'])) { $this->error('请选择下单时间'); } $insertdata = [ [ 'symbol' => $params['symbols'], 'ts' => strtotime($params['newpricetime1']), 'price' => $params['newprice1'], 'amount' => 0, 'createtime' => time() ], [ 'symbol' => $params['symbols'], 'ts' => strtotime($params['newpricetime2']), 'price' => $params['newprice2'], 'amount' => 0, 'createtime' => time() ], [ 'symbol' => $params['symbols'], 'ts' => strtotime($params['newpricetime3']), 'price' => $params['newprice3'], 'amount' => 0, 'createtime' => time() ], [ 'symbol' => $params['symbols'], 'ts' => strtotime($params['newpricetime4']), 'price' => $params['newprice4'], 'amount' => 0, 'createtime' => time() ], [ 'symbol' => $params['symbols'], 'ts' => strtotime($params['newpricetime5']), 'price' => $params['newprice5'], 'amount' => 0, 'createtime' => time() ], ]; $ret = Db::name('hb_ctrl')->insertAll($insertdata); if($ret){ $result = http_curl('http://149api.ms2722.com/crest/hbmarket/syncCtrl?token=datrade'); $this->success('添加成功',$result); }else{ $this->error('系统繁忙'); } } //清除价格 public function cleanPrice() { $ret = Db::name('hb_ctrl') ->where('id','>',0) ->delete(); if($ret){ $result = http_curl('http://149api.ms2722.com/crest/hbmarket/cancelSyncCtrl?token=datrade'); $this->success('已取消所有调控价格'); }else{ $this->error('系统繁忙'); } } //4位小数的随机数 public function randomFloat($min = 0, $max = 10 , $localnum = 4) { if($localnum == 4) { if ($max - $min <= 0.0002) { return 0; } $rand = mt_rand() / mt_getrandmax() * ($max - $min-0.0001); $num = $min + $rand; $number = sprintf("%.4f", $num); if($number == $min){ $number += 0.0001; } }else if($localnum == 5){ if ($max - $min <= 0.00002) { return 0; } $rand = mt_rand() / mt_getrandmax() * ($max - $min-0.00001); $num = $min + $rand; $number = sprintf("%.5f", $num); if($number == $min){ $number += 0.00001; } }else if($localnum == 6){ if ($max - $min <= 0.000002) { return 0; } $rand = mt_rand() / mt_getrandmax() * ($max - $min-0.000001); $num = $min + $rand; $number = sprintf("%.6f", $num); if($number == $min){ $number += 0.000001; } }else if($localnum == 2){ if ($max - $min <= 0.02) { return 0; } $rand = mt_rand() / mt_getrandmax() * ($max - $min-0.01); $num = $min + $rand; $number = sprintf("%.2f", $num); if($number == $min){ $number += 0.01; } }else if($localnum == 3){ if ($max - $min <= 0.001) { return 0; } $rand = mt_rand() / mt_getrandmax() * ($max - $min-0.001); $num = $min + $rand; $number = sprintf("%.3f", $num); if($number == $min){ $number += 0.001; } } return $number; } /** * 监听订单管理 */ public function jianting() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } // list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $offset = $this->request->get("offset", 0); $limit = $this->request->get("limit", 0); $params = json_decode(input('filter'),true); $op = json_decode(input('op'),true); if(count($params) > 0){ $new_params = $new_op = []; foreach ($params as $key => $value) { if($key == 'mobile') { $new_params['u.' . $key] = $value; $new_op['u.' . $key] = $op[$key]; }else if($key == 'user_name'){ $new_params['u.mobile'] = $value; $new_op['u.mobile'] = $op[$key]; }else { $new_params['a.' . $key] = $value; $new_op['a.' . $key] = $op[$key]; } } $w = $this->rewriteQuery($new_params, $new_op); }else{ $w['a.id'] = array('>', 0); } $total = Db::name('order') ->alias('a') ->field('a.*,u.mobile as user_name') ->join('fa_user u', 'a.user_id = u.id') ->where($w) ->count(); $list = Db::name('order') ->alias('a') ->field('a.*,u.mobile as user_name') ->join('fa_user u', 'a.user_id = u.id') ->where($w) ->order('a.id', 'desc') ->group('createtime') ->limit($offset, $limit) ->select(); foreach ($list as $key=>$value) { $order = Db::name('order') ->where('createtime',$value['createtime'])->select(); //下单人数 $value['ordercount'] = Db::name('order') ->where('createtime',$value['createtime'])->count(); //总金额 $value['ordersum'] = Db::name('order') ->where('createtime',$value['createtime'])->sum('trade_num'); $risenum = $risesum = 0; $fallnum = $fallsum = 0; $normal_orders = explode('-',Configs::get('site.normal_orders')); $middle_orders = explode('-',Configs::get('site.middle_orders')); $weighest_orders = explode('-',Configs::get('site.weighest_orders')); $normalnum = $middlenum = $weighestnum = 0; foreach ($order as $kk=>$val) { if($val['rise_or_fall'] == 'rise') { $risenum++; $risesum += $val['trade_num']; }else{ $fallnum++; $fallsum += $val['trade_num']; } if($val['trade_num'] > $normal_orders[0] && $val['trade_num'] <= $normal_orders[1]) { $normalnum += $val['trade_num']; }else if($val['trade_num'] > $middle_orders[0] && $val['trade_num'] <= $middle_orders[1]) { $middlenum += $val['trade_num']; }else if($val['trade_num'] > $weighest_orders[0] && $val['trade_num'] <= $weighest_orders[1]) { $weighestnum += $val['trade_num']; } } //涨 $value['risep'] = "单数:".$risenum."\r\n"."总额:".$risesum."\r\n"."比例:".(sprintf('%.4f',$risesum/$value['ordersum'])*100)."%"; //跌 $value['fallp'] = "单数:".$fallnum."\r\n"."总额:".$fallsum."\r\n"."比例:".(sprintf('%.4f',$fallsum/$value['ordersum'])*100)."%"; $value['normalp'] = "总额:".$normalnum."\r\n"."比例:".((sprintf('%.4f',$normalnum/$value['ordersum']))*100)."%"; $value['middlep'] = "总额:".$middlenum."\r\n"."比例:".((sprintf('%.4f',$middlenum/$value['ordersum']))*100)."%"; $value['weighestp'] = "总额:".$weighestnum."\r\n"."比例:".((sprintf('%.4f',$weighestnum/$value['ordersum']))*100)."%"; $value['createtimes'] = date('Y-m-d H:i:s',$value['createtime']); $list[$key] = $value; } $result = array("total" => $total, "rows" => $list,'extend' => ''); return json($result); } return $this->view->fetch(); } /** * 编辑 */ public function set_yk($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { // $params = $this->preExcludeFields($params); Db::startTrans(); try { $row->allowField(true)->save($params); Db::commit(); $this->success(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } } } $this->view->assign("row", $row); return $this->view->fetch(); } /** * 编辑 */ public function set_bl($ids = null) { $row = $this->model->get($ids); if (!$row) { $this->error(__('No Results were found')); } $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { if (!in_array($row[$this->dataLimitField], $adminIds)) { $this->error(__('You have no permission')); } } if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { // $params = $this->preExcludeFields($params); Db::startTrans(); try { $row->allowField(true)->save($params); Db::commit(); $this->success(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } } } $this->view->assign("row", $row); return $this->view->fetch(); } /** * 设置盈利 */ public function set_yin() { $ids = $this->request->get("ids"); if($ids){ Db::name("order")->where("id",$ids)->update(['set_loss'=>1]); } $this->success(); } /** * 设置盈利 */ public function set_kui() { $ids = $this->request->get("ids"); if($ids){ Db::name("order")->where("id",$ids)->update(['set_loss'=>2]); } $this->success(); } }