$data['width'], 'height' => $data['height'], ]; $start = $data['starttime']; $end = $data['endtime']; $rep = Ad::where($where) ->where('fromtime', '<', $start) ->where('totime', '>', $end) ->orderBy('id') ->limit($data['pageSize']) ->offset(($data['page'] - 1) * $data['pageSize'])->get(); $count = Ad::where($where)->count(); $data = [ 'rows' => $rep->toArray(), 'count' => $count, ]; $ads = Ad::whereIn($data['id']) ->leftJoin('ad_place', 'ad.pid', 'ad_place.id') ->leftJoin("article_data", "article.id", "article_data.article_id") ->select("ad_place.*", "ad.*") ->orderBy("ad.id", "desc") ->limit($data['pageSize']) ->offset(($data['page'] - 1) * $data['pageSize'])->get(); $count = Ad::whereIn($data['id'])->count(); $data = [ 'rows' => $ads->toArray(), 'count' => $count, ]; if (empty($rep)) { return Result::error("没有信息数据"); } return Result::success($data); } /** * 添加订单 * @param * @return void */ public function addOrder(array $data): array { $ads = Ad::whereIn($data['id']) ->leftJoin('ad_place', 'ad.pid', 'ad_place.id') ->leftJoin("article_data", "article.id", "article_data.article_id") ->select("ad_place.*", "ad.*") ->orderBy("ad.id", "desc") ->limit($data['pageSize']) ->offset(($data['page'] - 1) * $data['pageSize'])->get(); $count = Ad::whereIn($data['id'])->count(); $data = [ 'rows' => $ads->toArray(), 'count' => $count, ]; if (empty($rep)) { return Result::error("没有信息数据"); } return Result::success($data); } /** * 获取订单列表 * @param * @return void */ public function getOrderListAdmin(array $data): array { // 获取分页参数,默认每页 10 条记录 $page = isset($data['page']) ? (int) $data['page'] : 1; $perPage = isset($data['pagesize']) ? (int) $data['pagesize'] : 10; // 构建查询条件 $where = [ 'order.status' => $data['status'], // 明确指定 order 表的 status 列 ]; // 添加订单号查询条件 if (!empty($data['order_num'])) { $where['order.order_num'] = $data['order_num']; // 明确指定 order 表的 order_num 列 } // 处理时间范围查询 $start = $data['sttime']; $end = $data['edtime']; // 查询数据并分页 $query = Order::where($where) ->when(!empty($start) && !empty($end), function ($q) use ($start, $end) { $q->whereBetween('order.fromtime', [$start, $end]); // 明确指定 order 表的 fromtime 列 }) ->when(!empty($start), function ($q) use ($start) { $q->where('order.fromtime', '>=', $start); // 明确指定 order 表的 fromtime 列 }) ->when(!empty($end), function ($q) use ($end) { $q->where('order.totime', '<=', $end); // 明确指定 order 表的 totime 列 }) ->leftJoin('user as admin_user', 'order.admin_user_id', '=', 'admin_user.id') ->leftJoin('user as user', 'order.user_id', '=', 'user.id') ->select( 'order.*', 'admin_user.user_name as admin_user_name', 'user.user_name as user_name' ) ->orderBy('order.id'); // 执行分页查询 $result = $query->paginate($perPage, ['*'], 'page', $page); // 返回分页结果 return Result::success([ 'count' => $result->total(), 'current_page' => $result->currentPage(), 'last_page' => $result->lastPage(), 'pagesize' => $result->perPage(), 'rows' => $result->items(), ]); } /** * 获取订单详情 * @param * @return void */ public function getOrderDetailAdmin(array $data): array { $order = Order::where('order.id', $data['id']) ->leftJoin('user as admin_user', 'order.admin_user_id', '=', 'admin_user.id') ->leftJoin('user as user', 'order.user_id', '=', 'user.id') ->select( 'order.*', 'admin_user.user_name as admin_user_name', 'user.user_name as user_name' )->first(); if (empty($order)) { return Result::error("没有信息数据"); } $pid = $order['id']; $ad = OrderAd::where('order_id', $pid)->get(); $order['ad'] = $ad; return Result::success($order); } /** * 修改订单价格 * @param * @return void */ public function editPriceOrderAdmin(array $data): array { $order = Order::where('id', $data['id'])->first(); if (empty($order)) { return Result::error("没有信息数据"); } $order->price = $data['price']; $order->save(); return Result::success($order); } /** *拒绝订单 * @param * @return void */ public function rejectOrderAdmin(array $data): array { $order = Order::where('id', $data['id'])->first(); if (empty($order)) { return Result::error("没有信息数据"); } Db::beginTransaction(); try { $order->status = 2; //订单状态:1:通过;2:驳回;3:撤回;4:修改;5:过期;6:待审核;7:结束 $order->ad_status = 2; $order->reason = $data['reason']; $order->bhtime = date('Y-m-d H:i:s'); $order->save(); OrderAd::where('order_id', $data['id']) ->update(['status' => 2]); Db::commit(); } catch (\Exception $e) { Db::rollBack(); return Result::error("操作失败"); } return Result::success($order); } /** * 结束订单 * @param * @return void */ public function endOrderAdmin(array $data): array { $order = Order::where('id', $data['id'])->first(); if (empty($order)) { return Result::error("没有信息数据"); } Db::beginTransaction(); try { $order->status = 7; $order->jstime = date('Y-m-d H:i:s'); $order->save(); // 获取 order_ad 表中的记录 $orderAds = OrderAd::where('order_id', $data['id']) ->update(['status' => 7]); // 在ad表中删除相同pid的数据 Ad::where('order_id',$data['id'])->delete(); Db::commit(); } catch (\Exception $e) { Db::rollBack(); return Result::error("操作失败" . $e->getMessage()); } return Result::success($order); } /** * 删除订单 * @param * @return void */ public function delOrderAdmin(array $data): array { // 获取订单信息 $order = Order::where('id', $data['id'])->first(); if (empty($order)) { return Result::error("没有信息数据"); } Db::beginTransaction(); try { // 获取 order_ad 表中的记录 OrderAd::where('order_id', $data['id'])->delete(); // 删除 ad 表中的记录 Ad::where('order_id', $order['id'])->delete();) // 提交事务 Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollBack(); // 返回错误信息 return Result::error($e->getMessage()); } // 返回成功信息 return Result::success("删除成功"); } /** * 审核订单 * @param * @return void */ public function applyOrderStatusAdmin(array $data): array { $order = Order::where('id', $data['id']) ->where('status', 6) ->first(); if (empty($order)) { return Result::error("没有信息数据"); } Db::beginTransaction(); try { $order->status = 1; $order->ad_status = 1; $order->shtime = date('Y-m-d H:i:s'); $order->save(); // 批量更新 order_ad 表中的状态 OrderAd::where('order_id', $data['id']) ->where('status', 6) ->update(['status' => 1]); //判断的当前时间是否在订单的开始时间之后,并且小于等于订单的结束时间 if (time() >= strtotime($order->sttime) && time() < strtotime($order->edtime)) { $ad_status = 1; //审核生效 } else { $ad_status = 2; //审核 } $ads = []; foreach ($orderAds as $orderAd) { $ads[] = [ 'name' => $orderAd->name, 'pid' => $orderAd->pid, 'areaid' => $orderAd->areaid, 'amount' => $orderAd->amount, 'introduce' => $orderAd->introduce, 'hits' => $orderAd->hits, 'admin_user_id' => $orderAd->admin_user_id, 'fromtime' => $orderAd->fromtime, 'totime' => $orderAd->totime, 'text_name' => $orderAd->text_name, 'text_url' => $orderAd->text_url, 'text_title' => $orderAd->text_title, 'image_src' => $orderAd->image_src, 'image_url' => $orderAd->image_url, 'image_alt' => $orderAd->image_alt, 'video_src' => $orderAd->video_src, 'video_url' => $orderAd->video_url, 'video_auto' => $orderAd->video_auto, 'video_loop' => $orderAd->video_loop, 'status' => $ad_status, 'order_id' => $orderAd->order_id, ]; } Ad::insert($ads); Db::commit(); } catch (\Exception $e) { Db::rollBack(); return Result::error($e->getMessage()); } return Result::success($order); } }