|
@@ -1469,4 +1469,107 @@ class User extends Api
|
|
|
|
|
|
$this->success('我的优惠券', $list);
|
|
|
}
|
|
|
+
|
|
|
+ //充值列表
|
|
|
+ public function rechargelist() {
|
|
|
+ $list = Db::name('recharge')->field('id, title, price, couponnum')->order('weigh desc')->select();
|
|
|
+
|
|
|
+ $this->success('充值列表', $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //资金明细
|
|
|
+ public function usermoneylog() {
|
|
|
+ $list = Db::name('user_money_log')->field('id, money, memo, createtime')
|
|
|
+ ->where(['user_id' => $this->auth->id])
|
|
|
+ ->page($this->page, $this->pagenum)
|
|
|
+ ->order('id desc')->select();
|
|
|
+
|
|
|
+ foreach ($list as &$v) {
|
|
|
+ $v['createtime'] = date('Y-m-d H:i:s', $v['createtime']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('资金明细', $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //充值
|
|
|
+ public function recharge() {
|
|
|
+ //检查是否已经开通体验会员
|
|
|
+ if ($this->auth->experiencetime >= time()) {
|
|
|
+ $this->error('您已开通体验会员,不能重复开通');
|
|
|
+ }
|
|
|
+
|
|
|
+ $id = input('id', 0, 'intval');
|
|
|
+ if (!$id) {
|
|
|
+ $this->error('参数缺失');
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = Db::name('vip')->where(['id' => $id])->find();
|
|
|
+ if (!$info) {
|
|
|
+ $this->error('会员不存在');
|
|
|
+ }
|
|
|
+ if ($info['status'] != 1) {
|
|
|
+ $this->error('体验会员已下架');
|
|
|
+ }
|
|
|
+ if ($info['price'] <= 0) {
|
|
|
+ $this->error('会员价格异常');
|
|
|
+ }
|
|
|
+ //体验会员等级必须大于成长值会员
|
|
|
+ if ($id <= $this->auth->maxlevel) {
|
|
|
+ $this->error('请开通更高等级体验会员');
|
|
|
+ }
|
|
|
+ //判断余额
|
|
|
+ if ($this->auth->money < $info['price']) {
|
|
|
+ $this->success('您的余额不足,请先去充值', ['code' => 2]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data['user_id'] = $this->auth->id;
|
|
|
+ $data['vip_id'] = $id;
|
|
|
+ $data['title'] = $info['title'];
|
|
|
+ $data['level'] = $info['level'];
|
|
|
+ $data['growthvalue'] = $info['growthvalue'];
|
|
|
+ $data['free'] = $info['free'];
|
|
|
+ $data['price'] = $info['price'];
|
|
|
+ $data['endtime'] = time() + $info['day'] * 86400;
|
|
|
+ $data['vipdiscount'] = $info['vipdiscount'];
|
|
|
+ $data['birthdiscount'] = $info['birthdiscount'];
|
|
|
+ $data['manypeople'] = $info['manypeople'];
|
|
|
+ $data['createtime'] = time();
|
|
|
+
|
|
|
+ //开启事务
|
|
|
+ Db::startTrans();
|
|
|
+
|
|
|
+ //添加开通记录
|
|
|
+ $rs = Db::name('vip_log')->insertGetId($data);
|
|
|
+ if (!$rs) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('开通失败');
|
|
|
+ }
|
|
|
+ //扣除余额
|
|
|
+ $result = create_log(-$info['price'], '开通会员', $this->auth->id, 4);
|
|
|
+ if ($result != 1) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('资金异常,请联系管理员');
|
|
|
+ }
|
|
|
+ //成长值会员信息
|
|
|
+ $growth_vip_info = Db::name('vip')->find($this->auth->growthlevel);
|
|
|
+ //修改用户表信息
|
|
|
+ $user_data['experiencelevel'] = $id;
|
|
|
+ $user_data['experiencetime'] = $data['endtime'];
|
|
|
+ $user_data['maxlevel'] = $id;
|
|
|
+ $freenumber = $this->auth->freenumber + $info['free'] - $growth_vip_info['free'];
|
|
|
+ $user_data['freenumber'] = $freenumber > 0 ? $freenumber : 0;
|
|
|
+
|
|
|
+ $rt = Db::name('user')->where([
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'experiencelevel' => $this->auth->experiencelevel,
|
|
|
+ 'maxlevel' => $this->auth->maxlevel,
|
|
|
+ 'freenumber' => $this->auth->freenumber])->setField($user_data);
|
|
|
+ if (!$rt) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('开通失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('开通成功');
|
|
|
+ }
|
|
|
}
|