where($query->getTable() . '.shop_supplier_id', -1); }else{ $query->where($query->getTable() . '.shop_supplier_id', 'in', $shop_supplier_ids); } } /** * 获取团购活动列表 */ public function getList($param) { $filter = []; if (!empty($param['search'])) { $filter[] = ['active_name', 'like', '%' . trim($param['search']) . '%']; } if (isset($param['status']) && $param['status'] !== '') { $filter[] = ['status', '=', (int)$param['status']]; } // 店铺ID筛选 - 如果提供了shop_supplier_id参数,则按供应商筛选 if (isset($param['shop_supplier_id']) && $param['shop_supplier_id'] !== '') { $filter[] = ['shop_supplier_id', '=', (int)$param['shop_supplier_id']]; } // 时间范围筛选 if (!empty($param['start_time']) && !empty($param['end_time'])) { $filter[] = ['start_time', '>=', strtotime($param['start_time'])]; $filter[] = ['end_time', '<=', strtotime($param['end_time'])]; } $order = ['create_time' => 'desc']; if (!empty($param['order'])) { $order = [$param['order_field'] => $param['order']]; } return $this->with(['file']) ->where($filter) ->order($order) ->paginate([ 'list_rows' => $param['list_rows'] ?? 15, 'query' => $param ]); } /** * 添加团购活动 */ public function add($data) { $this->startTrans(); try { // 格式化数据 $data['start_time'] = strtotime($data['start_time']); $data['end_time'] = strtotime($data['end_time']); $data['app_id'] = self::$app_id; $result = $this->save($data); $this->commit(); return $result !== false; } catch (\Exception $e) { $this->rollback(); $this->error = $e->getMessage(); return false; } } /** * 编辑团购活动 */ public function edit($data) { $this->startTrans(); try { // 格式化数据 if (isset($data['start_time'])) { $data['start_time'] = strtotime($data['start_time']); } if (isset($data['end_time'])) { $data['end_time'] = strtotime($data['end_time']); } $result = $this->save($data); $this->commit(); return $result !== false; } catch (\Exception $e) { $this->rollback(); $this->error = $e->getMessage(); return false; } } /** * 更新状态 */ public function updateStatus($status) { return $this->save(['status' => $status]) !== false; } /** * 删除团购活动 */ public function remove() { // 检查是否有团购商品关联 $productModel = new \app\operations\model\plus\groupbuy\Product(); $count = $productModel->where('groupbuy_active_id', $this->groupbuy_active_id)->count(); if ($count > 0) { $this->error = '该活动下还有团购商品,无法删除'; return false; } return $this->delete(); } }