Manage.php 1.4 KB

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