| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- namespace common\services;
- use Yii;
- use linslin\yii2\curl;
- use common\components\dict;
- use common\models\xhUserTagClass;
- class xhUserTagClassService {
- /**
- * 更新获取商家的用户标签
- */
- public static function refreshMerchantTag($sjId)
- {
- $merchantTagKey = dict::getCacheKey('merchantTag').$sjId;
- Yii::$app->redis->executeCommand('DEL', [$merchantTagKey]);
- return self::getMerchantTag($sjId);
- }
- /**
- * 获取商家的所有用户标签
- */
- public static function getMerchantTag($sjId)
- {
- $merchantTagKey = dict::getCacheKey('merchantTag').$sjId;
- $tag = Yii::$app->redis->executeCommand('HGETALL', [$merchantTagKey]);
- if(!empty($tag)){
- $i = 0;
- $x = 0;
- $arr = [];
- foreach($tag as $key => $val){
- $i++;
- if($i%2 == 0){
- $arr[$x]['value'] = $val;
- $x++;
- }else{
- $arr[$x]['key'] = $val;
- }
- }
- $return = [];
- foreach($arr as $key => $val){
- $return[$val['key']] = $val['value'];
- }
- unset($return['info_already_get_by_sql']);
- return $return;
- }
- $tag = xhUserTagClass::getAllByCondition(['sjId' => $sjId]);
- $arr = [];
- $params = [$merchantTagKey];
- $params[] = 'info_already_get_by_sql';
- $params[] = 'ok';//redis没有办法设置带空值的键,加此可以数据空时表示取过
- if(!empty($tag)){
- foreach($tag as $key => $val){
- $arr[$val['tagId']] = $val['name'];
- $params[] = $val['tagId'];
- $params[] = $val['name'];
- }
- }
- Yii::$app->redis->executeCommand('HMSET',$params);//将用户信息、用户标签放入缓存
- return $arr;
- }
- public static function add($data,$sjId)
- {
- $class = xhUserTagClass::add($data);
- self::refreshMerchantTag($sjId);
- return $class;
- }
- public static function updateById($id,$data,$sjId)
- {
- xhUserTagClass::updateById($id,$data);
- self::refreshMerchantTag($sjId);
- }
- public static function updateByCondition($condition,$data,$sjId)
- {
- xhUserTagClass::updateByCondition($condition,$data);
- self::refreshMerchantTag($sjId);
- }
- public static function deleteByCondition($condition,$sjId)
- {
- xhUserTagClass::deleteByCondition($condition);
- self::refreshMerchantTag($sjId);
- }
- public static function getByCondition($condition)
- {
- return xhUserTagClass::getByCondition($condition);
- }
- public static function getAllByCondition($condition)
- {
- return xhUserTagClass::getAllByCondition($condition);
- }
- }
|