xhApplyOrderService.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace common\services;
  3. use Yii;
  4. use common\components\dict;
  5. use common\models\xhApplyOrder;
  6. class xhApplyOrderService {
  7. public static function nameIsUse($applyName)
  8. {
  9. $use = xhApplyOrder::getByCondition(['applyName'=>$applyName,'payStatus'=>1]);
  10. return $use;
  11. }
  12. public static function emailIsUse($email)
  13. {
  14. $apply = xhApplyOrder::getByCondition(['email'=>$email,'payStatus'=>1]);
  15. if(empty($apply)){
  16. return false;
  17. }
  18. return true;
  19. }
  20. public static function getByUserId($userId)
  21. {
  22. $apply = xhApplyOrder::getByCondition(['userId'=>$userId]);
  23. return $apply;
  24. }
  25. public static function getBySjId($sjId)
  26. {
  27. $apply = xhApplyOrder::getByCondition(['invitedMerchantId'=>$sjId]);
  28. return $apply;
  29. }
  30. public static function add($data)
  31. {
  32. $return = xhApplyOrder::add($data);
  33. $id = $return['id'];
  34. $cacheKey = dict::getCacheKey('xhApplyOrder').$id;
  35. $params = [$cacheKey];
  36. if(!empty($return)){
  37. foreach($return as $key => $val){
  38. $params[] = $key;
  39. $params[] = $val;
  40. }
  41. }
  42. Yii::$app->redis->executeCommand('HMSET',$params);
  43. return $return;
  44. }
  45. public static function updateById($id,$data)
  46. {
  47. xhApplyOrder::updateById($id, $data);
  48. self::getById($id);
  49. $cacheKey = dict::getCacheKey('xhApplyOrder').$id;
  50. $params = [$cacheKey];
  51. foreach($data as $key => $val){
  52. $params[] = $key;
  53. $params[] = $val;
  54. }
  55. Yii::$app->redis->executeCommand('HMSET',$params);
  56. }
  57. public static function getById($id)
  58. {
  59. $cacheKey = dict::getCacheKey('xhApplyOrder').$id;
  60. $apply = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
  61. if(!empty($apply)){
  62. $arr = [];
  63. $i = 0;
  64. $x = 0;
  65. foreach($apply as $key => $val){
  66. $i++;
  67. if($i%2 == 0){
  68. $arr[$x]['value'] = $val;
  69. $x++;
  70. }else{
  71. $arr[$x]['key'] = $val;
  72. }
  73. }
  74. $applyArr = [];
  75. foreach($arr as $key => $val){
  76. $applyArr[$val['key']] = $val['value'];
  77. }
  78. unset($applyArr['info_already_get_by_sql']);
  79. return $applyArr;
  80. }
  81. $apply = xhApplyOrder::find()->where(['id' => $id])->asArray()->one();
  82. $params = [$cacheKey];
  83. $params[] = 'info_already_get_by_sql';
  84. $params[] = 'ok';
  85. if(!empty($apply)){
  86. foreach($apply as $key => $val){
  87. $params[] = $key;
  88. $params[] = $val;
  89. }
  90. }
  91. Yii::$app->redis->executeCommand('HMSET',$params);
  92. return $apply;
  93. }
  94. }