UserLogic.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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\adminapi\logic\settings\user;
  20. use app\common\{enum\DistributionConfigEnum,
  21. enum\UserEnum,
  22. model\Distribution,
  23. model\DistributionConfig,
  24. service\ConfigService,
  25. service\FileService};
  26. /**
  27. * 设置-用户设置逻辑层
  28. * Class UserLogic
  29. * @package app\adminapi\logic\config
  30. */
  31. class UserLogic
  32. {
  33. /**
  34. * @notes 获取用户设置
  35. * @return array
  36. * @author cjhao
  37. * @date 2021/7/27 17:49
  38. */
  39. public static function getConfig():array
  40. {
  41. $poster = DistributionConfig::where(['key'=>'poster'])->value('value', DistributionConfigEnum::DEFAULT_POSTER);
  42. $config = [
  43. //默认头像
  44. 'default_avatar' => FileService::getFileUrl(ConfigService::get('config', 'default_avatar', config('project.default_image.user_avatar'))),
  45. //开启邀请下级
  46. 'invite_open' => ConfigService::get('config', 'invite_open', config('project.default_user.invite_open')),
  47. //邀请下级资格
  48. 'invite_ways' => ConfigService::get('config', 'invite_ways', config('project.default_user.invite_ways')),
  49. //邀请下级指定用户
  50. 'invite_appoint_user' => ConfigService::get('config', 'invite_appoint_user', config('project.default_user.invite_appoint_user')),
  51. //成为下级条件
  52. 'invite_condition' => ConfigService::get('config', 'invite_condition', config('project.default_user.invite_condition')),
  53. //分销海报背景图
  54. 'poster' => FileService::getFileUrl($poster),
  55. ];
  56. return $config;
  57. }
  58. /**
  59. * @notes 设置用户设置
  60. * @param array $postData
  61. * @return bool
  62. * @author cjhao
  63. * @date 2021/7/27 17:58
  64. */
  65. public function setConfig(array $params):bool
  66. {
  67. ConfigService::set('config', 'default_avatar', $params['default_avatar']);
  68. ConfigService::set('config', 'invite_open', $params['invite_open']);
  69. ConfigService::set('config', 'invite_ways', $params['invite_ways']);
  70. ConfigService::set('config', 'invite_appoint_user',$params['invite_appoint_user']);
  71. ConfigService::set('config', 'invite_condition', $params['invite_condition']);
  72. $config = DistributionConfig::where(['key' => 'poster'])->findOrEmpty();
  73. if($config->isEmpty()){
  74. DistributionConfig::create(['key'=>'poster','value'=>FileService::setFileUrl($params['poster'])]);
  75. }else{
  76. DistributionConfig::where(['key'=>'poster'])->update(['value'=>$params['poster']]);
  77. }
  78. return true;
  79. }
  80. public function getRegisterConfig():array
  81. {
  82. $config = [
  83. //注册方式
  84. 'register_way' => ConfigService::get('config', 'register_way', config('project.login.register_way')),
  85. //登录方式
  86. 'login_way' => ConfigService::get('config', 'login_way', config('project.login.login_way')),
  87. //手机号码注册需验证码
  88. 'is_mobile_register_code' => ConfigService::get('config', 'is_mobile_register_code', config('project.login.is_mobile_register_code')),
  89. //注册强制绑定手机
  90. 'coerce_mobile' => ConfigService::get('config', 'coerce_mobile', config('project.login.coerce_mobile')),
  91. //公众号微信授权登录
  92. 'h5_wechat_auth' => ConfigService::get('config', 'h5_wechat_auth', config('project.login.h5_wechat_auth')),
  93. //公众号自动微信授权登录
  94. 'h5_auto_wechat_auth' => ConfigService::get('config', 'h5_auto_wechat_auth', config('project.login.h5_auto_wechat_auth')),
  95. //小程序微信授权登录
  96. 'mnp_wechat_auth' => ConfigService::get('config', 'mnp_wechat_auth', config('project.login.mnp_wechat_auth')),
  97. //小程序自动微信授权登录
  98. 'mnp_auto_wechat_auth' => ConfigService::get('config', 'mnp_auto_wechat_auth', config('project.login.mnp_auto_wechat_auth')),
  99. //APP微信授权登录
  100. 'app_wechat_auth' => ConfigService::get('config', 'app_wechat_auth', config('project.login.app_wechat_auth')),
  101. //字节小程序授权登录
  102. 'toutiao_auth' => ConfigService::get('config', 'toutiao_auth', config('project.login.toutiao_auth')),
  103. //字节小程序自动授权登录
  104. 'toutiao_auto_auth' => ConfigService::get('config', 'toutiao_auto_auth', config('project.login.toutiao_auto_auth')),
  105. ];
  106. return $config;
  107. }
  108. /**
  109. * @notes 设置登录注册
  110. * @param array $params
  111. * @return bool
  112. * @author cjhao
  113. * @date 2021/9/14 17:20
  114. */
  115. public static function setRegisterConfig(array $params):bool
  116. {
  117. //注册方式:1-手机号注册
  118. ConfigService::set('config', 'register_way', $params['register_way']);
  119. //登录方式:1-账号密码登录;2-手机短信验证码登录
  120. ConfigService::set('config', 'login_way', $params['login_way']);
  121. //手机号码注册需验证码
  122. ConfigService::set('config', 'is_mobile_register_code', $params['is_mobile_register_code']);
  123. //注册强制绑定手机
  124. ConfigService::set('config', 'coerce_mobile', $params['coerce_mobile']);
  125. //公众号微信授权登录
  126. ConfigService::set('config', 'h5_wechat_auth', $params['h5_wechat_auth']);
  127. //公众号自动微信授权登录
  128. ConfigService::set('config', 'h5_auto_wechat_auth', $params['h5_auto_wechat_auth']);
  129. //小程序微信授权登录
  130. ConfigService::set('config', 'mnp_wechat_auth', $params['mnp_wechat_auth']);
  131. //小程序自动微信授权登录
  132. ConfigService::set('config', 'mnp_auto_wechat_auth', $params['mnp_auto_wechat_auth']);
  133. //APP微信授权登录
  134. ConfigService::set('config', 'app_wechat_auth', $params['app_wechat_auth']);
  135. //字节小程序授权登录
  136. ConfigService::set('config', 'toutiao_auth', $params['toutiao_auth']);
  137. //字节小程序自动授权登录
  138. ConfigService::set('config', 'toutiao_auto_auth', $params['toutiao_auto_auth']);
  139. return true;
  140. }
  141. /**
  142. * @notes 获取用户提现
  143. * @return array
  144. * @author cjhao
  145. * @date 2021/9/14 17:22
  146. */
  147. public function getWithdrawConfig():array
  148. {
  149. $config = [
  150. //提现方式:1-钱包余额;2-微信零钱;3-银行卡;4-微信收款码;5-支付宝收款码
  151. 'withdraw_way' => ConfigService::get('config', 'withdraw_way'),
  152. //微信零钱接口:1-企业付款到零钱;2-商家转账到零钱
  153. 'transfer_way' => ConfigService::get('config', 'transfer_way',1),
  154. //最低提现金额
  155. 'withdraw_min_money' => ConfigService::get('config', 'withdraw_min_money'),
  156. //最高提现金额
  157. 'withdraw_max_money' => ConfigService::get('config', 'withdraw_max_money'),
  158. //提现手续费
  159. 'withdraw_service_charge' => ConfigService::get('config', 'withdraw_service_charge'),
  160. ];
  161. return $config;
  162. }
  163. /**
  164. * @notes 设置提现
  165. * @param array $params
  166. * @return bool
  167. * @author cjhao
  168. * @date 2021/9/14 17:24
  169. */
  170. public function setWithdrawConfig(array $params):bool
  171. {
  172. //提现方式:1-钱包余额;2-微信零钱;3-银行卡;4-微信收款码;5-支付宝收款码
  173. ConfigService::set('config', 'withdraw_way',$params['withdraw_way']);
  174. //微信零钱接口:1-企业付款到零钱;2-商家转账到零钱
  175. ConfigService::set('config', 'transfer_way',$params['transfer_way']);
  176. //最低提现金额
  177. ConfigService::set('config', 'withdraw_min_money', $params['withdraw_min_money']);
  178. //最高提现金额
  179. ConfigService::set('config', 'withdraw_max_money', $params['withdraw_max_money']);
  180. //提现手续费
  181. ConfigService::set('config', 'withdraw_service_charge', $params['withdraw_service_charge']);
  182. return true;
  183. }
  184. /**
  185. * @notes 判断用户是否具有邀请下级资格
  186. * @param $userId
  187. * @return bool|mixed
  188. * @author Tab
  189. * @date 2021/8/4 15:29
  190. */
  191. public static function eligible($userId)
  192. {
  193. // 邀请下级资格
  194. $inviteWays = ConfigService::get('config', 'invite_ways', config('project.default_user.invite_ways'));
  195. // 全部用户可邀请
  196. if($inviteWays == UserEnum::INVITE_WAYS_ALL) {
  197. return true;
  198. }
  199. // 指定用户可邀请
  200. $inviteAppointUser = ConfigService::get('config', 'invite_appoint_user', config('project.default_user.invite_appoint_user'));
  201. foreach($inviteAppointUser as $value) {
  202. // 分销会员
  203. if($value == UserEnum::DISTRIBUTION_MEMBER) {
  204. $isDistribution = Distribution::where('user_id', $userId)->value('is_distribution');
  205. return $isDistribution;
  206. }
  207. // 股东会员
  208. if($value == UserEnum::SHAREHOLDER_MEMBER) {
  209. return false;
  210. }
  211. // 代理会员
  212. if($value == UserEnum::PROXY_MEMBER) {
  213. return false;
  214. }
  215. }
  216. return false;
  217. }
  218. }