cxgj/modules/admin/models/BindLogListForm.php
2023-11-27 09:45:13 +08:00

289 lines
10 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2020-11-5
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\admin\models;
use app\components\EncryptHelper;
use app\models\BallCart;
use app\models\Coach;
use app\models\DeviceUniqueBindStore;
use app\models\DeviceUniqueBindUser;
use app\models\DeviceUniqueData;
use app\models\Order;
use app\models\Store;
use app\models\User;
use app\models\UserOauth;
use app\models\UserToken;
use app\models\Admin;
use app\modules\api\models\DeviceUniqueDataForm;
use yii\data\Pagination;
class BindLogListForm extends AdminModel
{
public $page;
public $limit;
public $keywords;
public $status;
public $store_id;
public $jiqiu_num; # 击球数量
public $jiqiu_type; # 击球类型,大于等于小于号
public $id;
public $type;
public $data;
public $pole_type;
public $pole_class;
public $start_date;
public $end_date;
public $date;
public function rules()
{
return [
[['keywords',], 'trim'],
[['keywords','data','pole_type','pole_class','start_date','end_date','date'], 'string'],
[['page', 'limit','status','store_id','is_true','jiqiu_num','jiqiu_type','id','type'], 'integer'],
[['page'], 'default', 'value' => 1],
[['limit'], 'default', 'value' => 20],
];
}
/**
* @ Author : Lw
* @ CreateTime : 2022-11-11
* @ Info : 获取租赁数据
*/
public function actionGetZlData(){
$where = "";
if (!empty($this->store_id)) {
$where = " AND (`store_id` = {$this->store_id}) ";
}
$time = time();
$start_date = $time-60*60*12;
$end_date = $time;
if(!empty($this->date)){
$explode = explode(' - ',$this->date);
if(!empty($explode)){
$start_date = strtotime($explode[0]);
$end_date = strtotime($explode[1]);
}
}
$temp_data = [];
$res_format = "%Y-%m-%d";
switch ($this->type){
case 1:
$res_format = "%Y-%m-%d %H";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60);$i++){
$temp_key = $start_date+($i*(60*60));
$temp_data[date('Y-m-d H',$temp_key)] = 0;
}
}
break;
case 2:
$res_format = "%Y-%m-%d";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60*24);$i++){
$temp_key = $start_date+($i*(60*60*24));
$temp_data[date('Y-m-d',$temp_key)] = 0;
}
}
break;
case 3:
$res_format = "%Y-%m";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60*24*30);$i++){
$temp_key = $start_date+($i*(60*60*24*30));
$temp_data[date('Y-m',$temp_key)] = 0;
}
}
break;
}
$sql = "SELECT from_unixtime(`created_at`, '{$res_format}') AS `riqi`, count(`id`) AS `count`
FROM `cx_order` WHERE(`created_at` BETWEEN $start_date AND $end_date) $where AND (`is_delete` = 0) AND (`is_pay` = '1') GROUP BY from_unixtime(`created_at`, '{$res_format}')";
$query = (new Order())->find();
$query->sql = $sql;
$create = $query->createCommand();
$record = $create->queryAll();
$data = array_column($record,'count','riqi');
$temp_data = array_merge($temp_data,$data);
return ['data'=>['x'=>array_keys($temp_data),'data'=>array_values($temp_data)]];
}
/**
* @ Author : Lw
* @ CreateTime : 2022-11-11
* @ Info : 获取扫码数据
*/
public function actionGetQrData(){
if(empty($this->store_id)){
$this->store_id = null;
}
$time = time();
$start_date = $time-60*60*12;
$end_date = $time;
if(!empty($this->date)){
$explode = explode(' - ',$this->date);
if(!empty($explode)){
$start_date = strtotime($explode[0]);
$end_date = strtotime($explode[1]);
}
}
# 查找所有的球车
$select = BallCart::find()->andFilterWhere([
'store_id' => $this->store_id,
])->andWhere([
'is_delete' => 0,
])->select('name,ball_number as id')->asArray()->all();
$data = [];
$keys = [];
foreach ($select as $key=>$val){
$temp_data = [];
$where = "and type=2 and unionid={$val['id']}";
$data[$key] = [
'name' => $val['name'],
'data' => [],
];
# 查找每个数据$temp_data = [];
$res_format = "%Y-%m-%d";
switch ($this->type){
case 1:
$res_format = "%Y-%m-%d %H";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60);$i++){
$temp_key = $start_date+($i*(60*60));
$temp_data[date('Y-m-d H',$temp_key)] = 0;
}
}
break;
case 2:
$res_format = "%Y-%m-%d";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60*24);$i++){
$temp_key = $start_date+($i*(60*60*24));
$temp_data[date('Y-m-d',$temp_key)] = 0;
}
}
break;
case 3:
$res_format = "%Y-%m";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60*24*30);$i++){
$temp_key = $start_date+($i*(60*60*24*30));
$temp_data[date('Y-m',$temp_key)] = 0;
}
}
break;
}
$sql = "SELECT from_unixtime(`created_at`, '{$res_format}') AS `riqi`, count(`id`) AS `count`
FROM `cx_qrcode_record` WHERE(`created_at` BETWEEN $start_date AND $end_date) $where AND (`is_delete` = 0) GROUP BY from_unixtime(`created_at`, '{$res_format}')";
$query = (new Order())->find();
$query->sql = $sql;
$create = $query->createCommand();
$record = $create->queryAll();
$data_ = array_column($record,'count','riqi');
$temp_data = array_merge($temp_data,$data_);
if(empty($key)){
$keys = array_keys($temp_data);
}
$data[$key]['data'] = array_values($temp_data);
}
return ['data'=>['x'=>$keys,'data'=>$data]];
}
/**
* @ Author : Lw
* @ CreateTime : 2022-11-15
* @ Info : 获取场地扫码数据
*/
public function actionGetCdQrData(){
if(empty($this->store_id)){
$this->store_id = null;
}
$time = time();
$start_date = $time-60*60*12;
$end_date = $time;
if(!empty($this->date)){
$explode = explode(' - ',$this->date);
if(!empty($explode)){
$start_date = strtotime($explode[0]);
$end_date = strtotime($explode[1]);
}
}
# 查找所有的球车
$select = Store::find()->andFilterWhere([
'id' => $this->store_id,
])->andWhere([
'is_delete' => 0,
])->select('id,name')->asArray()->all();
$data = [];
$keys = [];
foreach ($select as $key=>$val){
$temp_data = [];
$where = "and type=1 and unionid={$val['id']}";
$data[$key] = [
'name' => $val['name'],
'data' => [],
];
# 查找每个数据$temp_data = [];
$res_format = "%Y-%m-%d";
switch ($this->type){
case 1:
$res_format = "%Y-%m-%d %H";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60);$i++){
$temp_key = $start_date+($i*(60*60));
$temp_data[date('Y-m-d H',$temp_key)] = 0;
}
}
break;
case 2:
$res_format = "%Y-%m-%d";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60*24);$i++){
$temp_key = $start_date+($i*(60*60*24));
$temp_data[date('Y-m-d',$temp_key)] = 0;
}
}
break;
case 3:
$res_format = "%Y-%m";
if(!empty($start_date)){
for($i=0;$i<($end_date-$start_date)/(60*60*24*30);$i++){
$temp_key = $start_date+($i*(60*60*24*30));
$temp_data[date('Y-m',$temp_key)] = 0;
}
}
break;
}
$sql = "SELECT from_unixtime(`created_at`, '{$res_format}') AS `riqi`, count(`id`) AS `count`
FROM `cx_qrcode_record` WHERE(`created_at` BETWEEN $start_date AND $end_date) $where AND (`is_delete` = 0) GROUP BY from_unixtime(`created_at`, '{$res_format}')";
$query = (new Order())->find();
$query->sql = $sql;
$create = $query->createCommand();
$record = $create->queryAll();
$data_ = array_column($record,'count','riqi');
$temp_data = array_merge($temp_data,$data_);
if(empty($key)){
$keys = array_keys($temp_data);
}
$data[$key]['data'] = array_values($temp_data);
}
return ['data'=>['x'=>$keys,'data'=>$data]];
}
}