/** * 保存用户对产品的点击数量;仅对匿名用户有效; * @param int $pid 产品ID * @param string $userIdentity 用户识别码 */ public static function saveCilck($pid, $userIdentity = '') { if (!intval($pid)) { return false; } $gapTime = \Yii::$app->params['gapTime']; $isInsert = false; $uid = User::getAnonymousId($userIdentity); if ($uid) { $sql = "SELECT IF( ( UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(createTime) ) >" . $gapTime . " , 'true', 'false' ) as result FROM product_click WHERE userId=" . $uid . " AND userType='anonymous' ORDER BY createTime DESC LIMIT 1"; $resData = static::getDb()->createCommand($sql)->queryScalar(); if ($resData != 'false') { $isInsert = true; } } $pownId = Product::getOwnId($pid); if ($isInsert && $pownId) { static::getDb()->createCommand()->insert(static::tableName(), array('productId' => $pid, 'userId' => $uid, 'userType' => 'anonymous'))->execute(); MiaoCoin::updateClickM(static::getDb()->getLastInsertID(), $pownId); User::updateCacheMcoin(User::getSoreId($pownId), 1, 'output'); return true; } return false; }