Mt5Order.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Titan 名字就是密码
  5. * Date: 2020/1/3
  6. * Time: 16:17
  7. */
  8. namespace backend\models;
  9. use common\helpers\Utils;
  10. use yii\db\ActiveRecord;
  11. class Mt5Order extends ActiveRecord
  12. {
  13. public static function tableName()
  14. {
  15. return "mt5_orders_history";
  16. }
  17. public static function getDb()
  18. {
  19. return \Yii::$app->get('mt5db');
  20. }
  21. public function getOrderList($post)
  22. {
  23. $result = ['code'=>0,'data'=>[],'message'=>''];
  24. $order = isset($post['order']) ? $post['order'] : '';
  25. $orderBy = isset($post['orderBy']) ? strtolower($post['orderBy']) : 'desc';
  26. $search = isset($post['search']) ? $post['search'] : '';
  27. $start = isset($post['start']) ? (int) $post['start'] : 0;
  28. $length = isset($post['length']) ? (int) $post['length'] : 20;
  29. $draw = isset($post['draw']) ? $post['draw'] : 1;
  30. $where = ['and'];
  31. if($search) {
  32. $where[] = [
  33. 'or',
  34. ['like','Order',$search],
  35. ['like',"Login",$search]
  36. ];
  37. }
  38. $allowOrderColumn = ['Login','Order','PositionID','Symbol','Type','VolumeInitial','PriceSL','PriceTP','PriceOrder','TimeSetup','PriceCurrent','PriceTrigger','TimeDone','TimeExpiration','Reason','State','RateMargin','Comment'];
  39. if(in_array($order,$allowOrderColumn) && in_array($orderBy,['asc','desc'])){
  40. if($orderBy == "asc"){
  41. $orderCondition = [$order => SORT_ASC];
  42. }else{
  43. $orderCondition = [$order => SORT_DESC];
  44. }
  45. }else{
  46. $orderCondition = ['Order' => SORT_DESC];
  47. }
  48. $query = static::find();
  49. $query->where($where)
  50. ->orderBy($orderCondition);
  51. $count = $query->count();
  52. $query->offset($start)->limit($length);
  53. $list = $query->asArray()->all();
  54. // if($count){
  55. // foreach ($list as $k => $v){
  56. // $list[$k][''] = Utils::formatFloatOrInt($v,8);
  57. // }
  58. // }
  59. $data['data'] = $list;
  60. $data['draw'] = $draw;
  61. $data['recordsFiltered'] = $count;
  62. $data['recordsTotal'] = $count;
  63. $result['data'] = $data;
  64. $result['code'] = 1;
  65. return $result;
  66. }
  67. }