| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace common\services;
- use common\components\arrayUtil;
- use Yii;
- use common\components\dict;
- use common\components\stringUtil;
- use common\components\wxUtil;
- use common\models\xhMerchantExtend;
- class xhMerchantExtendService
- {
-
- public static function getBySjId($sjId)
- {
- $merchant = xhMerchantExtend::find()->where(['sjId' => $sjId])->asArray()->one();
- return $merchant;
- }
-
- public static function add($data)
- {
- $return = xhMerchantExtend::add($data);
- $sjId = $return['id'];
- self::refresh($sjId);
- return $return;
- }
-
- /**
- * 更新缓存信息
- */
- public static function refresh($sjId)
- {
- $extendKey = dict::getCacheKey('merchantExtend') . $sjId;
- Yii::$app->redis->executeCommand('DEL', [$extendKey]);
- self::getBySjId($sjId);
- }
-
- /**
- * 更新数据
- */
- public static function updateBySjId($sjId, $data)
- {
- xhMerchantExtend::updateByCondition(['sjId' => $sjId], $data);
- $cacheKey = dict::getCacheKey('merchantExtend') . $sjId;
- $params = [$cacheKey];
- foreach ($data as $key => $val) {
- $params[] = $key;
- $params[] = $val;
- }
- Yii::$app->redis->executeCommand('HMSET', $params);
- }
-
- /**
- * 积分等级列表
- */
- public static function getGradeList($extend, $order = 'asc')
- {
- $gradeStr = $extend['gradeList'];
- $data = [];
- if (!empty($gradeStr)) {
- $arr = explode("I", $gradeStr);
- $arr = array_filter($arr);
- foreach ($arr as $key => $val) {
- $son = explode("_", $val);
- $discount = $son[2];
- $data[$son[0]] = ['level' => $son[0], 'growth' => $son[1], 'discount' => $discount];
- }
- }
- $data = arrayUtil::sort($data, 'level', $order);
- return $data;
- }
- }
|