AgentCode.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\model;
  3. use think\Model;
  4. class AgentCode extends Model
  5. {
  6. protected $connection = 'mysql';
  7. protected $pk = 'id';
  8. protected $name = 'agent_code';
  9. public static function getuid($agent_code)
  10. {
  11. $data = AgentCode::where(['agent_code' => $agent_code])->find();
  12. if (!empty($data)) {
  13. $data = $data->toArray();
  14. if (!empty($data['status'] == 1)) {
  15. return $data['uid'];
  16. }
  17. }
  18. }
  19. public static function getagent_code($uid)
  20. {
  21. $data = AgentCode::where(['uid' => $uid])->find();
  22. if (!empty($data)) {
  23. $data = $data->toArray();
  24. if (!empty($data['status'] == 1)) {
  25. return $data['agent_code'];
  26. } else {
  27. return '审核中';
  28. }
  29. } else {
  30. $agent_code = str_pad($uid, 6, "0", STR_PAD_LEFT);
  31. return self::upcode($uid, $agent_code, 1);
  32. }
  33. }
  34. public static function upcode($uid, $agent_code, $status)
  35. {
  36. $data = AgentCode::where(['agent_code' => $agent_code])->find();
  37. if (!empty($data)) {
  38. if ($status == 0) {
  39. return 0;
  40. } else {
  41. $agent_code = rand(1, 99) . time();
  42. }
  43. }
  44. $Codedata = AgentCode::where(['uid' => $uid])->find();
  45. if (empty($Codedata)) {
  46. self::create(['uid' => $uid, 'agent_code' => $agent_code, 'status' => $status]);
  47. } else {
  48. self::where(['uid' => $uid])->update(['agent_code' => $agent_code, 'status' => $status]);
  49. }
  50. if ($status != 1) {
  51. $agent_code = '审核中';
  52. }
  53. return $agent_code;
  54. }
  55. }