| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 | <?phpnamespace Home\Controller;use Think\Model;/** * @author   Xusong */class ThemeDataController extends CommonController {    public function _initialize() {        // 调用父类前置方法        parent::_initialize();    }    /**     * 新增主题运营数据     */    public function addData()    {        $uid            = I('uid');        $theme_id       = I('theme_id',0,'intval');        $user_origin    = I('user_origin');        $insertData = array(            'uid'           =>$uid,            'theme_id'      =>$theme_id,            'user_origin'   =>$user_origin,            'created_at'    =>date('Y-m-d H:i:s'),            'date'          =>date('Ymd')        );        if(!$theme_data = M('theme')->where(['id'=>$theme_id])->find()){            $this->responseError('params invalid');        }        //汇总数据更新        if(M('theme_detail')->where(['uid'=>$uid,'theme_id'=>$theme_id])->find()){            //如果数据存在,只更新pv,不更新uv            $update['page_view'] = $theme_data['page_view'] + 1;            M('theme')->where(['id'=>$theme_id])->save($update);        }else{            //如果数据存在,更新pv,更新uv            $update['page_view'] = $theme_data['page_view'] + 1;            $update['user_view'] = $theme_data['user_view'] + 1;            M('theme')->where(['id'=>$theme_id])->save($update);        }        if(!M('theme_detail')->add($insertData)){            echo M()->getLastSql();        }        $this->responseSuccess();    }}
 |