Manage.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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($create_uid, $uid, $ldate = false, $type = 1)
  29. {
  30. $table = array();
  31. if ($create_uid && $create_uid > 0) {
  32. $user = Dever::load('passport/user-one', $create_uid);
  33. $table['创建人'] = $user['username'] . '('.$create_uid.')';
  34. }
  35. if ($type == 3 && $uid && $uid > 0) {
  36. $user = Dever::load('passport/user-one', $uid);
  37. if ($user) {
  38. $table['领取人'] = $user['username'] . '('.$uid.')';
  39. $table['手机号'] = $user['mobile'];
  40. $table['领取时间'] = date('Y-m-d H:i:s', $ldate);
  41. }
  42. }
  43. return Dever::table($table);
  44. }
  45. /**
  46. * 创建兑换码
  47. *
  48. * @return mixed
  49. */
  50. public function create($id, $name, $param)
  51. {
  52. $code = Dever::param('num', $param);
  53. $score = Dever::param('score', $param);
  54. $product_num = Dever::param('product_num', $param);
  55. $product = Dever::param('product', $param);
  56. //$product_id = Dever::param('product_id', $param);
  57. $seller_id = Dever::param('seller_id', $param);
  58. $cate_id = $product_id = 0;
  59. if ($product && isset($product[0])) {
  60. $cate_id = $product[0];
  61. if (isset($product[1])) {
  62. $product_id = $product[1];
  63. }
  64. $product = implode(',', $product);
  65. }
  66. if ($cate_id <= 0){
  67. Dever::alert('生成失败,请选择分类');
  68. }
  69. //$total = Dever::db('code/info')->total(array('product_id' => $product_id, 'type' => 1));
  70. $total = 0;
  71. $core = Dever::load('code/lib/core');
  72. if ($code > 0 && $code > $total) {
  73. $num = $code - $total;
  74. $core->createCode($product, $cate_id, $product_id, $seller_id, $product_num, -1, false, $score, 1, $num);
  75. }
  76. }
  77. /**
  78. * 作废
  79. *
  80. * @return mixed
  81. */
  82. public function drop_api($id, $journal_id, $code)
  83. {
  84. if (!$code && $journal_id > 0) {
  85. Dever::setInput('set_product_id', $journal_id);
  86. }
  87. $update['where_id'] = $id;
  88. $update['type'] = 4;
  89. Dever::db('code/info')->update($update);
  90. return 'ok';
  91. }
  92. public function recovery_api($id, $journal_id, $code)
  93. {
  94. if (!$code && $journal_id > 0) {
  95. Dever::setInput('set_product_id', $journal_id);
  96. }
  97. $update['where_id'] = $id;
  98. $update['type'] = 1;
  99. Dever::db('code/info')->update($update);
  100. return 'ok';
  101. }
  102. }