| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Titan 名字就是密码
- * Date: 2020/1/6
- * Time: 16:05
- */
- namespace backend\models;
- use common\helpers\Utils;
- use yii\db\ActiveRecord;
- class Mt5Deal extends ActiveRecord
- {
- public static function tableName()
- {
- return "mt5_deals";
- }
- public static function getDb()
- {
- return \Yii::$app->get('mt5db');
- }
- public function getDealList($post)
- {
- $result = ['code'=>0,'data'=>[],'message'=>''];
- $order = isset($post['order']) ? $post['order'] : '';
- $orderBy = isset($post['orderBy']) ? strtolower($post['orderBy']) : 'desc';
- $search = isset($post['search']) ? $post['search'] : '';
- $start = isset($post['start']) ? (int) $post['start'] : 0;
- $length = isset($post['length']) ? (int) $post['length'] : 20;
- $draw = isset($post['draw']) ? $post['draw'] : 1;
- $where = ['and'];
- if($search) {
- $where[] = [
- 'or',
- ['like','Deal',$search],
- ['like',"Login",$search]
- ];
- }
- $allowOrderColumn = ['Time','Login','Deal','Symbol','Action','Entry','Volume','Price','PriceSL','PriceTP','Storage','Profit'];
- if(in_array($order,$allowOrderColumn) && in_array($orderBy,['asc','desc'])){
- if($orderBy == "asc"){
- $orderCondition = [$order => SORT_ASC];
- }else{
- $orderCondition = [$order => SORT_DESC];
- }
- }else{
- $orderCondition = ['Order' => SORT_DESC];
- }
- $query = static::find();
- $query->where($where)
- ->orderBy($orderCondition);
- $count = $query->count();
- $query->offset($start)->limit($length);
- $list = $query->asArray()->all();
- if($count){
- foreach ($list as $k => $v){
- $list[$k]['Price'] = Utils::formatFloatOrInt($v['Price'],5);
- $list[$k]['Profit'] = Utils::formatFloatOrInt($v['Profit'],2);
- $list[$k]['PriceSL'] = Utils::formatFloatOrInt($v['PriceSL'],2);
- $list[$k]['PriceTP'] = Utils::formatFloatOrInt($v['PriceTP'],2);
- }
- }
- $data['data'] = $list;
- $data['draw'] = $draw;
- $data['recordsFiltered'] = $count;
- $data['recordsTotal'] = $count;
- $result['data'] = $data;
- $result['code'] = 1;
- return $result;
- }
- }
|