|
@@ -83,6 +83,7 @@ class AuctionProductController
|
|
|
|
|
|
|
|
|
$product = AuctionProduct::where('id', $data['product_id'])->find();
|
|
|
+ if ($product['is_show'] == 0) return app('json')->fail('商品未挂售');
|
|
|
$product_ids = AuctionProduct::where('auction_id', $product['auction_id'])->column('id');
|
|
|
$auction = Auction::where('id', $product['auction_id'])->find();
|
|
|
$count = AuctionOrder::where('frequency',$auction['frequency'])->where('uid', $request->uid())->where('product_id', 'in', $product_ids)->count();
|
|
@@ -253,7 +254,7 @@ class AuctionProductController
|
|
|
if (empty($details)) return app('json')->fail('商品不存在');
|
|
|
$details['slider_image'] = is_string($details['slider_image']) ? json_decode($details['slider_image'], true) : [];
|
|
|
$details['description'] = !empty($details['description']) ? html_entity_decode($details['description'], ENT_COMPAT) : '';
|
|
|
- $details['user_nickname'] = User::where('uid', $details['auction_id'])->find()['nickname'];
|
|
|
+ $details['user_nickname'] = User::where('uid', $details['uid'])->find()['nickname'];
|
|
|
|
|
|
$auction = Auction::where('id', $details['auction_id'])->find();
|
|
|
$details['time'] = $auction['radd_time'].'-'.$auction['rend_time'];
|
|
@@ -300,7 +301,7 @@ class AuctionProductController
|
|
|
$product = AuctionProduct::where('id', $data['id'])->find();
|
|
|
if (!$product) return app('json')->fail('商品不存在');
|
|
|
|
|
|
- $data = $this->bs($data['id']);
|
|
|
+ $data = AuctionProduct::bs($data['id']);
|
|
|
return app('json')->successful($data);
|
|
|
|
|
|
}
|
|
@@ -325,7 +326,7 @@ class AuctionProductController
|
|
|
|
|
|
if ($product['is_show'] == 1) return app('json')->fail('商品已挂售');
|
|
|
|
|
|
- $datas = $this->bs($data['id']);
|
|
|
+ $datas = AuctionProduct::bs($data['id']);
|
|
|
if ($user['anticipate'] < $datas['anticipate']) return app('json')->fail('预约券不足');
|
|
|
|
|
|
$product['price'] = $product['hanging_price'];
|
|
@@ -358,51 +359,53 @@ class AuctionProductController
|
|
|
|
|
|
}
|
|
|
|
|
|
- public function bs($id)
|
|
|
+
|
|
|
+ * 取消挂售
|
|
|
+ * @param Request $request
|
|
|
+ * @return void
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function cancel(Request $request)
|
|
|
{
|
|
|
- $product = AuctionProduct::where('id',$id)->find();
|
|
|
- $auction = Auction::where('id', $product['auction_id'])->find();
|
|
|
- if (!$product) return app('json')->fail('商品不存在');
|
|
|
+ $data = UtilService::postMore([
|
|
|
+ ['id']
|
|
|
+ ]);
|
|
|
+ $productModel = new AuctionProduct();
|
|
|
|
|
|
- $data['time'] = explode(',', $auction['site']);
|
|
|
-
|
|
|
- $date = date('w', time());
|
|
|
- $data['gs_time'] = '';
|
|
|
- $bs = 0;
|
|
|
- if (in_array(1, $data['time'])){
|
|
|
- if ($date >= 1 and $date <= 2){
|
|
|
- $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Wednesday"));
|
|
|
- $bs = 2;
|
|
|
- }elseif ($date >= 3 and $date <= 4){
|
|
|
- $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Friday"));
|
|
|
- $bs = 2;
|
|
|
- }elseif ($date >= 5 or $date == 0){
|
|
|
- $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Monday"));
|
|
|
- $bs = 3;
|
|
|
- }
|
|
|
+ $details = $productModel->find($data['id']);
|
|
|
+ if (!$details) return app('json')->fail('商品不存在');
|
|
|
+ $order = AuctionOrder::where([['product_id', '=', $details['id']], ['status', '<', 3], ['status', '>', 0]])->find();
|
|
|
+ if ($order) return app('json')->fail('商品已出售,无法取消');
|
|
|
|
|
|
- }else if (in_array(2, $data['time'])){
|
|
|
- if ($date >= 2 and $date <= 3){
|
|
|
- $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Thursday"));
|
|
|
- $bs = 2;
|
|
|
- }elseif ($date >= 4 and $date <= 5){
|
|
|
- $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Saturday"));
|
|
|
- $bs = 2;
|
|
|
- }elseif ($date >= 6 or $date == 0 or $date == 1){
|
|
|
- $data['gs_time'] = date('Y-m-d H:i:s', strtotime("Tuesday"));
|
|
|
- $bs = 3;
|
|
|
- }
|
|
|
- }
|
|
|
+ $user = User::where('uid', $request->uid())->find();
|
|
|
+ $anticipate = round($details['price'] * $details['deduct']/100, 2);
|
|
|
+ $details['hanging_price'] = $details['price'];
|
|
|
+ $details['is_show'] = 0;
|
|
|
+ $user['anticipate'] += $anticipate;
|
|
|
|
|
|
- $hanging_price = round($product['hanging_price'] * $product['rise']/100, 2);
|
|
|
- $anticipate = round($product['hanging_price'] * $product['deduct']/100, 2);
|
|
|
|
|
|
- $data['hanging_price'] = (int)$product['hanging_price'] + ($hanging_price * $bs);
|
|
|
- $data['anticipate'] = $anticipate;
|
|
|
+ try {
|
|
|
+ Db::startTrans();
|
|
|
+ $details->save();
|
|
|
+ $user->save();
|
|
|
+ AuctionOrder::where('order_id', $details['order'])->save(['is_gs' => 0]);
|
|
|
+ UserBill::income('取消挂售退回预约券', $request->uid(), 'anticipate', 'add_anticipate', $anticipate, 0, $user['anticipate'], '取消挂售退回预约券');
|
|
|
+ AuctionTime::where([['uid', '=', $request->uid()], ['product_id', '=', $data['id']]])->delete();
|
|
|
+ Db::commit();
|
|
|
+
|
|
|
+ return app('json')->successful('取消挂售成功');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return app('json')->fail('取消挂售失败');
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- return $data;
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|