1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* Created by PhpStorm.
* User: ZCY
* Date: 2018/10/16
* Time: 11:25
*/
namespace common\models\psources;
use common\core\BaseActiveRecord;
use Yii;
class CoinAppCate extends BaseActiveRecord
{
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_app_cate}}';
}
public function getApplication()
{
return $this->hasOne(CoinApplication::class, ['id' => 'app_id']);
}
public function getCategory()
{
return $this->hasOne(CoinApplicationCategory::class, ['id' => 'cate_id']);
}
public static function getAppIdByCateId($cate_id)
{
return self::find()->where(['cate_id' => $cate_id])->asArray()->all();
}
public static function getAppCountByCateId($cate_id)
{
return self::find()->where(['cate_id' => $cate_id])->count();
}
public static function getAppCountByCateIds($cate_ids)
{
$data = self::find()->select('cate_id,count(*) as num')->where(['in','cate_id',$cate_ids])->groupBy('cate_id')->asArray()->all();
return array_column($data,'num','cate_id');
}
public static function getAppCate($category_id,$app_id)
{
return self::find()->where(['cate_id' => $category_id,'app_id' => $app_id])->one();
}
public static function getCateCountByAppId($app_id)
{
return self::find()->where(['app_id' => $app_id])->count();
}
public static function updateSort($category_id,$app_id,$sort)
{
$cate_app = self::getAppCate($category_id,$app_id);
if($cate_app){
$cate_app->sort = $sort;
$cate_app->save();
}
}
public static function getCateItemsByAppId($app_id)
{
return array_column(self::find()->where(['app_id' => $app_id])->asArray()->all(),'cate_id');
}
}