with(['goods' => function ($query) use ($where) { $query->where($where); }]) ->where('delete_time', 0) ->paginate([ 'page' => $get['page'], 'list_rows' => $get['limit'], 'var_page' => 'page' ])->toArray();; return ['count' => $lists['total'], 'lists' => $lists['data']]; } // 获取详情 public static function detail($id) { $result = NewGoods::with('goods')->where(['id' => $id, 'delete_time' => 0])->find(); return $result; } // 添加表单信息 public static function create($form) { if (!empty($form['sort']) && !is_numeric($form['sort'])) { return ['code' => -1, 'msg' => '请输入整数']; } $result = NewGoods::create([ 'goods_id' => $form['goods_id'], 'sort' => $form['sort'], 'create_time' => time() ]); if ($result) { return ['code' => 1, 'msg' => '添加成功']; } return ['code' => -1, 'msg' => '添加失败']; } // 修改表单信息 public static function edit($form) { $result = NewGoods::where(['id' => $form['id']])->update([ 'goods_id' => $form['goods_id'], 'sort' => $form['sort'], 'update_time' => time() ]); if ($result) { return ['code' => 1, 'msg' => '修改成功']; } return ['code' => -1, 'msg' => '修改失败']; } // 删除文章 public static function del($id) { $result = NewGoods::where(['id' => $id])->update(['delete_time' => time()]); if ($result) { return true; } return false; } }