fail('场次不存在'); if (!$data['s_id']) return app('json')->fail('数据传入错误'); $section = AuctionSection::where('id', $data['s_id'])->find(); $price = (float)SystemConfigService::get('product_hanging_price'); $pro = AuctionProduct::where('hanging_price', '>=', $section['low'])->where('hanging_price','<=','high')->select()->toArray(); if (empty($pro) and ($price < $section['low'] or $price > $section['high'])) { return app('json')->fail('该区间没有商品'); } if (AuctionOrder::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']], ['uid', '=', $request->uid()]])->count() >= 1) return app('json')->fail('当前场次已购买商品'); if ($request->user()['is_real'] < 1){ $orderCount = AuctionOrder::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']]])->count(); // 查找出当前场次已派单多少 $pd = AuctionBooking::where([['auction_id', '=', $data['id']], ['frequency', '=', $auction['frequency']]])->count(); // 当前预约人数 $pds = ceil($pd * ($auction['dispatch']/100)); if ($orderCount >= $pds) return app('json')->fail('商品已买完'); } $show = AuctionProduct::random($data['id'], $request->uid(),$section); if ($show == 'false') return app('json')->fail('购买失败'); return app('json')->successful($show); } /** * 用户商品 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function user_product(Request $request) { $data = UtilService::getMore([ [['page', 'd'], 0], [['limit', 'd'], 0], ]); return app('json')->successful(AuctionProduct::user_product( $data,$request->uid())); } /** * 用户订单 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function user_auction_order(Request $request) { $data = UtilService::getMore([ [['type', 'd'], 0], [['page', 'd'], 0], [['limit', 'd'], 0], ['order_id'] ]); return app('json')->successful(AuctionOrder::userOrder($data,$request->uid())); } /** * 卖家显示订单 * @param Request $request * @return void */ public function seller(Request $request) { $data = UtilService::getMore([ ['type', 0], [['page', 'd'], 0], [['limit', 'd'], 0], ['order_id'] ]); return app('json')->successful(AuctionOrder::seller_list($data,$request->uid())); } /** * 支付订单 * @param Request $request * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function zfpay(Request $request) { $data = UtilService::postMore([ ['order_id'], ['pas'] ]); if (empty($data['pas'])) return app('json')->fail('请填写支付密码'); if ($request->user()['payment_pas'] != md5($data['pas'].'sxg')) return app('json')->fail('支付密码不正确'); $model = new User(); $order = AuctionOrder::where('order_id', $data['order_id'])->find(); if (!$order) return app('json')->fail('订单不存在'); if ($order['status'] == 0 or $order['status'] == 2) return app('json')->fail('订单状态不对'); $user = $model->where('uid', $request->uid())->find(); if ($user['now_money'] < $order['actual_price']) return app('json')->fail('余额不足'); try { Db::startTrans(); AuctionOrder::pay($order, $request->uid()); Db::commit(); return app('json')->successful('支付成功'); } catch (\Exception $e) { Db::rollback(); return app('json')->fail('支付失败'); } } /** * 挂售详情 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function gsxq(Request $request) { $data = UtilService::postMore([ ['id'] ]); $product = AuctionProduct::where('id', $data['id'])->find(); $data['aid_val'] = round($product['hanging_price'] * 0.0485, 2); // 需要的广告值 $data['hanging_price'] = round($product['hanging_price'] + $product['hanging_price'] * 0.06, 2); // 第二天溢价 return app('json')->successful($data); } /** * 挂售商品 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function hanging_sale(Request $request) { $data = UtilService::postMore([ ['id'], ['pas'] ]); if (empty($data['pas'])) return app('json')->fail('请填写支付密码'); if ($request->user()['payment_pas'] != md5($data['pas'].'sxg')) return app('json')->fail('支付密码不正确'); $product = AuctionProduct::where('id', $data['id'])->find(); if ($product['is_show'] == 1) return app('json')->fail('商品已挂售'); $user = User::where('uid', $request->uid())->find(); if (!$product) return app('json')->fail('商品不存在'); $aid_val = round($product['hanging_price'] * 0.0485,2); // 需要的广告值 $hanging_price = round($product['hanging_price'] + $product['hanging_price'] * 0.06, 2); // 第二天溢价 if ($user['aid_val'] < $aid_val) return app('json')->fail('挂售需要广告值不足'); $auction = Auction::where([['id', '=', $product['auction_id']]])->find(); $bk = AuctionBooking::where([['uid', '=', $request->uid()], ['auction_id', '=', $auction['id']], ['frequency', '=', $auction['frequency']], ['status', '=', 1]])->find(); if ($bk){ $bk['status'] = 0; //解冻广告值 $user['aid_val'] += $bk['advert']; // 退回用户广告值 $bk->save(); UserBill::income('广告值退回', $request->uid(), 'aid_val', 'add_aid_val', $bk['advert'], $user['spread_uid'], $user['aid_val'], '寄售商品成功退回广告值'); } $product['hanging_price'] = $hanging_price; $product['is_show'] = 1; $product['gs_time'] = time(); $user['aid_val'] -= $aid_val; try { User::beginTrans(); $product->save(); $user->save(); UserBill::expend('挂售扣除广告值', $user['uid'], 'aid_val', 'sub_aid_val', $aid_val, $user['spread_uid'], $user['aid_val'], '挂售商品扣除广告值'); User::commitTrans(); return app('json')->successful('挂售成功'); } catch (\Exception $e) { User::rollbackTrans(); return app('json')->fail($e->getMessage()); } } /** * 商品详情 * @param Request $request * @return mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * */ public function product(Request $request) { $data = UtilService::getMore([ ['id'] ]); $product = AuctionProduct::where('id', $data['id'])->find(); if (!$product) return app('json')->fail('没有此商品'); $product['slider_image'] = is_string($product['slider_image']) ? json_decode($product['slider_image'], true) : []; $product['description'] = !empty($product['description']) ? html_entity_decode($product['description'], ENT_COMPAT) : ''; $product = $product->toArray(); return app('json')->successful($product); } }