xhMerchantExtendService.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace common\services;
  3. use common\components\arrayUtil;
  4. use Yii;
  5. use common\components\dict;
  6. use common\components\stringUtil;
  7. use common\components\wxUtil;
  8. use common\models\xhMerchantExtend;
  9. class xhMerchantExtendService
  10. {
  11. public static function getBySjId($sjId)
  12. {
  13. $merchant = xhMerchantExtend::find()->where(['sjId' => $sjId])->asArray()->one();
  14. return $merchant;
  15. }
  16. public static function add($data)
  17. {
  18. $return = xhMerchantExtend::add($data);
  19. $sjId = $return['id'];
  20. self::refresh($sjId);
  21. return $return;
  22. }
  23. /**
  24. * 更新缓存信息
  25. */
  26. public static function refresh($sjId)
  27. {
  28. $extendKey = dict::getCacheKey('merchantExtend') . $sjId;
  29. Yii::$app->redis->executeCommand('DEL', [$extendKey]);
  30. self::getBySjId($sjId);
  31. }
  32. /**
  33. * 更新数据
  34. */
  35. public static function updateBySjId($sjId, $data)
  36. {
  37. xhMerchantExtend::updateByCondition(['sjId' => $sjId], $data);
  38. $cacheKey = dict::getCacheKey('merchantExtend') . $sjId;
  39. $params = [$cacheKey];
  40. foreach ($data as $key => $val) {
  41. $params[] = $key;
  42. $params[] = $val;
  43. }
  44. Yii::$app->redis->executeCommand('HMSET', $params);
  45. }
  46. /**
  47. * 积分等级列表
  48. */
  49. public static function getGradeList($extend, $order = 'asc')
  50. {
  51. $gradeStr = $extend['gradeList'];
  52. $data = [];
  53. if (!empty($gradeStr)) {
  54. $arr = explode("I", $gradeStr);
  55. $arr = array_filter($arr);
  56. foreach ($arr as $key => $val) {
  57. $son = explode("_", $val);
  58. $discount = $son[2];
  59. $data[$son[0]] = ['level' => $son[0], 'growth' => $son[1], 'discount' => $discount];
  60. }
  61. }
  62. $data = arrayUtil::sort($data, 'level', $order);
  63. return $data;
  64. }
  65. }