| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace common\services;
- use Yii;
- use common\components\dict;
- use common\models\xhMerchantAccount;
- class xhMerchantAccountService {
- public static function add($data)
- {
- $return = xhMerchantAccount::add($data);
- $businessLicense = $return['businessLicense'];
- $cacheKey = dict::getCacheKey('xhMerchantAccount').$businessLicense;
- $params = [$cacheKey];
- if(!empty($return)){
- foreach($return as $key => $val){
- $params[] = $key;
- $params[] = $val;
- }
- }
- Yii::$app->redis->executeCommand('HMSET',$params);
- return $return;
- }
- public static function getByBusinessLicense($no)
- {
- $cacheKey = dict::getCacheKey('xhMerchantAccount').$no;
- $apply = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
- if(!empty($apply)){
- $arr = [];
- $i = 0;
- $x = 0;
- foreach($apply as $key => $val){
- $i++;
- if($i%2 == 0){
- $arr[$x]['value'] = $val;
- $x++;
- }else{
- $arr[$x]['key'] = $val;
- }
- }
- $applyArr = [];
- foreach($arr as $key => $val){
- $applyArr[$val['key']] = $val['value'];
- }
- unset($applyArr['info_already_get_by_sql']);
- return $applyArr;
- }
- $apply = xhMerchantAccount::find()->where(['businessLicense' => $no])->asArray()->one();
- $params = [$cacheKey];
- $params[] = 'info_already_get_by_sql';
- $params[] = 'ok';
- if(!empty($apply)){
- foreach($apply as $key => $val){
- $params[] = $key;
- $params[] = $val;
- }
- }
- Yii::$app->redis->executeCommand('HMSET',$params);
- return $apply;
- }
-
- }
|