exists() ) { throw new \ApiException("你被对方拒绝了", 101); } if ( ConfessModel::where([ ['uid', $uid], ['state', 1], ['partner_id', $partner_id] ])->count() > 2 ) { throw new \ApiException('一张卡片只能表白3次', 101); } if ($send_msg == 1) { $fee += 10; } if ($receive_msg == 1) { $fee += 10; } return $fee; } /** * 发起表白 * @param Request $request * @return array * @throws \ApiException * @throws \Tymon\JWTAuth\Exceptions\JWTException */ public function store(Request $request) { $this->validate($request, [ 'partner_id' => 'required', 'nickname' => 'required', 'media_id' => 'required', 'content' => 'required', 'send_self' => 'required', 'send_msg' => 'required', 'receive_msg' => 'required' ]); $partner_id = $request->input('partner_id'); $uid = Auth::auth(); $fee = $this->calcFee($uid, $partner_id, $request->input('send_msg'), $request->input('receive_msg')); $confessModel = new ConfessModel(); $confess = $confessModel->fill([ 'nickname' => $request->input('nickname'), 'media_id' => $request->input('media_id'), 'content' => $request->input('content'), 'send_self' => $request->input('send_self'), 'send_msg' => $request->input('send_msg'), 'receive_msg' => $request->input('receive_msg'), 'state' => 0, 'create_at' => time() ]); if (!$confess->save()) { throw new \ApiException("数据库异常", 505); } if ($fee > 0) { # 下单 $orderObj = new Order(); $order_id = $orderObj->unifyByConfess($fee, $confess->id); } return array( 'code' => 200, 'message' => 'success', 'data' => [ 'order_id' => $order_id, 'confess_id' => $confess->id ], ); } /** * 表白支付结果处理 * @param OrderModel $order * @return bool * @throws \Exception */ public function payment(OrderModel $order) { $ticketController = new Ticket(); \DB::beginTransaction(); try { // 获取表白记录信息 $confess = ConfessModel::find($order->type_id); // 让表白生效 $confess->state = 1; $confess->save(); // 获取被表白卡片信息 $partner = PartnerModel::find($confess->partner_id); // 获取被表白用户信息 $user = UserModel::find($partner->uid); $invite = new User(); $invite->task($user->uid, 5); // 表白者-加入通知 NoticeModel::create([ 'uid' => $order->uid, 'title' => '你的表白已发送成功', 'content' => '你的表白已通过系统信息通知到对方,如有回应我们将第一时间通知你反馈结果', 'type' => 10, 'type_id' => $confess->id, ]); // 被表白用户-加入通知 NoticeModel::create([ 'uid' => $user->uid, 'title' => "你收到一条来自{$confess->nickname}的表白", 'content' => $confess->content, 'type' => 6, 'type_id' => $confess->id, ]); // 发送短信 $media = MediaModel::mediaInfo($partner->media_id, 'msy'); $params = array( 'username' => ", 系统中有人喜欢了你上架的室友,并发送了表白信息", 'place' => "微信公众号「{$media->public_name}」中回复\"{$media->keyword[0]}bbtx\"即", 'type' => '表白' ); $params['username'] = ",系统中有人喜欢了你,并向你发了表白信息"; \DB::commit(); return true; } catch (\Exception $e) { \DB::rollBack(); return false; } } }