xhMerchantAccountService.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\components\dict;
  5. use common\models\xhMerchantAccount;
  6. class xhMerchantAccountService {
  7. public static function add($data)
  8. {
  9. $return = xhMerchantAccount::add($data);
  10. $businessLicense = $return['businessLicense'];
  11. $cacheKey = dict::getCacheKey('xhMerchantAccount').$businessLicense;
  12. $params = [$cacheKey];
  13. if(!empty($return)){
  14. foreach($return as $key => $val){
  15. $params[] = $key;
  16. $params[] = $val;
  17. }
  18. }
  19. Yii::$app->redis->executeCommand('HMSET',$params);
  20. return $return;
  21. }
  22. public static function getByBusinessLicense($no)
  23. {
  24. $cacheKey = dict::getCacheKey('xhMerchantAccount').$no;
  25. $apply = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
  26. if(!empty($apply)){
  27. $arr = [];
  28. $i = 0;
  29. $x = 0;
  30. foreach($apply as $key => $val){
  31. $i++;
  32. if($i%2 == 0){
  33. $arr[$x]['value'] = $val;
  34. $x++;
  35. }else{
  36. $arr[$x]['key'] = $val;
  37. }
  38. }
  39. $applyArr = [];
  40. foreach($arr as $key => $val){
  41. $applyArr[$val['key']] = $val['value'];
  42. }
  43. unset($applyArr['info_already_get_by_sql']);
  44. return $applyArr;
  45. }
  46. $apply = xhMerchantAccount::find()->where(['businessLicense' => $no])->asArray()->one();
  47. $params = [$cacheKey];
  48. $params[] = 'info_already_get_by_sql';
  49. $params[] = 'ok';
  50. if(!empty($apply)){
  51. foreach($apply as $key => $val){
  52. $params[] = $key;
  53. $params[] = $val;
  54. }
  55. }
  56. Yii::$app->redis->executeCommand('HMSET',$params);
  57. return $apply;
  58. }
  59. }