Manage.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Code\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. /**
  7. * 显示用户信息
  8. *
  9. * @return mixed
  10. */
  11. public function showUserInfo($uid, $ldate = false)
  12. {
  13. if ($uid) {
  14. $user = Dever::load('passport/user.info', $uid);
  15. if ($user) {
  16. $table = array();
  17. $table['用户名'] = $user['username'];
  18. $table['手机号'] = $user['mobile'];
  19. $table['领取时间'] = date('Y-m-d H:i:s', $ldate);
  20. return Dever::table($table);
  21. }
  22. } else {
  23. return '';
  24. }
  25. }
  26. /**
  27. * 创建兑换码
  28. *
  29. * @return mixed
  30. */
  31. public function create($id, $name, $param)
  32. {
  33. $code = Dever::param('num', $param);
  34. $product_id = Dever::param('product_id', $param);
  35. //$total = Dever::db('code/info')->total(array('product_id' => $product_id, 'type' => 1));
  36. $total = 0;
  37. if ($code > 0 && $code > $total) {
  38. $num = $code - $total;
  39. for ($i = 0; $i < $num; $i++) {
  40. $this->createCode($product_id);
  41. }
  42. }
  43. }
  44. private function createCode($product_id)
  45. {
  46. $code = Dever::rand(8, 0);
  47. $data['product_id'] = $product_id;
  48. $data['code'] = $code;
  49. $total = Dever::db('code/info')->total($data);
  50. if ($total > 0) {
  51. return $this->createCode($product_id, $id);
  52. }
  53. $data['type'] = 1;
  54. Dever::db('code/info')->insert($data);
  55. return $code;
  56. }
  57. }