success\(\'\', \[\'list\' => \$rows, \'total\' => \(int\)\$total, \'page\' => \$page\]\);\s*\}/s'; $newOrders = <<<'PHP' public function orders() { $merchant = $this->requireMerchant(); $uids = $this->merchantUserIds($merchant); $status = $this->request->param('status', 'all'); $keyword = trim((string)$this->request->param('keyword', '')); $page = max(1, (int)$this->request->param('page', 1)); $limit = min(50, max(1, (int)$this->request->param('limit', 20))); $build = function () use ($uids, $status, $keyword) { $q = Db::name('order')->where('user_id', 'in', $uids)->where('user_deleted', 0); if ($keyword !== '') { $q->where(function ($sub) use ($keyword) { $sub->where('contact', 'like', "%{$keyword}%") ->whereOr('mobile', 'like', "%{$keyword}%") ->whereOr('order_no', 'like', "%{$keyword}%") ->whereOr('service_name', 'like', "%{$keyword}%") ->whereOr('address', 'like', "%{$keyword}%") ->whereOr('remark', 'like', "%{$keyword}%"); }); } if ($status === 'active') { $q->where('status', 'in', \app\common\library\OrderStatus::activeValues()); } elseif ($status === 'completed') { $q->where('status', \app\common\library\OrderStatus::COMPLETED); } elseif ($status === 'cancelled') { $q->where('status', \app\common\library\OrderStatus::CANCELLED); } elseif ($status !== 'all' && $status !== '') { $q->where('status', (int)$status); } return $q; }; $total = $build()->count(); $rows = $build()->order('id desc')->page($page, $limit)->select(); $userMap = Db::name('user')->where('id', 'in', $uids)->column('id,nickname,mobile', 'id'); foreach ($rows as &$row) { $statusInt = (int)$row['status']; $ownerUser = (int)$row['user_id'] === (int)$merchant['user_id']; $u = isset($userMap[(int)$row['user_id']]) ? $userMap[(int)$row['user_id']] : null; $mobile = $u ? (string)$u['mobile'] : ''; $row['pay_amount'] = (float)$row['pay_amount']; $row['urgent'] = (int)$row['urgent']; $row['status_text'] = \app\common\library\OrderStatus::label($statusInt); $row['status_tip'] = \app\common\library\OrderStatus::tip($statusInt); $row['appoint_text'] = $row['appoint_time'] ? date('m-d H:i', (int)$row['appoint_time']) : '尽快上门'; $row['create_text'] = date('Y-m-d H:i', (int)$row['createtime']); $fullAddr = trim(($row['province'] ?? '') . ($row['city'] ?? '') . ($row['district'] ?? '') . ($row['address'] ?? '')); $row['address_text'] = $fullAddr ?: ($row['address'] ?? ''); $row['full_address'] = $row['address_text']; $row['mobile_mask'] = strlen($row['mobile']) === 11 ? substr_replace($row['mobile'], '****', 3, 4) : $row['mobile']; $row['account_name'] = $u && $u['nickname'] ? $u['nickname'] : ('用户' . substr($mobile, -4)); $row['account_role'] = $ownerUser ? 'owner' : 'member'; $row['account_role_text'] = $ownerUser ? '主账号' : '关联账号'; $goodsNum = max(1, (int)$row['goods_num']); $row['goods_title'] = ($row['service_name'] ?: '专业师傅上门服务') . ' x ' . $goodsNum . '套'; $row['service_items_text'] = '服务项目: 安装x' . $goodsNum . ';'; $row['status_timeline_text'] = \app\common\library\OrderStatus::tip($statusInt); $row['status_time_text'] = date('Y-m-d H:i:s', !empty($row['updatetime']) ? (int)$row['updatetime'] : (int)$row['createtime']); } unset($row); $this->success('', ['list' => $rows, 'total' => (int)$total, 'page' => $page]); } PHP; $code = preg_replace($oldPattern, $newOrders, $code); file_put_contents($merchantFile, $code); echo "Merchant.php enhanced.\n";