| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace common\services;
- use Yii;
- use common\components\dict;
- use common\models\xhApplyOrder;
- class xhApplyOrderService {
- public static function nameIsUse($applyName)
- {
- $use = xhApplyOrder::getByCondition(['applyName'=>$applyName,'payStatus'=>1]);
- return $use;
- }
- public static function emailIsUse($email)
- {
- $apply = xhApplyOrder::getByCondition(['email'=>$email,'payStatus'=>1]);
- if(empty($apply)){
- return false;
- }
- return true;
- }
- public static function getByUserId($userId)
- {
- $apply = xhApplyOrder::getByCondition(['userId'=>$userId]);
- return $apply;
- }
- public static function getBySjId($sjId)
- {
- $apply = xhApplyOrder::getByCondition(['invitedMerchantId'=>$sjId]);
- return $apply;
- }
- public static function add($data)
- {
- $return = xhApplyOrder::add($data);
- $id = $return['id'];
- $cacheKey = dict::getCacheKey('xhApplyOrder').$id;
- $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 updateById($id,$data)
- {
- xhApplyOrder::updateById($id, $data);
- self::getById($id);
- $cacheKey = dict::getCacheKey('xhApplyOrder').$id;
- $params = [$cacheKey];
- foreach($data as $key => $val){
- $params[] = $key;
- $params[] = $val;
- }
- Yii::$app->redis->executeCommand('HMSET',$params);
- }
- public static function getById($id)
- {
- $cacheKey = dict::getCacheKey('xhApplyOrder').$id;
- $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 = xhApplyOrder::find()->where(['id' => $id])->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;
- }
- }
|