CpUserService.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Modules\CpUser\Services;
  3. use App\Modules\CpUser\Models\CpUser;
  4. class CpUserService
  5. {
  6. /**
  7. * 得到用户
  8. *
  9. */
  10. public static function getCpUser($username) {
  11. return CpUser::getCpUser($username);
  12. }
  13. /**
  14. * 得到用户by id
  15. */
  16. public static function getCpUserById($id) {
  17. return CpUser::getCpUserById($id);
  18. }
  19. static function createCp($username){
  20. try{
  21. $password = $username.'123456';
  22. $pass = md5($password."^-^zhuishuyun^_^");
  23. return CpUser::create([
  24. 'username'=>$username,
  25. 'password'=>$pass,
  26. 'is_enabled'=>1,
  27. 'is_show_total_amount'=>0
  28. ]);
  29. }catch (\Exception $e){
  30. }
  31. return false;
  32. }
  33. static function getAllCpUser($param,$is_all=false){
  34. if($is_all){
  35. return CpUser::all();
  36. }
  37. $where = [];
  38. if(isset($param['cp']) && !empty(($param['cp']))){
  39. $where[] = ['username','like','%'.trim($param['cp']).'%'];
  40. }
  41. return CpUser::where($where)->orderBy('id','desc')->paginate(20);
  42. }
  43. }