Manage.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. namespace Code\Lib;
  3. use Dever;
  4. class Manage
  5. {
  6. public function showCode($id)
  7. {
  8. $info = Dever::db('code/info')->one($id);
  9. if ($info['code']) {
  10. return $info['code'];
  11. }
  12. /*
  13. if ($info['create_uid'] > 0) {
  14. return Dever::load('code/lib/core')->view($info['id'], true);
  15. return '用户创建';
  16. }
  17. */
  18. if ($info['product_id'] > 0) {
  19. return Dever::load('code/lib/core')->view($info['id'], true);
  20. }
  21. return 'T' . $id;
  22. }
  23. /**
  24. * 显示用户信息
  25. *
  26. * @return mixed
  27. */
  28. public function showUserInfo($teacher_id, $ldate = false, $type = 1)
  29. {
  30. $table = array();
  31. if ($type == 3 && $teacher_id && $teacher_id > 0) {
  32. $user = Dever::load('teacher/info-one', $uid);
  33. if ($user) {
  34. $table['讲师名称'] = $user['name'] . '('.$uid.')';
  35. $table['手机号'] = $user['mobile'];
  36. $table['使用时间'] = date('Y-m-d H:i:s', $ldate);
  37. }
  38. }
  39. return Dever::table($table);
  40. }
  41. /**
  42. * 创建兑换码
  43. *
  44. * @return mixed
  45. */
  46. public function create($id, $name, $param)
  47. {
  48. $code = Dever::param('num', $param);
  49. $product = Dever::param('product', $param);
  50. $cate_id = $product_id = 0;
  51. if ($product && isset($product[0])) {
  52. $cate_id = $product[0];
  53. if (isset($product[1])) {
  54. $product_id = $product[1];
  55. }
  56. $product = implode(',', $product);
  57. }
  58. if ($cate_id <= 0){
  59. Dever::alert('生成失败,请选择分类');
  60. }
  61. $total = 0;
  62. $core = Dever::load('code/lib/core');
  63. if ($code > 0 && $code > $total) {
  64. $num = $code - $total;
  65. $core->createCode($product, $cate_id, $product_id, 1, $num);
  66. }
  67. }
  68. /**
  69. * 作废
  70. *
  71. * @return mixed
  72. */
  73. public function drop_api($id, $journal_id, $code)
  74. {
  75. if (!$code && $journal_id > 0) {
  76. Dever::setInput('set_product_id', $journal_id);
  77. }
  78. $update['where_id'] = $id;
  79. $update['type'] = 4;
  80. Dever::db('code/info')->update($update);
  81. return 'ok';
  82. }
  83. public function recovery_api($id, $journal_id, $code)
  84. {
  85. if (!$code && $journal_id > 0) {
  86. Dever::setInput('set_product_id', $journal_id);
  87. }
  88. $update['where_id'] = $id;
  89. $update['type'] = 1;
  90. Dever::db('code/info')->update($update);
  91. return 'ok';
  92. }
  93. }