model = new \app\admin\model\Showcase; $this->view->assign('statusList', $this->model->getStatusList()); } /** * 晒单列表 */ public function index() { $this->request->filter(['strip_tags', 'trim']); if (false === $this->request->isAjax()) { return $this->view->fetch(); } if ($this->request->request('keyField')) { return $this->selectpage(); } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model ->with(['order', 'user', 'service']) ->where($where) ->order($sort, $order) ->paginate($limit); $items = $list->items(); foreach ($items as &$item) { if (!empty($item['images'])) { $item['images'] = implode(',', $this->parseTags($item['images'])); } } unset($item); return json(['total' => $list->total(), 'rows' => $items]); } /** * 晒单详情(关联源头工单与实拍组图) */ public function detail($ids = null) { $row = $this->model->with(['order', 'user', 'service'])->where('showcase.id', (int)$ids)->find(); if (!$row) { $this->error(__('No Results were found')); } $images = $this->parseTags($row['images']); $tags = $this->parseTags($row['tags']); $this->view->assign([ 'row' => $row, 'images' => $images, 'tags' => $tags, ]); return $this->view->fetch(); } /** * 晒单展示状态与封面治理 */ public function edit($ids = null) { $row = $this->model->with(['order', 'user', 'service'])->where('showcase.id', (int)$ids)->find(); if (!$row) { $this->error(__('No Results were found')); } $images = $this->parseTags($row['images']); if (false === $this->request->isPost()) { $this->view->assign([ 'row' => $row, 'images' => $images, ]); return $this->view->fetch(); } $params = $this->request->post('row/a', []); $status = in_array($params['status'] ?? '', ['normal', 'hidden'], true) ? $params['status'] : $row['status']; $coverImage = trim((string)($params['cover_image'] ?? $row['cover_image'])); Db::name('showcase')->where('id', (int)$row['id'])->update([ 'status' => $status, 'cover_image' => mb_substr($coverImage, 0, 255), 'updatetime' => time(), ]); $this->success(); } /** * 禁止后台伪造虚拟晒单 */ public function add() { $this->error('业主晒单仅由真实完工订单评价同步生成,后台不可手工伪造'); } /** * 删除违规晒单并同步复位源头工单晒单标记 */ public function del($ids = null) { if (false === $this->request->isPost()) { $this->error(__('Invalid parameters')); } $ids = $ids ?: $this->request->post('ids'); $idArr = array_values(array_filter(array_map('intval', explode(',', (string)$ids)))); if (!$idArr) { $this->error(__('Parameter %s can not be empty', 'ids')); } $rows = Db::name('showcase')->where('id', 'in', $idArr)->field('id,order_id')->select(); if (!$rows) { $this->error(__('No Results were found')); } Db::startTrans(); try { $orderIds = array_values(array_unique(array_filter(array_map('intval', array_column($rows, 'order_id'))))); Db::name('showcase')->where('id', 'in', $idArr)->delete(); if ($orderIds) { Db::name('order')->where('id', 'in', $orderIds)->update([ 'is_showcase' => 0, 'showcase_time' => null, ]); } Db::commit(); } catch (\Exception $e) { Db::rollback(); $this->error($e->getMessage()); } $this->success(); } protected function parseTags($raw) { $raw = trim((string)$raw); if ($raw === '') { return []; } if ($raw[0] === '[') { $arr = json_decode($raw, true); if (is_array($arr)) { return array_values(array_filter(array_map('trim', $arr))); } } return array_values(array_filter(array_map('trim', explode(',', $raw)))); } }