'主键' , 'smart_form_template_id' => '智能装修表单管理id', 'today_filling_times' => '今日填写次数-当天填写次数,包含同一个ID用户填写次数', 'today_view_times' => '今日访问人次-当天访问次数,只访问未填写', 'today_filling_people' => '今日填写人数-当天填写人数,一个ID用户统计一次', 'filling_times' => '总填写次数-当天填写次数,包含同一个ID用户填写次数', 'view_times' => '总访问人次-当天访问次数,只访问未填写', 'filling_people' => '总填写人数-当天填写人数,一个ID用户统计一次', 'created_at' => '添加时间', 'updated_at' => '修改时间', ]; } /** * @method checkTplUse * 判断当前表单是否填写 * @author zqh * @datetime 2022-05-06T15:23:56+0800 * @param int $template_id [description] * @return [type] [description] */ public static function checkTplUse($template_id=0){ if(!$template_id){ self::$static_error = "模板不存在"; return false; } $find = self::getOne([['smart_form_template_id'=>$template_id]],true); if($find && $find['filling_times'] > 0){ self::$static_error = "模板已填写"; return true; } return false; } /** * @method setUserStatistics * 设置表单信息 * @author zqh * @datetime 2022-05-07T03:25:02+0800 */ public static function setTplStatistics($params) { if(!isset($params['template_id']) || !$params['template_id']){ self::$static_error = "模板不存在"; return false; } $tplModel = self::findOne(['smart_form_template_id'=>$params['template_id']]); if (!$tplModel){ $tplModel = new self(); $tplModel->loadDefaultValues(); $tplModel->smart_form_template_id = $params['template_id']; } if ($params['type']=='0') { # 总访问人次-当天访问次数,只访问未填写 $tplModel->view_times = $tplModel->view_times + 1; }else{ # 填写表单 # 判断当前用户今天是否已经填写 $filling_people = AddonsSmartFormTemplateUserbehavior::findOne(['smart_form_template_id'=>$params['template_id'],'user_id'=>$params['user_id'],'behavior_type'=>1,'month_day'=>date('Y-m-d')]); $s = AddonsSmartFormTemplateUserbehavior::updateAll(['is_submit'=>1],['smart_form_template_id'=>$params['template_id'],'user_id'=>$params['user_id'],'behavior_type'=>0,'month_day'=>date('Y-m-d')]); if(!$filling_people){ # 总填写人数-当天填写人数,一个ID用户统计一次 $tplModel->filling_people = $tplModel->filling_people + 1; $tplModel->view_times = $tplModel->view_times - $s; } # 总填写次数-当天填写次数,包含同一个ID用户填写次数 $tplModel->filling_times = $tplModel->filling_times + 1; } if(!$tplModel->save()){ self::$static_error = $tplModel->getErrorMessage(); return false; } # 记录行为 $behavior = new AddonsSmartFormTemplateUserbehavior; $behavior->loadDefaultValues(); $behavior->created_at = time(); $behavior->updated_at = time(); $behavior->diy_page_id = $params['diy_page_id']; $behavior->smart_form_template_id = $params['template_id']; $behavior->user_id = $params['user_id']; $behavior->behavior_type = $params['type']; $behavior->month_day = date('Y-m-d'); $s = $behavior->insert(); if(!$s){ self::$static_error = $behavior->getErrorMessage(); return false; } return true; } }