| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace addons\SmartForm\common\models;
- use common\enums\StatusEnum;
- use common\models\mall\MallAddons;
- use common\models\user\User;
- use Yii;
- use yii\db\Exception;
- use addons\SmartForm\common\models\AddonsSmartFormTemplateUserBehavior; # 用户行为
- /**
- * This is the model class for table "{{%addons_smart_form_template_statistics}}".
- *
- * @property int $id
- * @property int $mall_id 商城ID
- * @property int|null $status 状态[-1:删除;0:禁用;1启用]
- * @property int $created_at 创建时间
- * @property int $updated_at 修改时间
- */
- class AddonsSmartFormTemplateStatistics extends \common\models\base\BaseActiveRecord
- {
- const ADDONS_NAME = 'SmartForm';
- /**
- * {@inheritdoc}
- */
- public static function tableName()
- {
- return '{{%addons_smart_form_template_statistics}}';
- }
- /**
- * {@inheritdoc}
- */
- public function rules()
- {
- return [
- [['smart_form_template_id'], 'required'],
- [['smart_form_template_id','today_filling_times','today_view_times','today_filling_people','filling_times','view_times','filling_people','created_at','updated_at'], 'integer'],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function attributeLabels()
- {
- return [
- 'id' => '主键' ,
- '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;
- }
-
- }
|