UserLevelLogic.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeshop100%开源免费商用商城系统
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | 商业版本务必购买商业授权,以免引起法律纠纷
  8. // | 禁止对系统程序代码以任何目的,任何形式的再发布
  9. // | gitee下载:https://gitee.com/likeshop_gitee
  10. // | github下载:https://github.com/likeshop-github
  11. // | 访问官网:https://www.likeshop.cn
  12. // | 访问社区:https://home.likeshop.cn
  13. // | 访问手册:http://doc.likeshop.cn
  14. // | 微信公众号:likeshop技术社区
  15. // | likeshop团队 版权所有 拥有最终解释权
  16. // +----------------------------------------------------------------------
  17. // | author: likeshopTeam
  18. // +----------------------------------------------------------------------
  19. namespace app\openapi\logic\user;
  20. use app\common\enum\PayEnum;
  21. use app\common\model\
  22. {
  23. User,
  24. Order,
  25. UserLevel
  26. };
  27. /**
  28. * 会员等级逻辑层
  29. * Class UserLevelLogic
  30. * @package app\adminapi\logic\user
  31. */
  32. class UserLevelLogic
  33. {
  34. /*
  35. * 获取等级列表
  36. * */
  37. public function getUserLevelLists($params){
  38. $where = [];
  39. if(isset($params['level_name'])){
  40. $where[] = ['name','like','%'.$params['level_name'].'%'];
  41. }
  42. $level_list = UserLevel::where($where)->field('id,name,discount,rank,condition,offline_user_level_id,create_time')->select()->toArray();
  43. return $level_list;
  44. }
  45. /**
  46. * @notes 添加会员等级
  47. * @param array $params
  48. * @return bool
  49. * @author cjhao
  50. * @date 2021/7/28 15:08
  51. */
  52. public function addUserLevelInfo(array $params)
  53. {
  54. $userLevel = new UserLevel();
  55. $condition = '';
  56. if(isset($params['condition'])){
  57. $condition = json_encode($params['condition'],JSON_UNESCAPED_UNICODE);
  58. }
  59. $userLevel->offline_user_level_id = $params['offline_user_level_id'];
  60. $userLevel->name = $params['name'];
  61. $userLevel->rank = $params['rank'];
  62. $userLevel->image = '/resource/image/adminapi/user/user_level_icon.png';
  63. $userLevel->background_image = '/resource/image/adminapi/user/user_level_bg.png';
  64. $userLevel->remark = isset($params['remark'])?$params['remark']:'';
  65. $userLevel->discount = $params['discount'] ;
  66. $userLevel->condition =$condition;
  67. $userLevel->save();
  68. return true;
  69. }
  70. // /**
  71. // * @notes 获取用户等级
  72. // * @param $id
  73. // * @return array
  74. // * @author cjhao
  75. // * @date 2021/7/29 17:14
  76. // */
  77. // public function detail($id){
  78. // $userLevel = UserLevel::find($id);
  79. //
  80. // $detail = [
  81. // 'id' => $userLevel->id,
  82. // 'name' => $userLevel->name,
  83. // 'rank' => $userLevel->rank,
  84. // 'image' => $userLevel->image,
  85. // 'background_image' => $userLevel->background_image,
  86. // 'remark' => $userLevel->remark,
  87. // 'level_discount' => $userLevel->discount > 0 ? 1 :0,
  88. // 'discount' => $userLevel->discount,
  89. // 'condition' => \app\common\logic\UserLogic::formatLevelCondition($userLevel->condition),
  90. // ];
  91. //
  92. // return $detail;
  93. // }
  94. /**
  95. * @notes 编辑会员等级
  96. * @param array $params
  97. * @author cjhao
  98. * @date 2021/7/28 15:15
  99. */
  100. public function updateUserLevel(array $params)
  101. {
  102. $condition = '';
  103. if (isset($params['condition'])) {
  104. $condition = json_encode($params['condition'], JSON_UNESCAPED_UNICODE);
  105. }
  106. $where['name'] = $params['name'];
  107. $userlevel = UserLevel::where($where)->findOrEmpty();
  108. if ($userlevel->isEmpty()) {
  109. $userLevels = new UserLevel();
  110. $userLevels->offline_user_level_id = $params['offline_user_level_id'];
  111. $userLevels->name = $params['name'];
  112. $userLevels->image = '/resource/image/adminapi/user/user_level_icon.png';
  113. $userLevels->rank = $params['rank'];
  114. $userLevels->background_image = '/resource/image/adminapi/user/user_level_bg.png';
  115. $userLevels->remark = isset($params['remark']) ? $params['remark'] : '';
  116. $userLevels->discount = $params['discount'];
  117. $userLevels->condition = $condition;
  118. $userLevels->save();
  119. } else {
  120. $updateWhere['name'] = $params['name'];
  121. $update['offline_user_level_id'] = $params['offline_user_level_id'];
  122. $update['rank'] = $params['rank'];
  123. $update['image'] = '/resource/image/adminapi/user/user_level_icon.png';
  124. $update['background_image'] = '/resource/image/adminapi/user/user_level_bg.png';
  125. $update['remark'] = isset($params['remark']) ? $params['remark'] : '';
  126. $update['discount'] = $params['discount'];
  127. $update['condition'] = $condition;
  128. $ret = UserLevel::where($updateWhere)->update($update);
  129. }
  130. return true;
  131. }
  132. /**
  133. * @notes 删除会员等级
  134. * @param int $id
  135. * @return bool
  136. * @author cjhao
  137. * @date 2021/7/28 16:59
  138. */
  139. public function del($params)
  140. {
  141. $where['name'] = $params['name'];
  142. $user_level = UserLevel::where($where)->find();
  143. if ($user_level) {
  144. $user_level->delete_time = time();
  145. $user_level->save();
  146. //todo 将该等级的用户全部降到系统默认等级
  147. $level = UserLevel::where(['rank' => 1])->find();
  148. if ($level) {
  149. User::where(['level' => $user_level['id']])->update(['level' => $level->id]);
  150. }
  151. }
  152. return true;
  153. }
  154. /**
  155. * @notes 处理前端传过来的等级数据
  156. * @param $condition
  157. * @author cjhao
  158. * @date 2022/4/28 17:05
  159. */
  160. public function disposeCondition($condition){
  161. //默认满足任意条件
  162. $condition_type = $condition['condition_type'] ?? 0;
  163. //默认不勾选
  164. $isSingleMoney = $condition['is_single_money'];
  165. //单笔消费金额
  166. $singleMoney =$condition['single_money'] ?? '';
  167. //默认不勾选
  168. $isTotalMoney = $condition['is_total_money'];
  169. //累计消费金额
  170. $totalMoney = $condition['total_money'] ?? '';
  171. //默认不勾选
  172. $isTotalNum = $condition['is_total_num'];
  173. //累计消费次数
  174. $totalNum = $condition['total_num'] ?? '';
  175. return [
  176. 'condition_type' => (int)$condition_type, //默认满足任意条件
  177. 'is_single_money' => (int)$isSingleMoney, //默认不勾选
  178. 'single_money' => $singleMoney ? round($singleMoney,2) : '',
  179. 'is_total_money' => (int)$isTotalMoney,
  180. 'total_money' => $totalMoney ? round($totalMoney,2) : '',
  181. 'is_total_num' => (int)$isTotalNum,
  182. 'total_num' => $totalNum ? (int)$totalNum : '',
  183. ];
  184. }
  185. }