|
@@ -71,28 +71,47 @@ class AuctionController
|
|
|
return app('json')->fail('预约时间已过');
|
|
return app('json')->fail('预约时间已过');
|
|
|
}
|
|
}
|
|
|
if (AuctionBooking::where([['uid', '=', $request->uid()], ['auction_id' , '=', $auction['id']], ['frequency', '=', $auction['frequency']]])->find()){
|
|
if (AuctionBooking::where([['uid', '=', $request->uid()], ['auction_id' , '=', $auction['id']], ['frequency', '=', $auction['frequency']]])->find()){
|
|
|
- return app('json')->fail('当前场馆已预约');
|
|
|
|
|
|
|
+ return app('json')->fail('当前场次已预约');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$userModel = new User();
|
|
$userModel = new User();
|
|
|
$user = $userModel->find($request->uid());
|
|
$user = $userModel->find($request->uid());
|
|
|
if ($user['is_auth'] != 2) return app('json')->fail('未实名认证');
|
|
if ($user['is_auth'] != 2) return app('json')->fail('未实名认证');
|
|
|
|
|
+ if ($user['shop_integral'] <= 0) return app('json')->fail('账户内没有购物券,无法进行预约');
|
|
|
if ($user['anticipate'] < $auction['anticipate']) return app('json')->fail('广告值不足');
|
|
if ($user['anticipate'] < $auction['anticipate']) return app('json')->fail('广告值不足');
|
|
|
$user['anticipate'] = $user['anticipate'] - $auction['anticipate'];// 扣除广告值
|
|
$user['anticipate'] = $user['anticipate'] - $auction['anticipate'];// 扣除广告值
|
|
|
|
|
|
|
|
User::rollbackTrans();
|
|
User::rollbackTrans();
|
|
|
- $res = $user->save();
|
|
|
|
|
|
|
+ $user->save();
|
|
|
|
|
+ $redis = new \Redis();
|
|
|
|
|
+ $redis->connect('127.0.0.1','6379'); // redis 缓存
|
|
|
|
|
+ $product = $redis->lPop($auction['id']);
|
|
|
|
|
+ if (!$product){
|
|
|
|
|
+ return app('json')->fail('商品已预约认购完,请等待下次');
|
|
|
|
|
+ }
|
|
|
|
|
+ $product = json_decode($product);
|
|
|
|
|
+ $res = AuctionOrder::create([
|
|
|
|
|
+ 'uid' => $request->uid(),
|
|
|
|
|
+ 'collection_id' => $product->uid,// 商品拥有有人
|
|
|
|
|
+ 'order_id' => getNewOrderId(),
|
|
|
|
|
+ 'name' => $product->name,
|
|
|
|
|
+ 'product_id' => $product->id,
|
|
|
|
|
+ 'auction_id' => $auction['id'],
|
|
|
|
|
+ 'image'=> $product->image,
|
|
|
|
|
+ 'price' => $product->hanging_price,
|
|
|
|
|
+ 'frequency' => $auction['frequency']
|
|
|
|
|
+ ]);
|
|
|
|
|
|
|
|
if ($res){
|
|
if ($res){
|
|
|
AuctionBooking::booking($user['uid'], $auction);
|
|
AuctionBooking::booking($user['uid'], $auction);
|
|
|
- UserBill::expend('预约场馆', $user['uid'], 'anticipate','reduce_anticipate', $auction['anticipate'], 0, $user['anticipate'], '预约扣除广告值'); // 写入记录
|
|
|
|
|
|
|
+ UserBill::expend('预约认购', $user['uid'], 'anticipate','reduce_anticipate', $auction['anticipate'], 0, $user['anticipate'], '预约扣除广告值'); // 写入记录
|
|
|
|
|
|
|
|
User::commitTrans();
|
|
User::commitTrans();
|
|
|
- return app('json')->successful('预约成功');
|
|
|
|
|
|
|
+ return app('json')->successful('认购成功');
|
|
|
}else{
|
|
}else{
|
|
|
|
|
|
|
|
User::rollbackTrans();
|
|
User::rollbackTrans();
|
|
|
- return app('json')->fail('预约失败');
|
|
|
|
|
|
|
+ return app('json')->fail('认购失败');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -176,7 +195,8 @@ class AuctionController
|
|
|
$data = UtilService::getMore([
|
|
$data = UtilService::getMore([
|
|
|
['uid'],
|
|
['uid'],
|
|
|
['anticipate'],
|
|
['anticipate'],
|
|
|
- ['payment']
|
|
|
|
|
|
|
+ ['payment'],
|
|
|
|
|
+ ['type']
|
|
|
], $request);
|
|
], $request);
|
|
|
if (!$data['uid'] or !$data['anticipate']) return app('json')->fail('数据传入错误');
|
|
if (!$data['uid'] or !$data['anticipate']) return app('json')->fail('数据传入错误');
|
|
|
if (!$data['payment']) return app('json')->fail('请填写支付密码');
|
|
if (!$data['payment']) return app('json')->fail('请填写支付密码');
|
|
@@ -187,14 +207,50 @@ class AuctionController
|
|
|
if ($user['payment'] != md5($data['payment'])) return app('json')->fail('支付密码错误');
|
|
if ($user['payment'] != md5($data['payment'])) return app('json')->fail('支付密码错误');
|
|
|
if (!in_array($data['uid'],$uid)) return app('json')->fail('该用户不是你下级');
|
|
if (!in_array($data['uid'],$uid)) return app('json')->fail('该用户不是你下级');
|
|
|
if ($data['anticipate'] < 10) return app('json')->fail('最少转账10');
|
|
if ($data['anticipate'] < 10) return app('json')->fail('最少转账10');
|
|
|
- if ($user['anticipate'] < $data['anticipate']) return app('json')->fail('广告值不够');
|
|
|
|
|
- $me = User::find($data['uid']);
|
|
|
|
|
- $user['anticipate'] = $user['anticipate'] - $data['anticipate'];// 扣除广告值
|
|
|
|
|
- $me['anticipate'] = $me['anticipate'] + $data['anticipate'];// 增加广告值
|
|
|
|
|
|
|
+ if ($data['type'] == 1){
|
|
|
|
|
+ if ($user['anticipate'] < $data['anticipate']) return app('json')->fail('广告值不足');
|
|
|
|
|
+ $me = User::find($data['uid']);
|
|
|
|
|
+ $user['anticipate'] -= $data['anticipate'];// 扣除广告值
|
|
|
|
|
+ $me['anticipate'] += $data['anticipate'];// 增加广告值
|
|
|
|
|
+ $title = ['广告值减少', '广告值增加'];
|
|
|
|
|
+ $category = 'anticipate';
|
|
|
|
|
+ $type = ['zz_anticipate', 'js_anticipate'];
|
|
|
|
|
+ $mark = '广告值';
|
|
|
|
|
+ }elseif ($data['type'] == 2){
|
|
|
|
|
+ //趣豆
|
|
|
|
|
+ if ($user['integral'] < $data['anticipate']) return app('json')->fail('趣豆不足');
|
|
|
|
|
+ $me = User::find($data['uid']);
|
|
|
|
|
+ $user['integral'] -= $data['anticipate'];// 扣除趣豆
|
|
|
|
|
+ $me['integral'] += $data['anticipate'];// 增加趣豆
|
|
|
|
|
+ $title = ['趣豆减少', '趣豆增加'];
|
|
|
|
|
+ $category = 'integral';
|
|
|
|
|
+ $type = ['zz_integral', 'js_integral'];
|
|
|
|
|
+ $mark = '趣豆';
|
|
|
|
|
+ }elseif ($data['type'] == 3){
|
|
|
|
|
+ //金豆
|
|
|
|
|
+ if ($user['golden_bean'] < $data['anticipate']) return app('json')->fail('金豆不足');
|
|
|
|
|
+ $me = User::find($data['uid']);
|
|
|
|
|
+ $user['golden_bean'] -= $data['anticipate'];// 扣除金豆
|
|
|
|
|
+ $me['golden_bean'] += $data['anticipate'];// 增加金豆
|
|
|
|
|
+ $title = ['金豆减少', '金豆增加'];
|
|
|
|
|
+ $category = 'golden_bean';
|
|
|
|
|
+ $type = ['zz_golden_bean', 'js_golden_bean'];
|
|
|
|
|
+ $mark = '金豆';
|
|
|
|
|
+ }elseif ($data['type'] == 4){
|
|
|
|
|
+ //购物券
|
|
|
|
|
+ if ($user['shop_integral'] < $data['anticipate']) return app('json')->fail('金豆不足');
|
|
|
|
|
+ $me = User::find($data['uid']);
|
|
|
|
|
+ $user['shop_integral'] -= $data['anticipate'];// 扣除购物券
|
|
|
|
|
+ $me['shop_integral'] += $data['anticipate'];// 增加购物券
|
|
|
|
|
+ $title = ['购物券减少', '购物券增加'];
|
|
|
|
|
+ $category = 'shop_integral';
|
|
|
|
|
+ $type = ['zz_shop_integral', 'js_shop_integral'];
|
|
|
|
|
+ $mark = '购物券';
|
|
|
|
|
+ }
|
|
|
try {
|
|
try {
|
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
|
- UserBill::expend('广告值减少',$user['uid'], 'anticipate', 'reduce_anticipate', $data['anticipate'], 0, $user['anticipate'], '转账给('.$me['nickname'].'-'.$me['uid'].')'.$data['anticipate'].'广告值');
|
|
|
|
|
- UserBill::income('广告值增加',$me['uid'], 'anticipate', 'add_anticipate', $data['anticipate'], 0, $me['anticipate'], '接收('.$user['nickname'].'-'.$user['uid'].')的'.$data['anticipate'].'广告值');
|
|
|
|
|
|
|
+ UserBill::expend($title[0],$user['uid'], $category, $type[0], $data['anticipate'], 0, $user['anticipate'], '转账给('.$me['nickname'].'-'.$me['uid'].')'.$data['anticipate'].$mark);
|
|
|
|
|
+ UserBill::income($title[1],$me['uid'], $category, $type[1], $data['anticipate'], 0, $me['anticipate'], '接收('.$user['nickname'].'-'.$user['uid'].')的'.$data['anticipate'].$mark);
|
|
|
$user->save();
|
|
$user->save();
|
|
|
$me->save();
|
|
$me->save();
|
|
|
|
|
|
|
@@ -458,6 +514,51 @@ class AuctionController
|
|
|
return app('json')->success($datas);// 失败
|
|
return app('json')->success($datas);// 失败
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 金豆兑换
|
|
|
|
|
+ * @param Request $request
|
|
|
|
|
+ * @return mixed
|
|
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
|
|
+ */
|
|
|
|
|
+ public function exchange_golden(Request $request)
|
|
|
|
|
+ {
|
|
|
|
|
+ $data = UtilService::postMore([
|
|
|
|
|
+ ['price'],
|
|
|
|
|
+ ['type']
|
|
|
|
|
+ ], $request);
|
|
|
|
|
+ if (empty($data['price'])) return app('json')->fail('传入兑换数量');
|
|
|
|
|
+ if (empty($data['type'])) return app('json')->fail('传入兑换类型');
|
|
|
|
|
+
|
|
|
|
|
+ $user = User::where('uid', $request->uid())->find();
|
|
|
|
|
+ if ($data['type'] == 1){
|
|
|
|
|
+ // 金豆兑换广告值
|
|
|
|
|
+ $proportion = SystemConfigService::get('anticipate');
|
|
|
|
|
+ $price = $data['price'] * $proportion;
|
|
|
|
|
+ if ($user['golden_bean'] < $price) return app('json')->fail('金豆不足');
|
|
|
|
|
+ $user['golden_bean'] -= $price;
|
|
|
|
|
+ $user['anticipate'] += $data['price'];
|
|
|
|
|
+ $user->save();
|
|
|
|
|
+ UserBill::expend('金豆兑换广告值', $request->uid(), 'golden_bean', 'dh_golden_bean', $price, '', $user['golden_bean'], '金豆兑换'.$data['price'].'广告值');
|
|
|
|
|
+ UserBill::income('广告值兑换', $request->uid(), 'anticipate', 'dh_anticipate', $data['price'], '', $user['anticipate'], '金豆兑换'.$data['price'].'广告值');
|
|
|
|
|
+ }elseif ($data['type'] == 2) {
|
|
|
|
|
+ // 金豆兑换趣豆
|
|
|
|
|
+ $proportion = SystemConfigService::get('integral');
|
|
|
|
|
+ $price = $data['price'] * $proportion;
|
|
|
|
|
+ if ($user['golden_bean'] < $price) return app('json')->fail('金豆不足');
|
|
|
|
|
+ $user['golden_bean'] -= $price;
|
|
|
|
|
+ $user['integral'] += $data['price'];
|
|
|
|
|
+ $user->save();
|
|
|
|
|
+ UserBill::expend('金豆兑换趣豆', $request->uid(), 'golden_bean', 'dh_golden_bean', $price, '', $user['golden_bean'], '金豆兑换'.$data['price'].'趣豆');
|
|
|
|
|
+ UserBill::income('趣豆兑换', $request->uid(), 'integral', 'dh_integral', $data['price'], '', $user['integral'], '金豆兑换'.$data['price'].'趣豆');
|
|
|
|
|
+ }else{
|
|
|
|
|
+ return app('json')->fail('兑换类型不存在');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return app('json')->success('兑换成功');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|