Commit cf6f30a4 authored by shajiaiming's avatar shajiaiming

dapp visit statistics

parent 460bd26a
<?php
/**
* Created by PhpStorm.
* User: shaji
* Date: 2019/4/19
* Time: 16:14
*/
namespace api\controllers;
use api\base\BaseController;
use common\models\psources\CoinAppVisitStatistics;
use Yii;
class VisitStatisticsController extends BaseController
{
public function actionIndex()
{
$dapp = Yii::$app->request->get('dapp', '');
$identify = Yii::$app->request->get('identify', '');
$duration = Yii::$app->request->get('duration', '');
if(empty($dapp) && !empty($identify)){
$isExistModel = CoinAppVisitStatistics::find()->where(['identify' => $identify])->one();
if($isExistModel) {
return ['code' => 0,'data' => [], 'msg' => '数据记录已存在'];
}
$model = new CoinAppVisitStatistics();
$model->dapp = '';
$model->duration = '';
$model->identify = $identify;
$model->save();
return ['code' => 0,'data' => [], 'msg' => '数据记录插入成功'];
}
if(!empty($dapp) && !empty($identify)) {
$isExistModel = CoinAppVisitStatistics::find()->where(['identify' => $identify])->one();
if(!$isExistModel){
return ['code' => 0,'data' => [], 'msg' => '数据记录不存在'];
}
$isExistModel->dapp = $dapp;
$isExistModel->duration = $duration;
$isExistModel->save();
return ['code' => 0,'data' => [], 'msg' => '数据记录更新成功'];
}
}
}
\ No newline at end of file
<?php
namespace common\models\psources;
use common\core\BaseActiveRecord;
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
use Yii;
class CoinAppVisitStatistics extends BaseActiveRecord
{
// public function behaviors()
// {
// return [
// [
// 'class' => TimestampBehavior::className(),
// 'createdAtAttribute' => 'created_at', // 自己根据数据库字段修改
// 'updatedAtAttribute' => 'updated_at', // 自己根据数据库字段修改
// 'value' => new Expression('NOW()'), // 自己根据数据库字段修改
// ]
// ];
// }
public static function getDb()
{
return Yii::$app->get('p_sources');
}
public static function tableName()
{
return '{{%coin_app_visit_statistics}}';
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment