|
@@ -0,0 +1,64 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Code\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+
|
|
|
+class Manage
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 显示用户信息
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function showUserInfo($uid, $ldate = false)
|
|
|
+ {
|
|
|
+ if ($uid) {
|
|
|
+ $user = Dever::load('passport/user.info', $uid);
|
|
|
+ if ($user) {
|
|
|
+ $table = array();
|
|
|
+ $table['用户名'] = $user['username'];
|
|
|
+ $table['手机号'] = $user['mobile'];
|
|
|
+ $table['领取时间'] = date('Y-m-d H:i:s', $ldate);
|
|
|
+ return Dever::table($table);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建兑换码
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function create($id, $name, $param)
|
|
|
+ {
|
|
|
+ $code = Dever::param('num', $param);
|
|
|
+ $product_id = Dever::param('product_id', $param);
|
|
|
+
|
|
|
+ //$total = Dever::db('code/info')->total(array('product_id' => $product_id, 'type' => 1));
|
|
|
+ $total = 0;
|
|
|
+ if ($code > 0 && $code > $total) {
|
|
|
+ $num = $code - $total;
|
|
|
+
|
|
|
+ for ($i = 0; $i < $num; $i++) {
|
|
|
+ $this->createCode($product_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function createCode($product_id)
|
|
|
+ {
|
|
|
+ $code = Dever::rand(8, 0);
|
|
|
+ $data['product_id'] = $product_id;
|
|
|
+ $data['code'] = $code;
|
|
|
+ $total = Dever::db('code/info')->total($data);
|
|
|
+ if ($total > 0) {
|
|
|
+ return $this->createCode($product_id, $id);
|
|
|
+ }
|
|
|
+ $data['type'] = 1;
|
|
|
+ Dever::db('code/info')->insert($data);
|
|
|
+ return $code;
|
|
|
+ }
|
|
|
+}
|