| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace common\services;
- use common\components\util;
- use Yii;
- use common\components\dict;
- use common\components\stringUtil;
- use linslin\yii2\curl;
- use common\components\wxUtil;
- use common\models\xhAdminToMerchant;
- class xhAdminToMerchantService {
- public static function getByAdminId($adminId)
- {
- return xhAdminToMerchant::find()->where(['adminId' => $adminId])->asArray()->one();
- }
- public static function add($data)
- {
- $relation = xhAdminToMerchant::add($data);
- $adminId = $relation['adminId'];
- $cacheKey = dict::getCacheKey('xhAdminToMerchant').'_'.$adminId;
- $params = [$cacheKey];
- if(!empty($relation)){
- foreach($relation as $key => $val){
- $params[] = $key;
- $params[] = $val;
- }
- }
- Yii::$app->redis->executeCommand('HMSET',$params);
- $sjId = $relation['sjId'];
- self::refreshByMerchantId($sjId);
- return $relation;
- }
- public static function getBySjId($sjId)
- {
- $cacheKey = dict::getCacheKey('xhAdminToMerchantList').'_'.$sjId;
- $relation = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
- if(!empty($relation)){
- $arr = [];
- $i = 0;
- $x = 0;
- foreach($relation as $key => $val){
- $i++;
- if($i%2 == 0){
- $arr[$x]['value'] = $val;
- $x++;
- }else{
- $arr[$x]['key'] = $val;
- }
- }
- $relationArr = [];
- foreach($arr as $key => $val){
- $relationArr[$val['key']] = $val['value'];
- }
- return $relationArr;
- }
- $relation = xhAdminToMerchant::find()->where(['sjId' => $sjId])->asArray()->one();
- $params = [$cacheKey];
- if(!empty($relation)){
- foreach($relation as $key => $val){
- $params[] = $key;
- $params[] = $val;
- }
- Yii::$app->redis->executeCommand('HMSET',$params);
- }
- return $relation;
- }
- public static function getAdminByMerchantId($sjId)
- {
- $relation = self::getBySjId($sjId);
- $admin = [];
- if(!empty($relation)){
- $adminId = $relation['adminId'];
- $admin = xhAdminService::getById($adminId);
- }
- return $admin;
- }
- /**
- * 删除管理员
- * @param int $adminId
- */
- public static function delByAdminId($adminId)
- {
- xhAdminToMerchant::deleteByCondition(['adminId'=>$adminId]);
- $cacheKey = dict::getCacheKey('xhAdminToMerchant').'_'.$adminId;
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- }
- /**
- * 更新商家的管理员缓存
- * @param int $sjId
- */
- public static function refreshByMerchantId($sjId)
- {
- $cacheKey = dict::getCacheKey('xhAdminToMerchantList').'_'.$sjId;
- Yii::$app->redis->executeCommand('DEL', [$cacheKey]);
- }
- }
|