save($data); } public function getList(array $param = []) { $filter = $this->getQueryFilter($param); $jd = new Jd(); $list = $this->where($filter)->order('create_time', 'desc')->paginate($param['pageSize'] ?? 150)->toArray(); foreach ($list['data'] as &$value) { if (isset($value['goods_id'])) { // 确保 $value['goods_id'] 是一个数组 $value['goods'] = Goods::where('goods_id','in', $value['goods_id'])->select(); } // foreach ( $value['goods'] as $key => $val) { // //京东短链 // $jd_short_url = $jd->getJdShortLink($val->goods_no); // $val['jd_short_url'] = $jd_short_url; // } } return $list; } public function getQueryFilter(array $param) { // 设置默认的检索数据 $params = $this->setQueryDefaultValue($param, [ 'header_content' => "", // 查询内容 'channel_name' => "", // 渠道 'betweenTime' => [] // 起止时间 ]); // 检索查询条件 $filter = []; // 起止时间 if (!empty($params['betweenTime'])) { $times = between_time($params['betweenTime']); if (isset($times['start_time']) && isset($times['end_time'])) { $filter[] = ['create_time', '>=', $times['start_time']]; $filter[] = ['create_time', '<', $times['end_time'] + 86400]; } } // 渠道名称 if (!empty($params['channel_name'])) { $filter[] = ['channel_name', 'like', "%{$params['channel_name']}%"]; } // 查询内容 if (!empty($params['header_content'])) { $filter[] = ['header_content', 'like', "%{$params['header_content']}%"]; } return $filter; } public function deleteTipoff($ids) { // 检查 $ids 是否为空或 null if (empty($ids)) { return false; // 或者抛出一个异常,具体取决于业务需求 } return $this->where('id', 'in', $ids)->delete(); } public function addGoods(int $id ,array $data) { return $this->where('id', $id)->update($data); } }