| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- <?php
- namespace app\index\controller;
- use think\Controller;
- use think\Request;
- use think\Db;
- use think\Session;
- class Index extends ApiCommon
- {
- //获取用户的函数 (根据条件筛选出来)
- public function getuser(Request $request){
- if ($request->isPost()){
- $data = input();
- $group = isset($data['group'])?$data['group']:''; //组
- $user = isset($data['user'])?$data['user']:''; //用户
- $order = isset($data['order'])?$data['order']:''; //用户
-
- $group = explode(",", $group); //使用字符串切割
- $user = explode(",", $user); //使用字符串切割
-
- $where1=[]; //后面一个字符的选择
- $where2=[]; //后面多个字符的选择
-
- foreach ($group as $key => $value) {
- // 对其中的通配符和单字符进行匹配
- $pos = strpos($value,"*"); //是否全字匹配
- if($pos===false){
-
- $pos_one = strpos($value,"?");
- if($pos_one===false){
- continue;
- }else{
- $value = str_replace("?","",$value);
- if($pos_one==0){
- $where1['Group'] = ['like','_'.$value]; //前面一个字符的选择
- }else{
- $where1['Group'] = ['like',$value.'_']; //后面一个字符的选择
- }
- unset($group[$key]);
- }
- }else{
-
- $value = str_replace("*","",$value);
- if($pos==0){
- $where2['Group'] = ['like','%'.$value]; //前面多个字符的选择
- }else{
- $where2['Group'] = ['like',$value.'%']; //后面多个字符的选择
- }
- unset($group[$key]);
- }
- }
-
- $where['Group'] = ['in',$group]; //精准选择(组的成员)
- $whereuser['Login']=['in',$user]; //精准选择(用户成员)
- $result = Db::name('mt5_users')->where($where)->whereOr($where1)->whereOr($where2)->whereOr($whereuser)->distinct(true)->select(); //筛选函数
- $result1 = Db::name('order_progress')->where(['orig_order'=>$order])->select(); //筛选函数(当前跟踪的订单)
- //外层筛选出来之前做过的订单
- foreach ($result as $key => $value) {
- //自己选择的用户
- $result[$key]['LOGIN'] = $value["Login"];
- $result[$key]['NAME'] = $value['Name'];
- $result[$key]['GROUP'] = $value['Group'];
- $result[$key]['BALANCE'] = $value['Balance'];
- foreach ($result1 as $k => $v) {
- if($value['Login']==$v['dest_login']){
- unset($result[$key]);
- }
- }
- }
- $result = array_values($result); //重新组织数组的键值对
- if($result){
-
- return json(['code'=>'00','user'=>$result,'msg'=>'获得数据成功']);
- }else{
- return json(['code'=>'01','msg'=>'没有对应的数据']);
- }
- }else{
- return json(['code'=>'01','msg'=>'请使用post方式访问']);
- }
- }
- //点击订单后获取到的信息
- public function getorder(Request $request){
- if ($request->isPost()){
- $data = input(); //获取订单的信息
- //从数据库获取到订单信息
- $OpenResult = Db::query("select PriceCurrent,TimeSetup from mt5_orders_history where PositionID={$data['orderid']} and type='0'");
- $closeResult = Db::name("mt5_orders_history")->where(["PositionID"=>$data['orderid'],"type"=>"1"])->find();
- if($OpenResult && $closeResult){
- $closeResult['OPEN_PRICE'] = $OpenResult['0']["PriceCurrent"];
- $closeResult['OPEN_TIME'] = $OpenResult['0']["TimeSetup"];
- $closeResult['CLOSE_TIME'] = $closeResult['TimeSetup'];
- $closeResult['CLOSE_PRICE'] = $closeResult['PriceCurrent'];
- $closeResult['LOGIN'] = $closeResult['Login'];
- $closeResult['TICKET'] = $closeResult['PositionID'];
- $closeResult['SYMBOL'] = $closeResult['Symbol'];
- $closeResult['VOLUME'] = $closeResult['Digits'];
- $closeResult['TP'] = $closeResult['PriceTP'];
- $closeResult['SL'] = $closeResult['PriceSL'];
- $closeResult['SL'] = $closeResult['PriceSL'];
- return json(['code'=>'00','data'=>$closeResult,'msg'=>'获得数据成功']);
- }else{
- return json(['code'=>'01','msg'=>'没有找到匹配的订单']);
- }
- }else{
- return json(['code'=>'01','msg'=>'请使用post方式访问']);
- }
- }
- // 点击订单后查询函数(rollback)
- public function rollback_order(Request $request){
- if ($request->isPost()){
- $data = input(); //获取订单的信息
- $result = Db::name('order_progress')->where(['type'=>"insert","orig_order"=>$data['orderid'],'error_code'=>0])->select(); //insert成功后插入的订单
- $result1 = Db::name('order_progress')->where(['type'=>"rollback","orig_order"=>$data['orderid']])->where('error_code','neq',0)->select(); //rollback失败后的订单
- $result2 = Db::name('order_progress')->where(['type'=>"retry","orig_order"=>$data['orderid']])->where('error_code','eq',0)->select(); //retry成功的订单
- $result = array_merge($result,$result1,$result2); //对数据进行合并
- if($result){
-
- return json(['code'=>'00','data'=>$result,'msg'=>'获得数据成功']);
- }else{
- return json(['code'=>'01','msg'=>'暂无数据']);
- }
- }else{
- return json(['code'=>'01','msg'=>'请使用post方式访问']);
- }
- }
- // 点击订单后查询函数(retry)
- public function retry_order(Request $request){
- if ($request->isPost()){
- $data = input(); //获取订单的信息
- $result = Db::name('order_progress')->where(['type'=>"insert","orig_order"=>$data['orderid']])->where('error_code','neq',0)->select(); //insert失败的订单
- $result1 = Db::name('order_progress')->where(['type'=>"retry","orig_order"=>$data['orderid']])->where('error_code','neq',0)->select(); //retry失败的订单
- $result2 = Db::name('order_progress')->where(['type'=>"except_rollback","orig_order"=>$data['orderid']])->where('error_code','neq',0)->select(); //except_rollback失败的订单
- $result = array_merge($result,$result1,$result2); //对数据进行合并
- if($result){
- return json(['code'=>'00','data'=>$result,'msg'=>'获得数据成功']);
- }else{
- return json(['code'=>'01','msg'=>'暂无数据']);
- }
- }else{
- return json(['code'=>'01','msg'=>'请使用post方式访问']);
- }
- }
-
- //确认密码函数(批量操作的时候需要)
- public function querypassword(Request $request){
- if ($request->isPost()){
- $data = input(); //获取传递的信息
- $password = md5($data['password']); //获取加密后的密码
- //根据用户来选择数据
- if($data['nickname']=="普通管理员"){
- $result = Db::name('admin')->where(['id'=>1])->find(); //找到用户(获取原始的密码)
- }else{
- $result = Db::name('admin')->where(['id'=>2])->find(); //找到用户(获取原始的密码)
- }
- // 筛选出来的数据进行密码的匹配
- if($password==$result['password']){
- return json(['code'=>'00','msg'=>'请求数据成功']);
- }else{
- return json(['code'=>'01','msg'=>'密码填写有误']);
- }
- }else{
- return json(['code'=>'01','msg'=>'请使用post方式访问']);
- }
- }
- //更新梯度函数(retry的时候进行查询)
- public function update_percentage(Request $request){
- if ($request->isPost()){
-
- $data = input(); //获取传递的信息
- $update_array =[];
- foreach ($data as $key => $value) {
- $result = Db::name('mt4_users')->where(['LOGIN'=>$value])->find();
- $update_array[$value]= $result['BALANCE'];
- }
- if($update_array){
- return json(['code'=>'00','data'=>$update_array,'msg'=>'请求数据成功']);
- }else{
- return json(['code'=>'01','data'=>$update_array,'msg'=>'请求数据有误']);
- }
- }else{
- return json(['code'=>'01','msg'=>'请使用post方式访问']);
- }
- }
- }
|