Manage.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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::db('passport/user')->one($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, $data)
  32. {
  33. $code = Dever::param('code', $data);
  34. $type = Dever::param('type', $data);
  35. $product_id = Dever::param('product_id', $data);
  36. if (!$product_id) {
  37. $product_id = $id;
  38. }
  39. if (!in_array(2, $type)) {
  40. return;
  41. }
  42. $total = Dever::db('code/info')->total(array('product_id' => $product_id,'product_price_id' => $id, 'type' => 1));
  43. if ($code > 0 && $code > $total) {
  44. $num = $code - $total;
  45. for ($i = 0; $i < $num; $i++) {
  46. $this->createCode($product_id, $id);
  47. }
  48. }
  49. }
  50. private function createCode($product_id, $id)
  51. {
  52. $code = Dever::rand(8, 0);
  53. $data['product_id'] = $product_id;
  54. $data['product_price_id'] = $id;
  55. $data['code'] = $code;
  56. $total = Dever::db('code/info')->total($data);
  57. if ($total > 0) {
  58. return $this->createCode($product_id, $id);
  59. }
  60. $data['type'] = 1;
  61. Dever::db('code/info')->insert($data);
  62. return $code;
  63. }
  64. }